(aws_stepfunctions_tasks): Lambda Functions deployed with LambdaInvoke won't generate Cloudwatch metrics
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
Hello,
I think I've found an issue with CDK and the way it adds Lambda function to the JSON definition with LambdaInvoke. This disables the possibility to get [Lambda Function Metrics] in Cloudwatch.
Let me explain.
We are using CDK to create our State Machine. To add Lambda Functions to our State Machine, we use LambdaInvoke, as intended.
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions_tasks.LambdaInvoke.html
This generates a definition, with States juste like this :
```
"LambdaState1": {
"Next": "LambdaState2",
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:eu-west-3:ACCOUNT:function:Lambda1ARN"
}
},
```
Please note that this definition has :
- Resource as "arn:aws:states:::lambda:invoke"
- Parameters.FunctionName as our Lambda Arn
Our state machine is running fine but this definition doesn't generate any metrics (such as "LambdaFunctionsStarted", "LambdaFunctionsSucceeded" and so on) for our deployed lambda functions.
As a matter of fact, the State Machine does not consider this state (here LambdaState1) as a LambdaFunction, but as a simple Task. Which, I presume, is the issue here.
When playing with this, I've found that this following definition does work.
```
"LambdaState1": {
"Next": "LambdaState2",
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-3:ACCOUNT:function:Lambda1ARN"
},
```
The state is considered a LambdaFunction, not a Task, from the state machine's point of view.
And, more importantly, metrics from this Lambda are indeed created.
But I can't seem to figure out how to force LambdaInvoke to generate something like this. With the ARN as a ressource.
So I suspect something is not quite right here.
### Expected Behavior
I would expect LambdaInvoke to add lambda functions as LambdaFunction, and not as Task.
Even if the documentation clealy states : "Invoke a Lambda function as a Task.".
If so, how can I force CDK to treat my Lambda as a LambdaFunction ? Is there any property available to do that ?
### Current Behavior
Adding a lambda function to a state machine like this:
```
const myLambdaState = new LambdaInvoke(
this,
"my-lambda-state",
{
lambdaFunction: new NodeJsFunction(...),
retryOnServiceExceptions: false,
}
);
```
Generates the following definition :
```
"myLambdaState": {
"End": "true",
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:eu-west-3:ACCOUNT:function:Lambda1ARN"
}
},
```
Instead of:
```
"myLambdaState": {
"End": "true",
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-3:ACCOUNT:function:Lambda1ARN"
},
```
So the lambda is not considered a LambdaFunction, but a Task, for the StateMachine, hence not generating any Lambda specific metrics.
### Reproduction Steps
Any lambda function deployed with LambdaInvoke will have the following definition:
```
"myLambdaState": {
"End": "true",
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:eu-west-3:ACCOUNT:function:Lambda1ARN"
}
},
```
Any new execution will work but you'll find that no metrics in [Lambda Function Metrics] is available.
### Possible Solution
When using LambdaInvoke, CDK could create the following definition instead:
```
"myLambdaState": {
"End": "true",
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-3:ACCOUNT:function:Lambda1ARN"
},
```
### Additional Information/Context
_No response_
### CDK CLI Version
2.63.1
### Framework Version
_No response_
### Node.js Version
16
### OS
Windows
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Begin at the aws_stepfunctions_tasks.LambdaInvoke entry point and inspect how its synthesized state-machine definition represents the Lambda target. Compare the two Resource forms in the reproduction and verify their CloudWatch metrics behavior, then add focused coverage for the expected definition and supported outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100