Conversation
commit: |
Collaborator
Author
AWS::SNS::TopicPolicy and AWS::SQS::QueuePolicy are full replacements: when two separate CloudFormation resources target the same topic/queue, the second overwrites the first. When multiple state machines share a notification topic or queue (fan-in), the second machine's policy destroys the first machine's permissions — its notification rules stop working silently. Fix: after compiling all notification resources, group SNS topic policies by topic and SQS queue policies by queue. Same-target policies are merged into a single resource with all statements combined, so CloudFormation sets the policy exactly once with all principals authorised. Adds three unit tests covering: - Two state machines sharing the same SNS topic - Two state machines sharing the same SQS queue - One state machine with the same topic on multiple statuses Updates the notifications integration fixture to include a second state machine sharing the same SNS topic and SQS queue as the first, matching the fan-in scenario described in #275. Adds fixtures/notifications/verify.test.js as the first implementation of the post-deploy template assertion pattern tracked in #748. It reads the compiled CloudFormation template after deployment and asserts exactly one SNS/SQS policy per unique target with statements from all state machines, catching silent policy-overwrite regressions that a successful deploy alone cannot detect. Closes #275 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
aa959d4 to
fe678cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes issue #275: when multiple state machines send notifications to the same SNS topic or SQS queue (fan-in), the plugin generates a separate
AWS::SNS::TopicPolicy/AWS::SQS::QueuePolicyresource per state machine.AWS::SNS::TopicPolicyandAWS::SQS::QueuePolicyare full replacements in CloudFormation — when two resources target the same topic/queue, the second overwrites the first. The first machine's notification rules then silently stop working because their principal is no longer in the policy.Fix
After compiling all notification resources, same-target SNS topic policies and SQS queue policies are merged into a single CloudFormation resource with all statements combined. CloudFormation then applies the policy exactly once with all principals authorised.
The change is in
compileNotifications.js: amergeResourcePoliciesstep groupsAWS::SNS::TopicPolicyresources by topic andAWS::SQS::QueuePolicyresources by queue, merging statements before the resources are written into the CloudFormation template.Verification
Integration test: The
notificationsfixture was updated to include a second state machine (notificationMachine2) sharing the same SNS topic and SQS queue as the first — the exact fan-in scenario from #275.The compiled CloudFormation template was inspected after packaging with the fix applied:
One merged policy per target, with one statement per state machine. Without the fix, two separate resources would be generated for each target, causing CloudFormation to overwrite the first machine's policy with the second's. LocalStack deploy is green.
Unit tests: Three new tests added covering:
Test plan
npm test— 533 passingnpx osls notifications:deploy --stage test— greenAWS::SNS::TopicPolicyand 1 mergedAWS::SQS::QueuePolicywith statements from both state machinesCloses #275
🤖 Generated with Claude Code