-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lambda Parameters are missing when deploying with CodeDeploy #3434
Comments
@jimbo5644535 thanks for opening the issue. The parameters you see are because you're using assets as your Lambda code. Which means you need to provide values for them in the CloudFormation Actions that are doing the deployment. See our docs for an example: https://docs.aws.amazon.com/cdk/latest/guide/codepipeline_example.html?shortFooter=true Thanks, |
Thanks, I wasn't aware of this page. I tried to piece it together from those code snippets. Any specific reason this is not in the cdk examples?^^ looks like the parameter overwrite during deloyment is the crucial thing here.
is this the actual syntax (with three points) or should this indicate that it is an example. Didn't use typescript before I started with cdk. If I understand correctly we need to overwrite 3 parameters in total. I'll bash my head against this tomorrow. Thanks for the fast reply and CDK in general, it's a huge step up from plain cfn or aws sam^^ |
The three points syntax, |
Hi skinny85, Is the example mentioned in the link https://docs.aws.amazon.com/cdk/latest/guide/codepipeline_example.html?shortFooter=true working as I was trying to make in work but I am getting error when I had pushed my lambda code (index.js) in the lambda directory. Here is the below excerpt i the Build phase. Container] 2019/07/26 06:58:23 Running command npm run build May be I am missing a trick, I am not sure. I suspect this second CDK build step which has below steps build: { has to given information on the LambdaStack |
@skinny85 thanks for the clarification. the rfc for CD in cdk is also proposing to use an extra build stage that executes |
@nikhilbhoj the error message is about a file Make sure you're using the correct directory in the buildspec. |
Hi @skinny85 , What I have done is follow the link above from AWS cdk documentation And here is the code build output.
I do not have src in my buildspec file. Here is buildpase details where it is failing(CdkBuild455F642E-q5wchZGs5EDo). {
"version": "0.2",
"phases": {
"install": {
"commands": [
"npm install",
"npm install -g cdk",
"npm install -g typescript"
]
},
"build": {
"commands": [
"ls -ltr",
"npm run build",
"npm run cdk synth -- -o dist"
]
}
},
"artifacts": {
"base-directory": "dist",
"files": [
"LambdaStack.template.json"
]
}
} And here is Lambdabuild project details (buildspec) this is working. {
"version": "0.2",
"phases": {
"install": {
"commands": [
"cd lambda",
"npm install"
]
},
"build": {
"commands": "npm run build"
}
},
"artifacts": {
"base-directory": "lambda",
"files": [
"index.js",
"node_modules/**/*"
]
}
} Here is my pipeline And here is my codecommit repo I am not sure if this will help. My assumption is that CDKbuild phase does not have lambdastack file for cdk synth command. |
Did you commit your
There is no |
I did not commit the package.json file and the package-lock.json was created during npm install as per my assumption. [Container] 2019/07/26 06:58:08 Running command npm install I had only commited the lambda folder having index.js and package.json. Can you please share the directory structure for this pipeline project ? Mine is as below. And here is the directory for lambda which I have commited to my codecommitrepo (lambdarepo). |
If you didn't commit these files, how are you expecting to successfully run a build using them on CodeBuild....? |
Hi @skinny85 , I was able to make this work, as pointed out by you when I had commited every thing into my codecommit repo. Thanks for point out. |
Glad you were able to figure it out :) |
@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. |
Hi @jonny-rimek , were you able to figure out how to handle multiple lambdas in this? I am implementing a similar use case as you described in the last comment. |
@Apoorva-Wathodkar well, I'm not using code deploy any more I simply run cdk deploy in the CI/CD |
Hi @Apoorva-Wathodkar, I managed to get an implementation working by adding multiple functions to the file specified by the build artifact. In my case, a CloudFormation template is first synthesized using a CodeBuild with the build artifacts containing the file with the lambda handler code. From what I gather, when CloudFormation creates a ChangeSet using the template, this lambda code needs to be passed in as a parameter. That's where the parameter_overrides and extra_inputs from the example (https://docs.aws.amazon.com/cdk/latest/guide/codepipeline_example.html?shortFooter=true) comes from. The So if the lambda handler file exports multiple functions, all you have to do is specify the handler function for each lambda. For example, if |
Multiple Lambdas are very similar to one Lambda, and depend on whether your functions share the same bundle, or not.
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.
// 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, |
Hi @skinny85 , Can this method be used for lambda layers as well? const lambdaLayer = new lambda.LayerVersion(this, 'LambdaLayer', {
code: cfnParamsCode2,
compatibleRuntimes: [
lambda.Runtime.NODEJS_8_10
],
}); |
@Spider-ant I personally have not tried it, but I don't see why it would not 🙂. |
Using python and base on the example above an error is thrown when attempting to assign() twice in the parameter overrides of the CFN deploy action. |
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 ...
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
this is my cdk code. I added all the files to the artifacts in case something was missing.
CloudDeploy should behave like cdk deploy
Please tell us about your environment:
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.
The text was updated successfully, but these errors were encountered: