Skip to content

fix(events): omit KmsKeyIdentifier from Archive when no KMS key is configured - #37865

Open
Zelys-DFKH wants to merge 5 commits into
aws:mainfrom
Zelys-DFKH:fix/events-archive-omit-kms-when-unset
Open

fix(events): omit KmsKeyIdentifier from Archive when no KMS key is configured#37865
Zelys-DFKH wants to merge 5 commits into
aws:mainfrom
Zelys-DFKH:fix/events-archive-omit-kms-when-unset

Conversation

@Zelys-DFKH

Copy link
Copy Markdown
Contributor

Issue # (if applicable)

Closes #37847.

Credit to @pahud, who did the full investigation here — the root cause and fix direction are his. This is the implementation.

Reason for this change

When Archive is created without a kmsKey prop, the L2 construct synthesizes KmsKeyIdentifier: "" into the CloudFormation template. An empty string is not a valid value for KmsKeyIdentifier: when no CMK is configured, the property should be absent so CloudFormation falls back to the AWS-managed default. In some regions, the empty string causes a GeneralServiceException on deployment.

The EventBus L2 already handles this correctly: it passes props?.kmsKey?.keyArn with no fallback. Archive was inconsistent. The comment claiming the empty string was "necessary to enforce an update that removes any previously used CMK" is also wrong: removing a CMK means omitting the property, not supplying an empty string.

Description of changes

  • archive.ts: removed the || '' fallback from kmsKeyIdentifier, so the property is undefined (and therefore absent from the synthesized template) when no key is provided. Removed the two misleading comment lines above the CfnArchive constructor call.
  • archive.test.ts: added Match to the import. Renamed the no-key test to better describe what it verifies. Updated the assertion from KmsKeyIdentifier: '' to KmsKeyIdentifier: Match.absent().

Describe any new or updated permissions being added

None.

Description of how you validated changes

All five archive unit tests pass:

  • creates an archive for an EventBus
  • creates an archive for an EventBus with a pattern including a detailType property
  • should have defined defaultChild
  • Archive with a customer managed key on an event bus
  • Archive without a KMS key omits KmsKeyIdentifier from the template

The CMK test still asserts KmsKeyIdentifier is present and matches the key ARN. The CMK path is unaffected.

No existing snapshot tests reference KmsKeyIdentifier: "", so no snapshot updates are required.

Checklist

  • My code adheres to the CONTRIBUTING GUIDE and DESIGN GUIDELINES

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions Bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels May 13, 2026

@aws-cdk-automation aws-cdk-automation left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@Zelys-DFKH

Copy link
Copy Markdown
Contributor Author

Two CI jobs show failures that are unrelated to the code change:

  • pr-triage-manager — labeling bot error, not code-related
  • cli-changes — the step-security/changed-files action errored with "Unable to locate commit sha" because it runs on the upstream's shallow pull_request_target checkout and can't resolve fork commit SHAs across the fork boundary. This PR doesn't touch cx-api/lib/features.ts or any CLI files; no CLI integ tests are needed.

Neither is required for merge. Happy to investigate further if helpful.

@Zelys-DFKH

Zelys-DFKH commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Exemption Request

The integ test requirement makes total sense for changes that affect real AWS resource behavior. This one is different. The bug is that KmsKeyIdentifier: "" was being written into the CloudFormation template when no KMS key is configured. An empty string isn't a valid value; the property should simply be absent.

The fix is a one-line || '' removal in archive.ts. The behavior is fully observable at synthesis time and the updated unit tests cover it directly: KmsKeyIdentifier: Match.absent() on the no-key path, and the CMK path still asserts the key ARN is present. A deployment-level integ test would spin up an EventBridge Archive with and without a KMS key: substantial AWS overhead to verify a template property being absent vs. empty string.

If the team thinks a deployment test is warranted here, I'll add one. Just checking first.

…key is configured

When no kmsKey is provided to the Archive construct, the L2 was emitting
KmsKeyIdentifier: "" in the synthesized CloudFormation template. The empty
string causes GeneralServiceException failures in some AWS regions that
reject it as an invalid value (the property must either hold a valid KMS
key ARN or be absent entirely).

The fix removes the || '' fallback so the property is omitted when
kmsKeyIdentifier resolves to undefined, consistent with how the EventBus
L2 handles the same property.

The test that previously asserted KmsKeyIdentifier: '' has been corrected
to assert Match.absent(), and the misleading comment explaining the empty
string as intentional has been removed.

Fixes aws#37847
@Zelys-DFKH

Copy link
Copy Markdown
Contributor Author

CI is red on one integration test snapshot. Dropping the empty KmsKeyIdentifier changes the synthesized template, so integ.archive comes back CHANGED.

I have not run cdk-integ with --dry-run or edited the snapshot by hand, since CONTRIBUTING asks contributors not to. Could a maintainer run the integration test so it gets regenerated from a real deployment?

The fix stops emitting an empty KmsKeyIdentifier when no KMS key is
configured, so the Archive resource in the snapshot loses that property.
Regenerated integ.archive.
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AWS::Events::Archive : CDK 2.253.0 Generates Invalid Empty String for EventBridge Archive KmsKeyIdentifier Property

4 participants