Skip to content

(hotswap): We don't support attributes of the 'AWS::DynamoDB::GlobalTable' resource. #35688

@pedrolourencoribeiro

Description

@pedrolourencoribeiro

Describe the bug

Currently if I try to watch my stack which includes nested stacks we get the following error:
We don't support attributes of the 'AWS::DynamoDB::GlobalTable' resource.

Regression Issue

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

Last Known Working CDK Library Version

No response

Expected Behavior

cdk watch should work

Current Behavior

When running cdk watch we get back the following error when a change is detected

⚠️ The --hotswap and --hotswap-fallback flags deliberately introduce CloudFormation drift to speed up deployments
⚠️ They should only be used for development - never use them for your production Stacks!

ExampleStack: deploying... [1/1]
Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: We don't support attributes of the 'AWS::DynamoDB::GlobalTable' resource. This is a CDK limitation. Please report it at https://github.com/aws/aws-cdk/issues/new/choose

✅ ExampleStack (no changes)

Reproduction Steps

import * as cdk from 'aws-cdk-lib';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
import { Construct } from 'constructs';

class OtherNestedStack extends cdk.NestedStack {
  table: dynamodb.TableV2;

  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // Create DynamoDB table
    const table = new dynamodb.TableV2(this, 'ExampleTable1', {
      tableName: 'example-table1',
      partitionKey: {
        name: 'id',
        type: dynamodb.AttributeType.STRING,
      },
      
      removalPolicy: cdk.RemovalPolicy.DESTROY, // For demo purposes only
    });

    this.table = table;
  }
}

class NestedStack extends cdk.NestedStack {
  constructor(scope: Construct, id: string, table: dynamodb.TableV2, props?: cdk.StackProps) {
    super(scope, id, props);

     // Create Lambda function
     const helloLambda = new lambda.Function(this, 'HelloLambda', {
      runtime: lambda.Runtime.NODEJS_18_X,
      handler: 'hello.handler',
      code: lambda.Code.fromAsset('lambda'),
      environment: {
        TABLE_NAME: table.tableName,
      },
    });

    // Grant Lambda permissions to read/write to DynamoDB table
    table.grantReadWriteData(helloLambda);

    // Create API Gateway
    const api = new apigateway.RestApi(this, 'ExampleApi', {
      restApiName: 'Example Service',
      description: 'Example API with Lambda and DynamoDB',
    });

    // Create Lambda integration
    const helloIntegration = new apigateway.LambdaIntegration(helloLambda, {
      requestTemplates: { 'application/json': '{ "statusCode": "200" }' },
    });

    // Add GET method to API Gateway
    api.root.addMethod('GET', helloIntegration);

    // Output the API Gateway URL
    new cdk.CfnOutput(this, 'ApiUrl', {
      value: api.url,
      description: 'API Gateway URL',
    });
  }
}

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

     // Create DynamoDB table
     const table = new dynamodb.TableV2(this, 'ExampleTable1', {
      tableName: 'example-table1',
      partitionKey: {
        name: 'id',
        type: dynamodb.AttributeType.STRING,
      },
      
      removalPolicy: cdk.RemovalPolicy.DESTROY, // For demo purposes only
    });



    new NestedStack(this, 'NestedStack1', table);
    

    // Output the DynamoDB table name
    new cdk.CfnOutput(this, 'TableName', {
      value: table.tableName,
      description: 'DynamoDB table name',
    });
  }
}


const app = new cdk.App();
new ExampleStack(app, 'ExampleStack', {
  env: {
    account: process.env.CDK_DEFAULT_ACCOUNT,
    region: process.env.CDK_DEFAULT_REGION,
  },
});

Possible Solution

No response

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.219.0

AWS CDK CLI version

2.1029.4 (build 09c0061)

Node.js Version

22

OS

MAC

Language

TypeScript

Language Version

typescript 5.9.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-dynamodbRelated to Amazon DynamoDBeffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions