SAM Deployment?
j opened this issue · 4 comments
Is it possible to have this workflow be a part of SAM / Cloudformation?
Great question! I'm open to suggestions on how to fit this into the SAM / CloudFormation workflow. Currently I think you'd have to parse the layers.json output and get it into your CFN template somehow.
When used with the "--dry-run" switch, this works really well in a SAM / CloudFormation workflow! By using that switch, the tool creates a .zip file for each of the Lambda Layers found, and these can be referenced in your SAM / CloudFormation templates.
Some examples to demonstrate... note these examples assume the img2lambda binary is embedded in the repository.
- Repository structure
<root>
│ buildspec.yml
│ template.yml
│
├───bin
│ img2lambda
│
└───custom-runtime
bootstrap
Dockerfile
- Sample CodeBuild buildspec.yml file.
version: 0.2
phases:
build:
commands:
# Compile Docker Images
- cd custom-runtime
- docker build -t custom-runtime .
# Perform img2lambda conversion
- cd $CODEBUILD_SRC_DIR
- sudo chmod +x ./bin/img2lambda
- sudo ./bin/img2lambda --image custom-runtime:latest --dry-run
# Publish the Custom Runtime
- cd $CODEBUILD_SRC_DIR
- aws cloudformation package --template-file template.yml --s3-bucket <s3bucketname> --output-template-file updated.yml
- aws cloudformation deploy --template-file updated.yml --stack-name custom-runtime --region us-east-1
- Sample SAM / CloudFormation Template.
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: A Lambda Custom Runtime
Resources:
CustomRuntime:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: custom-runtime
Description: A Lambda custom runtime
ContentUri: './output/layer-1.zip'
RetentionPolicy: Retain
SecondLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: custom-runtime-second-layer
Description: The second layer for the custom runtime
ContentUri: './output/layer-2.zip'
RetentionPolicy: Retain
Outputs:
CustomRuntimeArn:
Value: !Ref CustomRuntime
Description: Lambda Layer Arn for the Custom Runtime
SecondLayerArn:
Value: !Ref SecondLayer
Description: The second Layer Arn for the Custom Runtime
maybe turn this into a new example in this repo?
Added examples to the repo for the SAM and Serverless tools:
https://github.com/awslabs/aws-lambda-container-image-converter#deploy-with-serverless-framework