Skip to content

Commit

Permalink
chore(cli): add integration test for Lambda function's hotswap feature
Browse files Browse the repository at this point in the history
This commit adds a basic integration test for the hotswap feature, for
the case when the Lambda function's description and environment variables
have changed.
  • Loading branch information
huyphan committed Aug 1, 2022
1 parent c5ebc75 commit ccefc23
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/aws-cdk/test/integ/cli/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ class LambdaStack extends cdk.Stack {
}
}

class LambdaHotswapStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);

const fn = new lambda.Function(this, 'my-function', {
code: lambda.Code.asset(path.join(__dirname, 'lambda')),
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
description: new Date().toISOString(),
environment: {
SomeVariable: new Date().toISOString(),
}
});

new cdk.CfnOutput(this, 'FunctionName', { value: fn.functionName });
}
}

class DockerStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);
Expand Down Expand Up @@ -379,6 +397,7 @@ switch (stackSet) {
new MissingSSMParameterStack(app, `${stackPrefix}-missing-ssm-parameter`, { env: defaultEnv });

new LambdaStack(app, `${stackPrefix}-lambda`);
new LambdaHotswapStack(app, `${stackPrefix}-lambda-hotswap`);
new DockerStack(app, `${stackPrefix}-docker`);
new DockerStackWithCustomFile(app, `${stackPrefix}-docker-with-custom-file`);
new FailedStack(app, `${stackPrefix}-failed`)
Expand Down
26 changes: 26 additions & 0 deletions packages/aws-cdk/test/integ/cli/cli.integtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,32 @@ integTest('test resource import', withDefaultFixture(async (fixture) => {
}
}));

integTest('hotswap deployment supports Lambda function\'s description and environment variables', withDefaultFixture(async (fixture) => {
// GIVEN
const stackArn = await fixture.cdkDeploy('lambda-hotswap', {
captureStderr: false,
});

// WHEN
const deployOutput = await fixture.cdkDeploy('lambda-hotswap', {
options: ['--hotswap'],
captureStderr: true,
onlyStderr: true,
});

const response = await fixture.aws.cloudFormation('describeStacks', {
StackName: stackArn,
});
const functionName = response.Stacks?.[0].Outputs?.[0].OutputValue;

// THEN

// The deployment should not trigger a full deployment, thus the stack's status must remains
// "CREATE_COMPLETE"
expect(response.Stacks?.[0].StackStatus).toEqual('CREATE_COMPLETE');
expect(deployOutput).toContain(`Lambda Function '${functionName}' hotswapped!`);
}));

async function listChildren(parent: string, pred: (x: string) => Promise<boolean>) {
const ret = new Array<string>();
for (const child of await fs.readdir(parent, { encoding: 'utf-8' })) {
Expand Down

0 comments on commit ccefc23

Please sign in to comment.