AWS CDK: Lambda Fleet
Deploy multiple AWS Lambda functions as container images to ECR with CDK.
Intention
Have a CloudFormation stack with multiple AWS Lambda functions in different langauges.
Usage
Create a folder like src/lambda-node-example
and store a Dockerfile
there:
FROM amazon/aws-lambda-nodejs:12
ARG FUNCTION_DIR="/var/task"
RUN mkdir -p ${FUNCTION_DIR}
COPY package.json ${FUNCTION_DIR}
RUN npm install
COPY handler.js ${FUNCTION_DIR}
CMD [ "handler.run" ]
Using the AWS CDK, a docker image will be created and deployed to Amazon ECR for every folder in src/
. After uploading the image, an AWS Lambda will be created or updated to use the latest image. Run yarn deploy
to deploy all functions and output the function's arn.
Examples
Deployment
$ > yarn deploy
Usage
Fleet.FleetLambdaNodeExampleArnXYZ = "arn:aws:lambda:eu-central-1:123:function:Fleet-FleetLambdaNodeExampleXYZ-XYZ"
Fleet.FleetLambdaPythonExampleArnXYZ = "arn:aws:lambda:eu-central-1:123:function:Fleet-FleetLambdaPythonExampleXYZ-XYZ"
Fleet.FleetLambdaTypescriptExampleArnXYZ = "arn:aws:lambda:eu-central-1:123:function:Fleet-FleetLambdaTypescriptExampleXYZ-XYZ"