Skip to content

[Bug]: Snapshot Test Fails After Setting Multiple CloudWatch Alarms to the Same Lambda (AWS CDK v2.136.0 or Later) #15376

Open
@mickey-DWS

Description

Version

29.7.0

Steps to reproduce

  1. Use AWS CDK version v2.136.0 or later.
  2. Create multiple CloudWatch alarms and attach them to the same Lambda function as shown in the code snippet above.
  3. Run Jest snapshot tests for the CloudFormation stack or Lambda configuration.
  4. Observe that the snapshot test fails with the error: There is already a Construct with name 'AlarmPermission' in NodejsFunction [<LambdaFunctionName>].

Expected behavior

I expect the snapshot tests to pass when multiple CloudWatch alarms are attached to the same Lambda function, as AWS CDK v2.136.0 or later now allows this configuration without errors during deployment.

Image

Actual behavior

The snapshot tests fail with the following error message:

There is already a Construct with name 'AlarmPermission' in NodejsFunction [EmailContentFormatter]

Additional context

Even though the deployment works correctly and the Lambda function is successfully attached to multiple CloudWatch alarms, Jest's snapshot mechanism does not seem to handle this updated behavior properly.

Environment

System:
  OS: macOS 15.0.1
  CPU: (8) arm64 Apple M2
Binaries:
  Node: 18.18.2 - ~/.volta/tools/image/node/18.18.2/bin/node
  Yarn: 4.2.2 - ~/.volta/tools/image/yarn/4.2.2/bin/yarn
  npm: 9.8.1 - ~/.volta/tools/image/node/18.18.2/bin/npm
  pnpm: 8.10.0 - ~/.volta/bin/pnpm
npmPackages:
  jest: ^29.7.0 => 29.7.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions