This package is an executable that uses @routineless/nx-aws-plugin to generate nx workspace with cdk and lambda applications.
To install this package globaly run:
npm install -g create-aws-cdk-app
To generate a workspace run:
npx create-aws-cdk-app nx-aws-cdk-workspace -i infra -l lambda
First argument is a workspace name, so after generation completed you can navigate to the nx-aws-cdk-workspace
folder.
By default cdk executor will deploy all changes to localstack environment. You need to have docker installed in order to use this mode.
npx nx cdk infra diff
npx nx cdk infra deploy --all
After deployment you can view your resources using awslocal cli:
awslocal lambda list-functions
awslocal lambda invoke --function-name <functionName> '/dev/stdout'
After exploring you can destroy your resources by running npx nx cdk infra destroy --all
command.
In order to use cdk executor for aws deployment you need to have configured aws credentials.
You can achieve this by configuring awscli. And you need to provide --env <envName>
flag to cdk executor. Environment name can be any string except local
because it is reserved for localstack environment.
npx nx cdk infra diff --env dev
npx nx cdk infra deploy --env dev --all
After deployment you can explore your resources:
aws lambda list-functions
aws lambda invoke --function-name <functionName> '/dev/stdout'
// Run to clean up your resources
npx nx cdk infra destroy --all --env dev
You can generate new lambda application by running withing you workspace:
// Optionally you can run deploy in watch mode so it will be deployed instantly after generation and any cahnges. You need to have a separate terminal window for this command.
npx nx cdk infra deploy --env dev --watch
npx nx g aws-lambda lambda
name | type | default | required | alias | description |
---|---|---|---|---|---|
infraAppName | string | infra | false | i | Name of cdk application. |
lambdaAppName | string | false | l | Name of lambda application. If not provided lambda application will not be generated during workspace creationg. | |
unitTestRunner | string | jest | false | u | Will add corresponing unit test executors and files. Available options jest, none. |
For detailed documentation navigate to the nx-aws-cdk package. It will has documentation for lambda and cdk applications generators and cdk executor.
MIT © 2023 Anatoli Kozel