aws / aws/aws-cdk

(aws-stepfunctions-task): (LambdaInvoke task fails to handle parametrized function arn)

Open
#23,658 4 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-stepfunctions-tasks effort/medium feature-request p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### Describe the bug

I want to use `LambdaInvoke` task in a step function, but I want to get function arn from the payload. For example:
```ts
new LambdaInvoke(
this,
'invoke-lambda',
{
lambdaFunction: Function.fromFunctionArn(
this,
'lambda',
JsonPath.stringAt('$.functionArn')
)
}
);
```

### Expected Behavior

I expect this to work correctly and to fetch function arn dynamically from payload

### Current Behavior

Currently this fails, because LambdaInvoke attempts to add "lambda:invoke" permission to state machine role default policy for resource `$.functionArn`, which fails at deployment time with following error:
```
9:45:00 AM | CREATE_FAILED | AWS::IAM::Policy | dynamodb-dlq-redri...Role/DefaultPolicy
Resource $.functionArn must be in ARN format or "*". (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: 1d7da978-1455-49a8-b167-90c5b6b5825e; Proxy: null)
```

### Reproduction Steps

```ts
const lambdaInvoke = new LambdaInvoke(
this,
'invoke-lambda',
{
lambdaFunction: Function.fromFunctionArn(
this,
'lambda',
JsonPath.stringAt('$.functionArn')
)
}
);
new StateMachine(this, 'test', {
stateMachineName: 'test',
stateMachineType: StateMachineType.STANDARD,
definition: lambdaInvoke,
});
```

### Possible Solution

Do not attempt to modify State machine role permissions, if function reference in `LambdaInvoke` class is using payload reference.

### Additional Information/Context

_No response_

### CDK CLI Version

2.49.0

### Framework Version

_No response_

### Node.js Version

18

### OS

Ubuntu 20

### Language

Typescript

### Language Version

4.9.4

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the LambdaInvoke construct and reproduce the provided StateMachine example with a function ARN read from $.functionArn. Trace how permissions are added for that reference; done means deployment succeeds without generating an invalid IAM resource while the Lambda invocation still uses the payload ARN.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
authorization, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.