By using AWS re:Post, you agree to the Terms of Use

Canary Deployments for Lambda using CodeDeploy with CodePipeline


I can't seem to set up a pipeline that uses CodeDeploy for a lambda function. I have tried:

  1. Generating the appspec.yml file as part of a CodeBuild action. In this case CodePipeline zips the file, and CodeDeploy says it can't find the appspec file.

  2. Generating the appspec.yml file manually (Lambda invocation). In this case CodeDeploy gives the error "The deployment specifies that the revision is a null file, but the revision provided is a zip file." (It is definitely not a zip file)

Has anyone succeeded in doing this?

Note: I know SAM apparently does this. But it would be difficult to introduce new tooling at this point

1 Answer
  1. It's a known issue, there are bunch of questions like yours in Stackoverflow like

  2. I remember also having issues with it, I decided to use S3 to store appspec.yml because CodeDeploy simply refused to accept appspec as text. Also I ended up starting deployments from CodeBuild, here are the deployment instructions:

      - zip -q -x yarn.lock -x *.git* -r .
      - aws lambda update-function-code --region=eu-west-1 --function-name test-pipeline --zip-file fileb://
      - newVersion=$(aws lambda publish-version --region=eu-west-1 --function-name test-pipeline --query Version --output text)
      - currentVersion=$(aws lambda get-alias --region=eu-west-1 --function-name test-pipeline --name production --query FunctionVersion --output text)
      - sed -i "s/%currentVersion%/${currentVersion}/g" appspec.yaml
      - sed -i "s/%targetVersion%/${newVersion}/g" appspec.yaml
      - aws s3 cp appspec.yaml s3://alex-test-bucket/
      - aws deploy create-deployment --region=eu-west-1 --application-name test-pipeline --deployment-group-name test-pipeline-group --s3-location bucket=alex-test-bucket,bundleType=yaml,key=appspec.yaml

Here is appspec.yml

version: 0.0
  - myLambdaFunction:
      Type: AWS::Lambda::Function
        Name: "test-pipeline"
        Alias: "production"
        CurrentVersion: "%currentVersion%"
        TargetVersion: "%targetVersion%"

Hope it helps

answered 8 months ago
  • Thank you for your answer. Its a little ridiculous that the integration between CodeDeploy and CodePipeline is so broken. Deploying from codebuild may be what I end up doing. Or maybe i'll try to keep the deployment separate by doing it in a lambda function...

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions