Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamodb: 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. #32199

Open
1 task
JonHolman opened this issue Nov 19, 2024 · 1 comment
Assignees
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@JonHolman
Copy link

Describe the bug

When trying to reference the table stream from a a table in another stack and using cdk watch, I get:
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

example code:

import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";

export class CdkDdbStreamExampleStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: cdk.StackProps) {
    super(scope, id, props);

    const table = new cdk.aws_dynamodb.Table(this, "myTable", {
      partitionKey: {
        name: "pk",
        type: cdk.aws_dynamodb.AttributeType.STRING,
      },
      stream: cdk.aws_dynamodb.StreamViewType.NEW_AND_OLD_IMAGES,
    });

    new HelloStack(this, "helloStack", {
      table,
    });
  }
}

interface HelloStackProps extends cdk.NestedStackProps {
  table: cdk.aws_dynamodb.Table;
}

export class HelloStack extends cdk.NestedStack {
  constructor(scope: Construct, id: string, props: HelloStackProps) {
    super(scope, id, props);

    const myLambda = new cdk.aws_lambda.Function(this, "myLambda", {
      runtime: cdk.aws_lambda.Runtime.NODEJS_18_X,
      code: cdk.aws_lambda.Code.fromInline(`
        exports.handler = async (event) => {
          return {
            Data: {
              Data: "hello world",
            },
          };
        };
      `),
      handler: "index.handler",
      environment: {
        test: props.table.tableStreamArn!,
      },
    });

    myLambda.addEventSource(
      new cdk.aws_lambda_event_sources.DynamoEventSource(props.table, {
        startingPosition: cdk.aws_lambda.StartingPosition.TRIM_HORIZON,
      })
    );
  }
}

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

Expect for cdk watch to work successfully hot swapping with dynamodb streams being used directly and/or indirectly with DynamoEventSource.

Current Behavior

hot swap is not working

Reproduction Steps

use the sample code, run cdk watch, make a small change to the lambda and watch for the hot swap error message.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.167.1

Framework Version

No response

Node.js Version

20.11.1

OS

macOS Sequoia 15.1

Language

TypeScript

Language Version

No response

Other information

No response

@JonHolman JonHolman added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 19, 2024
@github-actions github-actions bot added the @aws-cdk/aws-dynamodb Related to Amazon DynamoDB label Nov 19, 2024
@ashishdhingra ashishdhingra self-assigned this Nov 22, 2024
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2024
@ashishdhingra
Copy link
Contributor

Reproducible using customer's provided code:

CdktestStack: start: Building b4f191e73a6d0917814d24f41b268c44283b91c1245f7c80b518c41a4fc1dde5:<<ACCOUNT_ID>>-us-east-2
CdktestStack: success: Built b4f191e73a6d0917814d24f41b268c44283b91c1245f7c80b518c41a4fc1dde5:<<ACCOUNT_ID>>-us-east-2
CdktestStack: start: Building bcb504bb841509279c59e5a0b0b37e0fe81891560c64c7275289a1f6fdce2184:<<ACCOUNT_ID>>-us-east-2
CdktestStack: success: Built bcb504bb841509279c59e5a0b0b37e0fe81891560c64c7275289a1f6fdce2184:<<ACCOUNT_ID>>-us-east-2
CdktestStack: start: Publishing b4f191e73a6d0917814d24f41b268c44283b91c1245f7c80b518c41a4fc1dde5:<<ACCOUNT_ID>>-us-east-2
CdktestStack: start: Publishing bcb504bb841509279c59e5a0b0b37e0fe81891560c64c7275289a1f6fdce2184:<<ACCOUNT_ID>>-us-east-2
CdktestStack: success: Published b4f191e73a6d0917814d24f41b268c44283b91c1245f7c80b518c41a4fc1dde5:<<ACCOUNT_ID>>-us-east-2
CdktestStack: success: Published bcb504bb841509279c59e5a0b0b37e0fe81891560c64c7275289a1f6fdce2184:<<ACCOUNT_ID>>-us-east-2
CdktestStack: deploying... [1/1]
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

 ✅  CdktestStack (no changes)

✨  Deployment time: 3.96s

The hotswap works fine when not using NestedStack, using code below:

import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";

export class CdkDdbStreamExampleStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: cdk.StackProps) {
    super(scope, id, props);

    const table = new cdk.aws_dynamodb.Table(this, "myTable", {
      partitionKey: {
        name: "pk",
        type: cdk.aws_dynamodb.AttributeType.STRING,
      },
      stream: cdk.aws_dynamodb.StreamViewType.NEW_AND_OLD_IMAGES,
    });

    const myLambda = new cdk.aws_lambda.Function(this, "myLambda", {
      runtime: cdk.aws_lambda.Runtime.NODEJS_18_X,
      code: cdk.aws_lambda.Code.fromInline(`
        exports.handler = async (event) => {
          return {
            Data: {
              Data: "hello world",
            },
          };
        };
      `),
      handler: "index.handler",
      environment: {
        test: table.tableStreamArn!,
      },
    });

    myLambda.addEventSource(
      new cdk.aws_lambda_event_sources.DynamoEventSource(table, {
        startingPosition: cdk.aws_lambda.StartingPosition.TRIM_HORIZON,
      })
    );
  }
}

@JonHolman I found existing issue with inputs from CDK team on why hotswap doesn't work for nested stacks:

In your use case, there is a below cross-stack reference:

"helloStackNestedStackhelloStackNestedStackResource61D4F3E5": {
   "Type": "AWS::CloudFormation::Stack",
   "Properties": {
    "Parameters": {
     "referencetoCdkDdbStreamExampleStackmyTableDBDB2785StreamArn": {
      "Fn::GetAtt": [
       "myTableA48C5C70",
       "StreamArn"
      ]
     }
    },

Please refer above issues for possible explanation.

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants