You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(iam): resolve local Lambda Ref to static ARN to prevent MalformedPolicyDocument (#746)
When a task state uses `Resource: !Ref localFunction`, two bugs occur:
1. The IAM role's policy resource contains `{ Ref: ParseCSVLambdaFunction }`.
CloudFormation resolves a Lambda function Ref to the function *name*
(e.g. `my-service-dev-parseCSV`), not its ARN — IAM rejects this with
MalformedPolicyDocument.
2. The state machine definition also receives the function name string as
its Resource. Step Functions rejects this with InvalidDefinition.
In both cases the Ref also introduces a CloudFormation resource dependency
that can cause the circular dependency error reported in #470 when the
referenced Lambda has an env var pointing back at the state machine.
Fix: add `resolveLambdaFunctionName` to `lib/utils/aws.js`. When a Ref
points to a local function whose deployed name is known at compile time
(via `serverless.service.functions[key].name`), callers emit a static
`Fn::Sub` ARN string instead of the Ref. Two call sites are fixed:
- `iamStrategies/lambda.js` — IAM policy resource for both the direct
lambda ARN path (getFallbackPermissions) and the lambda:invoke SDK
integration path (getPermissions)
- `compileStateMachines.js` — definition string Fn::Sub params: local
Lambda Refs are inlined as static ARNs directly in the definition
string, eliminating both the CF dependency and the name-not-ARN error
Adds a `circular-dependency` integration fixture reproducing #470.
LocalStack confirms: without the fix the IAM role fails with
MalformedPolicyDocument and the state machine fails with InvalidDefinition;
with the fix the full stack deploys cleanly.
Closes#470
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
0 commit comments