Skip to content
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

Deploy AWS CDK stacks using CodePipeline #7108

Closed
kennu opened this issue Apr 1, 2020 · 12 comments
Closed

Deploy AWS CDK stacks using CodePipeline #7108

kennu opened this issue Apr 1, 2020 · 12 comments
Assignees
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.

Comments

@kennu
Copy link

kennu commented Apr 1, 2020

I would like to build my AWS CDK stack in CodeBuild using cdk synth into an artifact, and then deploy the artifact with CodePipeline using its built-in CloudFormation deployment feature.

When I try to do that, I get an error about missing parameters. I can't figure out how to pass the right parameters to CodePipeline. It seems that AWS CDK only generates the required parameters when using cdk deploy.

The parameters are like:

AssetParameters66eaa5211f0e5a7e13085d03b9a2660bca429dd36d6f2ff63caaad265fa82d05ArtifactHash42F81164
AssetParameters66eaa5211f0e5a7e13085d03b9a2660bca429dd36d6f2ff63caaad265fa82d05S3Bucket8B26DF3A
AssetParameters66eaa5211f0e5a7e13085d03b9a2660bca429dd36d6f2ff63caaad265fa82d05S3VersionKeyC231E1D0

I have a project where a single Git repository builds 13 CloudFormation stacks. It would be nice to use CodePipeline to deploy them, instead of trying to handle all the cdk deploy processes in CodeBuild. It seems like the right way to do deploy CloudFormation stacks anyway.

Maybe there already is some way to pass these parameters from CDK to CodePipeline?


This is a 🚀 Feature Request

@kennu kennu added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Apr 1, 2020
@vineethsoma
Copy link

I am currently working through this scenario too. I was thinking of doing the following in Code Pipeline -

  1. Do cdk bootstrap against deployment account in a Code Build Action. This will resources to stage your lambda assets.

  2. Do cdk deploy <stackName> after bootstrap in a another Code Build Action.

In step 2, I want to see if I can do cdk synth which spits out an assets.json file with assets to templete parameter mappings and templates. And use this infra package with cdk deploy <stackName> to build out my infra.

It would be nice as you mentioned if Code Pipeline has native actions to do CDK deploys.

@kennu
Copy link
Author

kennu commented Apr 1, 2020

When thinking about this further, I guess the problem is also that cdk synth does not upload Lambda function code to S3 yet. A perfect integration with CodePipeline would probably output the Lambda function contents as artifacts, and let CodePipeline upload them to S3, and then pass the necessary values to the CloudFormation stack parameters.

@vineethsoma
Copy link

I know they are working on the assets publishing capability which is part of the puzzle - https://github.com/aws/aws-cdk-rfcs/blob/master/text/0092-asset-publishing.md

I haven't quite figured out if it can be used yet.

@vineethsoma
Copy link

vineethsoma commented Apr 1, 2020

@kennu So I ran into a different issue trying to do cdk deploy of a stack containing Lambdas with API Gateway -
The LambdaIntegration tries to give invoke permissions which requires approval from a user to move forward. I tried using --require-approval=never flag but that just throws -
Stack [myStack] does not exist

I think I am going to take the Code Pipeline approach laid out here and create a Lambda stack and Build Artifact job per lambda.

Hope this helps!

@skinny85
Copy link
Contributor

skinny85 commented Apr 1, 2020

Hey @kennu and @vineethsoma ,

thanks for opening and commenting on the issue. You've pretty much figured out everything I wanted to say by yourselves, but let me say it anyway 🙂.

The problem you encountered @kennu is indeed because you're using assets in your code, and assets (currently!) are modeled in the CDK using CloudFormation parameters. Like @vineethsoma said, we're working hard on making applications using assets deployable through CodePipeline, but until we release that functionality, you have to forego using assets in all stacks that you want to deploy through CodePipeline. Looking at your asset parameters, I'm guessing you're using assets for the code property of a Lambda function. If that is indeed the case, take a look at this example (that @vineethsoma already mentioned):

https://github.com/skinny85/cdk-codepipeline-and-local-lambda-guidance

Which shows you how to use assets for local development of Lambdas, but then using a different code implementation that's specifically tailored to CodePipeline.

Hope this makes it clear!

Thanks,
Adam

@skinny85 skinny85 added guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Apr 1, 2020
@skinny85 skinny85 self-assigned this Apr 1, 2020
@kennu
Copy link
Author

kennu commented Apr 1, 2020

Okay thanks, I will wait for the support to come out. I think until then I can just run cdk deploy in CodeBuild.

I realized, though, that my current use case involves quite a few Lambda functions (total 150 functions in 13 CloudFormation stacks). It would be a lot of work to configure 150 separate CodePipeline S3 artifacts and deployments. Also adding a new Lambda function would require modifying the Pipeline every time. So I'm not sure if that would be the best approach in this case.

Configuring 13 different CloudFormation template artifacts and deployments, on the other hand, seems reasonable. They would stay pretty static.

@skinny85
Copy link
Contributor

skinny85 commented Apr 1, 2020

Let me ask you this: are all 150 of those Lambdas completely separate? Like, does each of them have their own package.json / pom.xml / setup.py / ... (depending on the programming language they're written in)?

@kennu
Copy link
Author

kennu commented Apr 2, 2020

In this particular project there's about 50 separate code asset folders so that 3 Lambda functions share one asset folder. It's a bit special because we are running some tests with many different Lambda runtime configurations (AWS CDK is very convenient for configuring them).

In my typical projects there tends to be only one code asset folder shared by all the Lambda functions in a CloudFormation stack.

@skinny85
Copy link
Contributor

skinny85 commented Apr 2, 2020

In this particular project there's about 50 separate code asset folders so that 3 Lambda functions share one asset folder. It's a bit special because we are running some tests with many different Lambda runtime configurations (AWS CDK is very convenient for configuring them).

Ok. In that case, you only need 50 CodePipeline Artifacts / CodeBuild Projects ;p Still not great, but better than 150...

@skinny85
Copy link
Contributor

skinny85 commented Apr 2, 2020

In my typical projects there tends to be only one code asset folder shared by all the Lambda functions in a CloudFormation stack.

For those, you only need a single artifact / CodeBuild Project.

@SomayaB SomayaB added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Apr 11, 2020
@SomayaB SomayaB added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Apr 20, 2020
@SomayaB
Copy link
Contributor

SomayaB commented Apr 28, 2020

Closing this issue for now. Feel free to reopen if you have more questions.

@SomayaB SomayaB closed this as completed Apr 28, 2020
@christophgysin
Copy link
Contributor

This is now possible with the introduction of CDK pipelines:
https://docs.aws.amazon.com/cdk/api/latest/docs/pipelines-readme.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

5 participants