Skip to main content

Fuse CDK app

CDK App has two stacks as listed below

  1. dist - contains S3 + CF
  2. API - contains Lambda + APIGateway

Local testing

  1. Installation - We will be using pnpm instead of npm and volta as node version manager. Run the following command for installing dependencies

    pnpm i
  2. Local testing - We have included a client application and a lambda for testing under folder test 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.

ENVDescription
CDK_DEPLOY_REGIONCDK Region to be deployed
CDK_DEPLOY_ACCOUNTCDK Account number
BRANDApplication brand name
APP_NAMEName of the Application
STAGEApplication stage
DOMAINCF Domain
HOSTED_ZONEHostedZone of Route53 for ACM and domain configuration
CUSTOM_DOMAINShould we create custom domain
DIST_PATHCloudfront distribution deployment path
API_STAGEAPIGateway 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.

cdk.json
{
"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-config.yaml
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],
});