(aws-cloudformation) Deploy a CDK stack in a Lambda
See original GitHub issueMy use case:
- I have a pipeline stack that is defined in Typescript
- I would like this stack to be deployed dynamically via a Lambda with parameters that will be resolved during the Lambda execution
All the documentation examples that I found show how to deploy a CDK stack via a CLI cdk synth
command.
What I need to achieve is exactly the same but in a Lambda, Typescript, doesn’t really matter, so:
- I need to synthesize the stack out of the TypeScript objects - probably something with the use of DefaultStackSynthesizer
- then I need to pass the template to nodeJS CloudFormation client
I found this but it doesn’t show how to handle the template synthesis part.
I would appreciate some info if this is the correct way to go or that there is maybe any more generic out-of-the-box way to do it.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Creating a serverless application using the AWS CDK
Create an AWS CDK app · Create a Lambda function to list all widgets · Create a widget service · Add the service...
Read more >Your first AWS CDK app - AWS Documentation
Synthesize one or more stacks in the app to create an AWS CloudFormation template. Deploy one or more stacks to your AWS account....
Read more >aws-cdk/aws-lambda module - AWS Documentation
When deploying a stack that contains this code, the directory will be zip archived and then uploaded to an S3 bucket, then the...
Read more >Deploy multiple-stack applications using AWS CDK with ...
This pattern provides a step-by-step approach for application deployment on Amazon Web Services (AWS) using AWS Cloud Development Kit (AWS CDK) with TypeScript....
Read more >Stacks - AWS Cloud Development Kit (AWS CDK) v2
The unit of deployment in the AWS CDK is called a stack . All AWS resources defined within the scope of a stack,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this is worth giving more consideration to. There are cases where pipelines is just a bad fit.
For instance, I run a multi-tenant app where a new stack has to be deployed when a user account is created, updated when key details change, and destroyed when the account is closed. This is in addition to pushing out bulk updates across accounts. To do this in pipelines would be incredibly inefficient, as it would have to check all user accounts for changes.
I’m not saying CDK should be redesigned lambda-first, but I think it’s worth an official example of how to handle this situation. The examples out there are broken and incomplete. I’ve started down the path of making this work, and it’s the wild west. The CDK CLI needs to be bundled in a layer. The CDK entry app needs to be bundled separately (probably with a custom
cdk.json
. Then the lambda func needs deploy privileges. And that’s just the issues I see from the get-go.If anything, I think the real key to this situation (and many others) is programmatic usage of CDK (filed #15851), but in the interim, there’s got to be a clear way through the lambda issue.
We are deploying a simple CDK app from lambda. We’ve successfully tried 2 options so far:
aws-cdk
classes: simple and amazingly fast (especially with hotswap when that’s possible depending on use case)Here is the snippet:
Hope this will become more or less the Programmatic API for CDK.