Canary Deployments for Lambda using CodeDeploy with CodePipeline

1

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

david
已提问 2 年前1974 查看次数
1 回答
1
  1. It's a known issue, there are bunch of questions like yours in Stackoverflow like https://stackoverflow.com/questions/62210071/aws-codedeploy-for-lambda-cant-read-appspec

  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 artifact.zip .
      - aws lambda update-function-code --region=eu-west-1 --function-name test-pipeline --zip-file fileb://artifact.zip
      - 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
Resources:
  - myLambdaFunction:
      Type: AWS::Lambda::Function
      Properties:
        Name: "test-pipeline"
        Alias: "production"
        CurrentVersion: "%currentVersion%"
        TargetVersion: "%targetVersion%"

Hope it helps

已回答 2 年前
  • 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...

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则