Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local development with the aws-cdk

Tags:

aws-cdk

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..

like image 870
VinceVega Avatar asked Oct 24 '19 10:10

VinceVega


People also ask

How do I run AWS CDK locally?

You can use the AWS SAM CLI to locally test your AWS CDK applications by running the following commands from the project root directory of your AWS CDK application: sam local invoke. sam local start-api. sam local start-lambda.

Does AWS CDK use CloudFormation?

AWS CDK is available to define and deploy AWS resources in all public regions. Since AWS CDK leverages the CloudFormation service, refer to Regional Products and Services for details about specific resource availability per AWS Region.

Is CDK better than terraform?

Terraform deploys resources using the AWS SDK, whereas the CDK code is first converted to CloudFormation templates and then applied. Terraform would work slightly faster than AWS CDK, particularly because of the time CDK takes to convert code to CloudFormation Template.

Is AWS CDK a framework?

The AWS Cloud Development Kit (AWS CDK) is an open-source software development framework to define your cloud application resources using familiar programming languages.


2 Answers

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.

like image 198
Adam Bellas Avatar answered Nov 23 '22 00:11

Adam Bellas


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

like image 42
confusedpunter Avatar answered Nov 23 '22 00:11

confusedpunter