Skip to content

fix(stateMachine): update state machine when useExactVersion layers change#757

Open
VirtueMe wants to merge 1 commit intomasterfrom
fix/452_exact-version-layer-update
Open

fix(stateMachine): update state machine when useExactVersion layers change#757
VirtueMe wants to merge 1 commit intomasterfrom
fix/452_exact-version-layer-update

Conversation

@VirtueMe
Copy link
Copy Markdown
Collaborator

Closes #452

Summary

  • Root cause: Serverless Framework generates Lambda version logical IDs from the function's code artifact hash. When only a layer changes, the hash is unchanged, so no new version is published and the state machine definition stays identical — CloudFormation skips the update entirely.
  • Fix: when 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 new AWS::Lambda::Version resource whose logical ID embeds that hash. When layers change, the hash changes, a new version is published, and the state machine DefinitionString changes so CloudFormation updates it.
  • Add five unit tests and a new use-exact-version integration fixture with a verify.test.js asserting the layer-aware version resource and state machine reference appear in the compiled CloudFormation template.

Test plan

  • Unit tests pass (npm test — 544 passing)
  • Integration fixture deploys cleanly to LocalStack
  • verify.test.js assertions pass against the deployed template
  • Functions without layers: state machine unchanged (no extra version resource created)
  • ARN string layers: hash changes when the version number in the ARN changes

🤖 Generated with Claude Code

… 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>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

Open in StackBlitz

npm i https://pkg.pr.new/serverless-operations/serverless-step-functions@757

commit: 9ee1d4d

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Step functions are not updated when useExactVersion is true and lambda layers are updated

1 participant