awslabs / aws-codedeploy-plugin

Jenkins plugin for AWS CodeDeploy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: BundleType must be either YAML or JSON

aleskiontherun opened this issue · comments

I'm trying to deploy a lambda function written in go and getting the following error:

Zipping files into /tmp/#10-Resources:
-   myfunc:
        Properties:
            Alias: main
            CurrentVersion: ''
            Name: myfunc
            TargetVersion: 0.0.10
        Type: AWS::Lambda::Function
version: 0.0.10.zip
Uploading zip to s3://my-bucket/myfunc/#10-Resources:
-   myfunc:
        Properties:
            Alias: main
            CurrentVersion: ''
            Name: myfunc
            TargetVersion: 0.0.10
        Type: AWS::Lambda::Function
version: 0.0.10.zip
Registering revision for application 'MyFunc'
Failed CodeDeploy post-build step; exception follows.
BundleType must be either YAML or JSON (Service: AmazonCodeDeploy; Status Code: 400; Error Code: InvalidRevisionException; Request ID: 5c46c0da-2124-11e8-9f19-914d46cbd854)
com.amazonaws.services.codedeploy.model.InvalidRevisionException: BundleType must be either YAML or JSON (Service: AmazonCodeDeploy; Status Code: 400; Error Code: InvalidRevisionException; Request ID: 5c46c0da-2124-11e8-9f19-914d46cbd854)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1639)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1304)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1056)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
	at com.amazonaws.services.codedeploy.AmazonCodeDeployClient.doInvoke(AmazonCodeDeployClient.java:3358)
	at com.amazonaws.services.codedeploy.AmazonCodeDeployClient.invoke(AmazonCodeDeployClient.java:3334)
	at com.amazonaws.services.codedeploy.AmazonCodeDeployClient.executeRegisterApplicationRevision(AmazonCodeDeployClient.java:2839)
	at com.amazonaws.services.codedeploy.AmazonCodeDeployClient.registerApplicationRevision(AmazonCodeDeployClient.java:2813)
	at com.amazonaws.codedeploy.AWSCodeDeployPublisher.registerRevision(AWSCodeDeployPublisher.java:403)
	at com.amazonaws.codedeploy.AWSCodeDeployPublisher.perform(AWSCodeDeployPublisher.java:232)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
	at hudson.model.Build$BuildExecution.post2(Build.java:186)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
	at hudson.model.Run.execute(Run.java:1749)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)

Hi,

The bundle the error is talking about is the AppSpec file which has to be YAML or JSON.
Here is an example Lambda deployment AppSpec:
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-example.html

Does changing your AppSpec fix the error?

I also received this error when attempting to deploy a lambda by providing the appspec-file over the cli. It appears as if a appspec is required to reside in the bundle (?). Since my artifacts change from build to build I was trying to avoid to generate a new appspec in the build pipeline since it's just extra complexity.

I find it unclear when and how to use AppSpecContent with lambdas, if it's even possible.

aws deploy create-deployment \
  --application-name myapp \
  --deployment-group-name mygrp \
  --revision revisionType=AppSpecContent,appSpecContent={content="'{"version":0,"Resources":[{"pretokengen":{"Type":"AWS::Lambda::Function","Properties":{"Name":"myLambda","Alias":"current","CurrentVersion":"1","TargetVersion":"1"}}}]}'"} \
  --s3-location bucket=artifacts-bucket,bundleType=json,key=myLambda.zip

I get the following error in the console:
The deployment failed because the AppSpec file that specifies the AWS Lambda deployment configuration is missing or has an invalid configuration. Failed to parse your appspec file. Please try again later.

If anyone is still struggling to get CodeDeploy to work using AppSpecContent value, here is my working example:

aws deploy create-deployment \
    --application-name my-awesome-app \
    --deployment-config-name CodeDeployDefault.LambdaAllAtOnce \
    --deployment-group-name something \
    --description "My demo deployment" \
    --revision '{"revisionType": "AppSpecContent", "appSpecContent": {"content": "{\"Resources\":[{\"MyFunction\":{\"Properties\":{\"Alias\":\"current-with-refresh1\",\"CurrentVersion\":\"1\",\"Name\":\"fond-mammoth-lambda1\",\"TargetVersion\":\"1\"},\"Type\":\"AWS::Lambda::Function\"}}],\"version\":\"0.0\"}", "sha256": "500fed8354d2a90a8551a0166837e45dbbf6fc6b0d138a5792502d0a0d35e604"}}' \
    --output text \
    --query '[deploymentId]'

The trick here is to calculate sha256 before escaping double-quotes, like this:

value="{\"Resources\":[{\"MyFunction\":{\"Properties\":{\"Alias\":\"current-with-refresh1\",\"CurrentVersion\":\"1\",\"Name\":\"fond-mammoth-lambda1\",\"TargetVersion\":\"1\"},\"Type\":\"AWS::Lambda::Function\"}}],\"version\":\"0.0\"}"
echo -n $value | shasum -a 256

I have tried different ways for this problem including @antonbabenko. Nothing solved it. All forums and blogs and internet bleeding with it. If somebody else tried anton's solution and thinks it fix i can insist to check sth else will try it more.
I can summorize the problem disqussions about:
is the problem YML or YAML?
should be Jar or Zip?
Codepipeline has bug ? cuz codebuild phase individually works fine.
AWS codepipeline can has bug?

Is this problem related with appspec or code bundle(zip, jar, S3,artifact location, file signature) ? If anyone can explain

@yusufunlu Here is the working module where this functionality is implemented - https://github.com/terraform-aws-modules/terraform-aws-lambda/blob/master/modules/deploy/main.tf#L35-L43

This is the Terraform module which does almost everything related to AWS Lambda functions, and you can copy shell script from there to your project.

Hopefully, it will help you.

Thank you @antonbabenko