Skip to content

fix: handle CloudFormation intrinsic functions in Arguments.StateMachineArn#709

Merged
zirkelc merged 1 commit intoserverless-operations:masterfrom
lracicot:fix/handle-intrinsic-function-in-arguments-statemachinearn
Mar 23, 2026
Merged

fix: handle CloudFormation intrinsic functions in Arguments.StateMachineArn#709
zirkelc merged 1 commit intoserverless-operations:masterfrom
lracicot:fix/handle-intrinsic-function-in-arguments-statemachinearn

Conversation

@lracicot
Copy link
Copy Markdown
Contributor

@lracicot lracicot commented Mar 20, 2026

Fixes #704

Summary

  • When using JSONata QueryLanguage with a CloudFormation intrinsic function (e.g. !Sub or Fn::Sub) as StateMachineArn in Arguments, getStateMachineArn() crashes with TypeError: state.Arguments.StateMachineArn.trim is not a function because it assumes the value is a string, but intrinsic functions resolve to objects like {"Fn::Sub": "..."}.
  • Added a type check before calling .trim() — when StateMachineArn is not a string (i.e. a CloudFormation intrinsic), return it as-is for use in the IAM policy resource. This matches the existing behavior for Parameters.StateMachineArn which already handles intrinsics correctly.

Reproduction

# serverless.yml — this crashes on deploy
stepFunctions:
  stateMachines:
    Workflow:
      definition:
        States:
          InvokeChild:
            Type: Task
            Resource: 'arn:aws:states:::states:startExecution.sync:2'
            QueryLanguage: JSONata
            Arguments:
              StateMachineArn: !Sub "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:ChildMachine"
              Input:
                key: "{% $states.input.value %}"
            End: true
TypeError: state.Arguments.StateMachineArn.trim is not a function
    at getStateMachineArn (compileIamRole.js:452:55)

Changes

  • lib/deploy/stepFunctions/compileIamRole.js: Check typeof arn !== 'string' before calling .trim() in getStateMachineArn()
  • lib/deploy/stepFunctions/compileIamRole.test.js: Added test case for JSONata with CloudFormation intrinsic StateMachineArn

Test plan

  • All 104 existing tests pass
  • New test case verifies Fn::Sub object is passed through correctly as the IAM policy resource

…ineArn

When using JSONata QueryLanguage with a CloudFormation intrinsic function
(e.g. !Sub or Fn::Sub) as StateMachineArn in Arguments, getStateMachineArn()
calls .trim() on the value expecting a string, but intrinsic functions resolve
to objects like {"Fn::Sub": "..."}, causing:

  TypeError: state.Arguments.StateMachineArn.trim is not a function

Check if StateMachineArn is a string before calling .trim(). When it is an
object (CloudFormation intrinsic), return it as-is for use in the IAM policy
resource, matching the existing behavior for Parameters.StateMachineArn.

Made-with: Cursor
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

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

commit: 9114fb8

@zirkelc zirkelc merged commit 799c09b into serverless-operations:master Mar 23, 2026
3 checks passed
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.

StateMachineArn not supporting Intrinsic Functions when using JSONata

3 participants