Fuse CDK app
CDK App has two stacks as listed below
dist
- contains S3 + CFAPI
- contains Lambda + APIGateway
Local testing
Installation - We will be using pnpm instead of
npm
and volta as node version manager. Run the following command for installing dependenciespnpm i
Local testing - We have included a
client
application and alambda
for testing under foldertest
spo we don't need to move to another application for testing CDK. We will be taking advantage of CDK Context to store application data as below.
ENV | Description |
---|---|
CDK_DEPLOY_REGION | CDK Region to be deployed |
CDK_DEPLOY_ACCOUNT | CDK Account number |
BRAND | Application brand name |
APP_NAME | Name of the Application |
STAGE | Application stage |
DOMAIN | CF Domain |
HOSTED_ZONE | HostedZone of Route53 for ACM and domain configuration |
CUSTOM_DOMAIN | Should we create custom domain |
DIST_PATH | Cloudfront distribution deployment path |
API_STAGE | APIGateway stage |
The first key of the context
in cdk.json
represents the application
name. For example, appfire
key in context
object represents the app name
which is also be present in the fuse-config.yaml
with path fuse.app
.
{
"app": "npx ts-node --swc ./bin/ac-app-dist.ts",
"profile": "default",
"context": {
"sai": {
"APP_NAME": "sai",
"BRAND": "bobswift",
"CDK_DEPLOY_ACCOUNT": "286845483821",
"CDK_DEPLOY_REGION": "us-east-1",
"CUSTOM_DOMAIN": true,
"DIST_PATH": "dist",
"DOMAIN": "sai-dev.sand-bobswift.appfire.app",
"HOSTED_ZONE": "sand-bobswift.appfire.app",
"STAGE": "dev",
"PROFILE": "default"
}
}
}
fuse:
app: appfire
brand: bobswift
stage: dev
profile: default
Commands
Stacks
List stacks with following command
cdk list
Deployment
For Deploying the changes, run following command. since we have multiple stacks,
we will use a stack name or --all
flag to deploy CDK changes.
cdk deploy --all (or) cdk deploy <stack-name>
Integration tests
To engage in integration testing, create your test file within the directory <tests/integration>
, ensuring that it starts with integ. For example, if you are testing a Lambda function, your test file might be named integ.lambda.ts
. Once you have your tests set up, you can run the following command to test them
npm run integ-test
The command above executes integration tests by creating multiple stacks: one for the test suite and another for assertions. You can choose to either delete or retain the Test stack by providing the following properties.
const ExampleStack = new ExampleIntegrationTest(app, 'stack-id', {
setDestroyPolicyToAllResources: <true to destroy and false to retain>,
// other props
});
const integrationTest = new IntegTest(app, 'integration-id', {
testCases: [SQSTestStack],
cdkCommandOptions: {
destroy: {
args: {
force: <true to destroy and false to retain>,
},
},
},
regions: [ExampleStack.region],
});