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

cdk deploy --hotswap: We don't support the 'StreamArn' attribute of the 'AWS::DynamoDB::Table' resource. #25417

Closed
jmataway opened this issue May 3, 2023 · 3 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. duplicate This issue is a duplicate.

Comments

@jmataway
Copy link

jmataway commented May 3, 2023

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

@jmataway jmataway added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 3, 2023
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label May 3, 2023
@jmataway
Copy link
Author

jmataway commented May 3, 2023

Forgot to include this in the submission, but this is a cdk diff of the project immediately before I attempt to cdk deploy --hotwap a Lambda source code change:

Stack TempProjectStack
Resources
[~] AWS::CloudFormation::Stack example.NestedStack/example.NestedStackResource exampleNestedStackexampleNestedStackResource5A5A6965 
 ├─ [~] NestedTemplate
 │   └─ [~] .Resources:
 │       ├─ [~] .examplealiasBA70626E:
 │       │   └─ [~] .Properties:
 │       │       └─ [~] .FunctionVersion:
 │       │           └─ [~] .Fn::GetAtt:
 │       │               └─ @@ -1,4 +1,4 @@
 │       │                  [ ] [
 │       │                  [-]   "examplelambdaCurrentVersion05CA5AA8f1242b020b9a9a0b6c14b282074e3338",
 │       │                  [+]   "examplelambdaCurrentVersion05CA5AA8544eaf54ce4283c252602896660c0d9f",
 │       │                  [ ]   "Version"
 │       │                  [ ] ]
 │       ├─ [~] .examplelambda0C208F3A:
 │       │   ├─ [~] .Metadata:
 │       │   │   └─ [~] .aws:asset:path:
 │       │   │       ├─ [-] asset.25b5a9e4aa62b199e107ab1387251fb18b45739653a1be7a05e2c466828f57c0
 │       │   │       └─ [+] asset.f80010741894d042c460a131143881f57701629b5f8628e0edc2e609371efe7b
 │       │   └─ [~] .Properties:
 │       │       └─ [~] .Code:
 │       │           └─ [~] .S3Key:
 │       │               ├─ [-] 25b5a9e4aa62b199e107ab1387251fb18b45739653a1be7a05e2c466828f57c0.zip
 │       │               └─ [+] f80010741894d042c460a131143881f57701629b5f8628e0edc2e609371efe7b.zip
 │       ├─ [+] Added: .examplelambdaCurrentVersion05CA5AA8544eaf54ce4283c252602896660c0d9f
 │       └─ [-] Removed: .examplelambdaCurrentVersion05CA5AA8f1242b020b9a9a0b6c14b282074e3338
 └─ [~] TemplateURL
     └─ [~] .Fn::Join:
         └─ @@ -13,6 +13,6 @@
            [ ]     {
            [ ]       "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
            [ ]     },
            [-]     "/cfcf8d79e86abc446e75bedf5fdfb7935ca9f811c9b1aee4ef758b2ae7d90a64.json"
            [+]     "/034654d6902019365c1b9ca9a92f28a525c2eed451e801f182aa45d5c1b88f6b.json"
            [ ]   ]
            [ ] ]

@peterwoodworth
Copy link
Contributor

I think it's highly likely that this and #25418 are caused by the same bug. I'll close this one in favor of that 🙂 Thanks for reporting! If these turn out to have different root causes, that will come to light when investigating the fix for #25418 and we will reopen this in that case

@peterwoodworth peterwoodworth added duplicate This issue is a duplicate. and removed needs-triage This issue or PR still needs to be triaged. labels May 3, 2023
@github-actions
Copy link

github-actions bot commented May 3, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. duplicate This issue is a duplicate.
Projects
None yet
Development

No branches or pull requests

2 participants