Is it possible to deploy to localstack with the aws-cdk? Thought about switching from serverless to the cdk, but could not find any ohter local testing option except aws SAM..
Asked
Active
Viewed 3,337 times
13
-
1Not quite clear what you mean by "switching from serverless to CDK". The CDK is for stack development, essentially on top of CFN. You can develop serverless stacks in CDK (i.e. deploy Lambda etc). – Marakai Oct 25 '19 at 02:32
-
@Marakai Probably means [the framework](https://serverless.com/). – Miles Elam Jan 20 '20 at 21:58
-
@MilesElam Yeah I see OP accepted the answer given, so it became clear then. – Marakai Jan 21 '20 at 22:43
-
1Why switch? We often recommend using Serverless Framework and AWS CDK together. Serverless’s strength is working with Lambda and API Gateway. So a good pattern here is to use CDK for the rest of your infrastructure, and Serverless for your Lambda functions. –– We created a tool to do exactly this - Serverless Stack Toolkit (SST), which allows you to combine CDK and Serverless Framework - github.com/serverless-stack/serverless-stack –– So you can do sls deploy --stage dev and sst deploy --stage dev. – Frank Sep 04 '20 at 07:39
2 Answers
17
I'm working through the same challenges right now. The way I'm getting by is taking the synthesized CloudFormation template from CDK and loading that into my LocalStack CloudFormation:
$ cdk synth my-stack > my-stack.template.json
$ awslocal cloudformation create-stack --stack-name my-stack --template-body file://./my-stack.template.json
This is working for me with very simple stacks that do not require artifacts/assets. What I'm still working on here is transposing what CDK does internally with S3 bucket based assets as CloudFormation parameters (e.g. Lambda functions, etc.).
Hopefully this gets you down the road a bit. I feel it's the first part of the solution, given what CDK can do today.

Adam Bellas
- 322
- 2
- 6
-
I looked around and this was the best option I could find. AWS tools want you to do everything in AWS all the time. I could find now way to give it a different URL. So you export the template and make localstack run it. I packaged the running of 'awslocal' into a docker image so other devs would not necessarily have to install awslocal. – sbzoom Jan 27 '20 at 18:13
1
I would point you towards the aws-cdk-local package. This allows you to deploy CDK IaC to your localstack. See aws-cdk-local link

confusedpunter
- 137
- 1
- 11