question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lambda Parameters are missing when deploying with CodeDeploy

See original GitHub issue

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository’s issues are intended for feature requests and bug reports.

  • I’m submitting a …

    • 🪲 bug report
    • 🚀 feature request
    • 📚 construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior? If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce

Can’t deploy a golang-lambda function through CodeDeploy. CloudFormationCreateUpdateStackAction and CloudFormationCreateReplaceChangeSetAction + CloudFormationExecuteChangeSetAction both don’t work. But when I deploy with cdk deploy from my local machine everything works as intended

Error Message:

Parameters: [getPictureCodeS3VersionKey7D69AA08, getPictureCodeArtifactHash67916A64, getPictureCodeS3Bucket4AE043CC] must have values (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: f89c844e-aeed-11e9-a28d-0f1fe7196728)

I double checked the generated cfn template and it contains the custom parameters for the lambda

  "Parameters": {
    "getPictureCodeS3Bucket4AE043CC": {
      "Type": "String",
      "Description": "S3 bucket for asset \"FirstCdkStackStack/getPicture/Code\""
    },
    "getPictureCodeS3VersionKey7D69AA08": {
      "Type": "String",
      "Description": "S3 key for asset version \"FirstCdkStackStack/getPicture/Code\""
    },
    "getPictureCodeArtifactHash67916A64": {
      "Type": "String",
      "Description": "Artifact hash for asset \"FirstCdkStackStack/getPicture/Code\""
    }
  }

this is my cdk code. I added all the files to the artifacts in case something was missing.

	const getPicture = new lambda.Function(this, 'getPicture', {
		code: lambda.Code.asset('handler'),
		handler: 'main',
		runtime: lambda.Runtime.GO_1_X,
	})

	const repo = new codecommit.Repository(this, 'Repo', {
		repositoryName: 'FirstCDKStackStack'
	});

	const sourceOutput = new codepipeline.Artifact();

	const sourceAction = new codepipeline_actions.CodeCommitSourceAction({
		actionName: 'CodeCommit',
		repository: repo,
		output: sourceOutput,
	});
	
	var project = new codebuild.PipelineProject(this, 'MyProject2', {
		buildSpec: codebuild.BuildSpec.fromObject({
			version: '0.2',
			phases: {
				install: {
					commands: [
						"go get github.com/aws/aws-lambda-go/events",
						"go get github.com/aws/aws-lambda-go/lambda",
					]
				},
				build: {
					commands: [
						"go build -o handler/main handler/get-picture.go",
						"ls",
					],
				},
			},
			artifacts: {
				files: ["*", "bin/*", "lib/*", "handler/*" ],
			}
		}),
	});

	const goBuildOutput = new codepipeline.Artifact();

	const goBuildAction = new codepipeline_actions.CodeBuildAction({
		actionName: 'goBuild',
		project,
		input: sourceOutput,
		outputs: [goBuildOutput], 
	});

	var project = new codebuild.PipelineProject(this, 'MyProject', {
		buildSpec: codebuild.BuildSpec.fromObject({
			version: '0.2',
			phases: {
				install: {
					commands: [
						"npm install",
						"npm install -g cdk",
						"npm install -g typescript",
					]
				},
				build: {
					commands: [
						"tsc",
						"cdk synth",
					],
				},
			},
			artifacts: {
				files: ["*", "bin/*", "lib/*", "cdk.out/*", "handler/*" ],
			}
		}),
	});

	const cfnBuildOutput = new codepipeline.Artifact();

	const cfnBuildAction = new codepipeline_actions.CodeBuildAction({
		actionName: 'cfnBuild',
		project,
		input: goBuildOutput,
		outputs: [cfnBuildOutput], 
	});
	const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', {
		stages: [
			{
			stageName: 'source',
			actions: [sourceAction],
			},
			{
			stageName: 'build-go',
			actions: [goBuildAction],
			},
			{
			stageName: 'build-cfn',
			actions: [cfnBuildAction],
			},
		],
	});

	const changeSetOutput = new codepipeline.Artifact();

	pipeline.addStage({
		stageName: 'changeset',
		actions: [
			new codepipeline_actions.CloudFormationCreateUpdateStackAction({
				templatePath: cfnBuildOutput.atPath('cdk.out/FirstCdkStackStack.template.json'),
				adminPermissions: true,
				stackName: 'FirstCdkStackStack',
				actionName: 'create_update_stack',
				output: changeSetOutput,
			})
		]
	})

