Skip to content

fix(iam): prevent nested Fn::Sub when lambda Resource is a Fn::Sub expression#749

Merged
zirkelc merged 1 commit intomasterfrom
fix-302-lambda-fn-sub-iam-policy
Apr 4, 2026
Merged

fix(iam): prevent nested Fn::Sub when lambda Resource is a Fn::Sub expression#749
zirkelc merged 1 commit intomasterfrom
fix-302-lambda-fn-sub-iam-policy

Conversation

@VirtueMe
Copy link
Copy Markdown
Collaborator

@VirtueMe VirtueMe commented Apr 2, 2026

Summary

Fixes #302.

When a Task state's Resource is a Fn::Sub object — as produced by plugins like serverless-pseudo-parameters that convert #{AWS::Region} to ${AWS::Region} — the versioned ARN (:*) was generated using the array form of Fn::Sub with the Fn::Sub object as a variable map value:

{ "Fn::Sub": ["${functionArn}:*", { "functionArn": { "Fn::Sub": "arn:..." } }] }

CloudFormation does not support nesting Fn::Sub as a variable map value, so this produces a MalformedPolicyDocument error on deploy.

Fix

Introduces getVersionedArn() in lambda.js which detects when the base ARN is already a Fn::Sub and appends :* directly to the template string:

{ "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:my-fn:*" }

Ref and Fn::GetAtt resources are unaffected and continue to use the existing array form.

Test plan

  • Two new unit tests in lambda.test.js (written before the fix, confirmed failing then passing)
  • fnSubMachine state machine added to the basic-state-machine integration fixture, covering the Fn::Sub resource reference style alongside the existing Fn::GetAtt one
  • verify.test.js added to basic-state-machine fixture asserting no nested Fn::Sub in the IAM policy and a valid versioned ARN

🤖 Generated with Claude Code

…pression (#302)

When a Task state's Resource was a Fn::Sub object (produced by plugins like
serverless-pseudo-parameters), the versioned ARN (:*) was generated as a
Fn::Sub array with the Fn::Sub object as a variable map value — invalid
CloudFormation that causes MalformedPolicyDocument errors on deploy.

Introduces getVersionedArn() which appends :* directly to the Fn::Sub
template string instead of nesting it as a variable value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 2, 2026

Open in StackBlitz

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

commit: 028ad7a

@zirkelc zirkelc merged commit c0f554f into master Apr 4, 2026
4 checks passed
@zirkelc zirkelc deleted the fix-302-lambda-fn-sub-iam-policy branch April 4, 2026 04:36
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.

Wrong policy state machine generation for lambda arn

2 participants