-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Describe the bug
--hotswap deploy is not working on a Lambda function that has a DynamoDB table set as an event source. The Dynamo table is created in a parent stack, the Lambda function is created in a NestedStack.
Expected Behavior
Hotswap deploy of the modified Lambda function source code, which was the only thing that changed when trying to run the cdk deploy --hotswap TempProjectStack command.
Current Behavior
Hotswap deploy fails and I get the following error:
Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: We don't support the 'StreamArn' attribute of the 'AWS::DynamoDB::Table' resource. This is a CDK limitation. Please report it at https://github.com/aws/aws-cdk/issues/new/choose
A regular deploy does successfully deploy.
Reproduction Steps
TypeScript files to reproduce on a new project
bin/cdk.ts
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { TempProjectStack } from '../lib/temp-project-stack';
const app = new cdk.App();
new TempProjectStack(app, 'TempProjectStack', {});lib/temp-project-stack.ts
import {
Stack,
StackProps,
NestedStack,
NestedStackProps,
} from 'aws-cdk-lib';
import { Construct } from 'constructs';
import {
Alias,
AssetCode,
Function,
FunctionProps,
Runtime,
StartingPosition,
Version,
} from 'aws-cdk-lib/aws-lambda';
import { AttributeType, StreamViewType, Table } from 'aws-cdk-lib/aws-dynamodb';
import { DynamoEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
// Properties for NestedStacks
interface LambdaStackProps extends NestedStackProps {
codeDirectory: string;
lambdaProps: Omit<FunctionProps, 'code'>;
}
// Example NestedStack used for Lambdas
export class NestedLambdaStack extends NestedStack {
public lambda: Function;
public alias: Alias;
public version: Version;
constructor(
scope: Construct,
id: string,
{ lambdaProps, codeDirectory, ...props }: LambdaStackProps
) {
super(scope, id, props);
const lambdaCode = AssetCode.fromAsset(codeDirectory);
this.lambda = new Function(this, `${id}-lambda`, {
code: lambdaCode,
...lambdaProps,
});
this.version = this.lambda.currentVersion;
this.alias = new Alias(this, `${id}-alias`, {
aliasName: 'live',
version: this.version,
});
}
}
// Parent Stack
export class TempProjectStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
// Using the NestedStack to create the Lambda function and a few defaults like versioning and an alias
const lambdaStack = new NestedLambdaStack(this, 'example', {
codeDirectory: 'src',
lambdaProps: {
handler: 'index.handler',
runtime: Runtime.NODEJS_18_X,
},
});
const table = new Table(this, 'dynamodb-table', {
partitionKey: {
name: 'id',
type: AttributeType.STRING,
},
stream: StreamViewType.NEW_IMAGE,
});
const lambdaAlias = lambdaStack.alias;
// The following call is what causes the hotswap error to show up
lambdaAlias.addEventSource(
new DynamoEventSource(table, {
startingPosition: StartingPosition.LATEST,
})
);
}
}src/index.js
exports.handler = function (event, context) {
// Modify the number after hello world to trigger a simple source code change for the hotswap deploy
context.succeed('hello world 1');
};The above files within the drop down have triggered the error for me on a fresh CDK project created using: cdk init app --language typescript
Possible Solution
To be clear I don't want to actually hotswap the entire Dynamo Table itself here. I would love to be able to hotswap deploy the modified Lambda code and maybe only the StreamArn of the table if that is required for this work. If we can do it without modifying the StreamArn that is fine too. I'm not overly familiar with Dynamo Streams and Lambda, so maybe there is a limitation here that makes this not an option. The end goal is to be able to adopt --hotswap deploys in our environment as it would greatly increase developer efficiency and improve iteration speed.
Additional Information/Context
No response
CDK CLI Version
2.73.0
Framework Version
No response
Node.js Version
v18.15.0
OS
Ubuntu 20.04 LTS
Language
Typescript
Language Version
No response
Other information
No response