//this doesnt work either
// pipeline.addStage({
	// 	stageName: 'changeset',
	// 	actions: [
	// 		new codepipeline_actions.CloudFormationCreateReplaceChangeSetAction({
	// 			templatePath: cfnBuildOutput.atPath('cdk.out/FirstCdkStackStack.template.json'),
	// 			adminPermissions: true,
	// 			stackName: 'FirstCdkStackStack',
	// 			actionName: 'create_change_set',
	// 			output: changeSetOutput,
	// 			changeSetName: 'changeset',
	// 		})
	// 	]
	// })

	// pipeline.addStage({
	// 	stageName: 'deploy',
	// 	actions: [
	// 		new codepipeline_actions.CloudFormationExecuteChangeSetAction({
	// 			stackName: 'FirstCdkStackStack',
	// 			actionName: 'execute_change_set',
	// 			changeSetName: 'changeset',
	// 		})
	// 	]
	// })

  }
}
  • What is the expected behavior (or behavior of feature suggested)?

CloudDeploy should behave like cdk deploy

  • What is the motivation / use case for changing the behavior or adding this feature?
  • Please tell us about your environment:

    • CDK CLI Version: 1.1.0 (build 1a11e96)
    • Module Version: xx.xx.xx
    • OS: Windows10 locally, the default image in CodeBuild
    • Language: TypeScript
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

DQIkGGp.zip this is the output that gets passed to the deploy stage.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
skinny85commented, May 28, 2020

Multiple Lambdas are very similar to one Lambda, and depend on whether your functions share the same bundle, or not.

  1. If they do, then it’s very simple; all Lambdas that share bundles use the same CfnParametersCode instance for their code property, but just differ in the entrypoint. So, like @wange011 said, you would have:
const cfnParamsCode = lambda.Code.fromCfnParameters();
const function1 = new lambda.Function(this, 'Function1', {
  code: cfnParamsCode,
  // other function properties...
  handler: 'handler.firstFunc',
});
const function2 = new lambda.Function(this, 'Function2', {
  code: cfnParamsCode,
  // other function properties...
  handler: 'handler.secondFunc',
});

All of the rest is the same as the example.

  1. If the functions use different bundles, you would have a separate instance of CfnParametersCode for each, and then a separate build artifact in your lambda-bundling CodeBuild project; so, something like this:
// Lambda stacks
const cfnParamsCode1 = lambda.Code.fromCfnParameters();
const function1 = new lambda.Function(this, 'Function1', {
  code: cfnParamsCode1,
  // other function properties...
  handler: 'handler.firstFunc',
});
const cfnParamsCode2 = lambda.Code.fromCfnParameters();
const function2 = new lambda.Function(this, 'Function2', {
  code: cfnParamsCode2,
  // other function properties...
  handler: 'handler.secondFunc',
});

// CodePipeline stacks
const lambdaBuildOutput1 = new codepipeline.Artifact('LambdaBuildOutput1');
const lambdaBuildOutput2 = new codepipeline.Artifact('LambdaBuildOutput2');

              new codebuild.PipelineProject(this, 'Build', {
                buildSpec: codebuild.BuildSpec.fromObject({
                  version: '0.2',
                  phases: {
                     // build all your Lambda functions here...
                  },
                  // save the generated files in the correct artifacts
                  artifacts: {
                    'secondary-artifacts': {
                      'LambdaBuildOutput1': {
                        'base-directory': 'lambda-build-output1',
                        files: ['**/*'],
                      },
                      'LambdaBuildOutput2': {
                        'base-directory': 'lambda-build-output2',
                        files: ['**/*'],
                      },
                    },
                  },
                }),
              });

// then, in the CFN deploy action:

            new codepipeline_actions.CloudFormationCreateUpdateStackAction({
              // ...
              parameterOverrides: {
                ...props.cfnParamsCode1.assign(lambdaBuildOutput1.s3Location),
                ...props.cfnParamsCode2.assign(lambdaBuildOutput2.s3Location),
              },

You can check out this example as well.

Thanks, Adam

1reaction
jonny-rimekcommented, Aug 7, 2019

@skinny85 I went with the original proposal after all, it works as expected.

But I’m unclear how to handle multiple lambdas, normally I would specify the path in the code property.

For reference, I’m building a stepfunction that is triggered on putObject in a bucket, the first lambda is downloading the csv converting it to parquet and uploading the file to another bucket, with the second lambda I want to query the parquet file with athena. The last step would be to read the result and write it to dynamodb.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot deployment issues in Lambda
When you update your function, Lambda deploys the change by launching new instances of the function with the updated code or settings.
Read more >
Deploying Lambda Function with CDK Failing Due to ...
When I try to deploy this to CodeDeploy, I get: Parameters: [TestFunctionCodeS3Bucket, TestFunctionCodeS3VersionKey] must have values ...
Read more >
Deploying to AWS
Deploying to AWS. The Serverless Framework was designed to provision your AWS Lambda Functions, Events and infrastructure Resources safely and quickly.
Read more >
get-deployment — AWS CLI 2.9.4 Command Reference
Disable automatically prompt for CLI input parameters. ... Information about the location of an Lambda deployment revision stored as a RawString.
Read more >
Solved: Missing Environment Variables Error.
One thing I want to know on this : if I have s3 deployment , lambda deployments, docker images deployment to ec2 using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found