fix(stateMachine): update state machine when useExactVersion layers change#757
Open
fix(stateMachine): update state machine when useExactVersion layers change#757
Conversation
… true (#452) When useExactVersion: true, the plugin resolves Lambda refs to a specific AWS::Lambda::Version resource. That resource's logical ID is generated by Serverless Framework from the function's code artifact hash — so when only a layer changes (same function code), the hash stays the same, no new version is published, and the state machine definition is unchanged. CloudFormation sees no diff and skips the update, leaving the step function invoking the stale Lambda version. Fix: after converting function refs to version refs, inspect the function's Layers property. If layers are present, compute an MD5 hash over all layer entries (Ref logical IDs, ARN strings, or any other intrinsic form) and create a new AWS::Lambda::Version resource whose logical ID embeds that hash. When layers change the hash changes, a new resource is created, CloudFormation publishes a new Lambda version, and the state machine DefinitionString changes so CloudFormation updates the state machine. - Handles all layer reference forms: {Ref: logicalId}, plain ARN strings, and any other intrinsic ({Fn::Sub}, {Fn::ImportValue}, etc.) - Functions without layers are unaffected - Add five unit tests covering: Ref layers, Ref layer version change, ARN string layers, ARN version change, and no-op with no layers - Add integration fixture use-exact-version with a layer and verify.test.js asserting the layer-aware version resource and state machine reference appear in the compiled CloudFormation template Part of #452 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
commit: |
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.
Closes #452
Summary
useExactVersion: true, compute an MD5 hash of all layer references on the function ({Ref: logicalId}, ARN strings, or any other intrinsic form) and create a newAWS::Lambda::Versionresource whose logical ID embeds that hash. When layers change, the hash changes, a new version is published, and the state machineDefinitionStringchanges so CloudFormation updates it.use-exact-versionintegration fixture with averify.test.jsasserting the layer-aware version resource and state machine reference appear in the compiled CloudFormation template.Test plan
npm test— 544 passing)verify.test.jsassertions pass against the deployed template🤖 Generated with Claude Code