I have a few AWS Lambda functions in a single repo that I use AWS SAM to package up with the following command in my buildspec.yml file
sam package --template template.yml --s3-bucket "$S3_BUCKET" --output-template-file template-export.yml --region ${AWS_REGION} --image-repository $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$DOCKER_IMAGE
One of my functions runs on a docker image, and the above command builds it fine! However, I now need to add a second function that runs on a container, and I can't find anywhere online how to build the second Lambda. Is there a pattern for this case?
I have a Docker image for each lambda that runs the commands
CMD ["lambdas.lambda1.index.handler"]
Painful and Unclear from AWS documentation but you need to pass --image-repositories
parameter for EACH lambda you have in the template. so in your example if you had 2 Lambdas named Function1
& Function2
then your command would be
sam package --template template.yml --s3-bucket "$S3_BUCKET" --output-template-file template-export.yml --region ${AWS_REGION} --image-repositories Function1=$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$DOCKER_IMAGE --image-repositories Function2=$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$DOCKER_IMAGE