Lambda's `retry_attempts` argument does not seem to work when it is the target of Eventbridge rule
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When the target of an Eventbridge rule is a Lambda, `retry_attempts` argument does not seem to be binding. For example, if I set `retry_attempts` to be 0 and the Lambda fails, the Lambda will be invoked with the same `RequestId` 1 minute later and another invocation 2 minutes after that (also with the same `RequestId)`. That is a total of 3 invocations (1 original + 2 retries).
I discovered that on instantiating a `aws_cdk.aws_lambda.Function` that the argument `retry_attempts` has a default value of 2.
I would like to set `retry_attempts` to 0 when I add the Lambda as the target to the Eventbridge rule, not set `retry_attempts` when instantiating a Lambda `Function` (I want to be able to leave this value unset as the default). There's presumably a use case where this distinction is important such as if there's another asynchronous invocation of this Lambda where you want it to have 2 retries but you specifically want 0 retries as the Eventbridge rule target.
Also, there is a case where you want retries from Eventbridge to be very high. When adding Lambda as Eventbridge target, `retry_attempts` allows a maximum of 185 retries. However, Lambda `Function` instantiation allow allows `retry_attempts` to only 2 retries. I assume that having more than 2 Lambda retries as part of Eventbridge target is not currently possible thru `cdk`.
### Expected Behavior
I expected when setting up the Eventbridge rule's target that the `retry_attempts` would work.
### Current Behavior
`retry_attempts` as set by Lambda `Function`'s instantiation is used instead.
### Reproduction Steps
```python
from aws_cdk import (
App,
Duration,
Stack,
aws_events as events,
aws_events_targets as events_targets,
aws_lambda as _lambda,
)
class TempStack(Stack):
def __init__(
self, scope, construct_id, **kwargs
) -> None:
super().__init__(scope, construct_id, **kwargs)
self.broken_lambda = _lambda.Function(
self,
"BrokenLambda",
runtime=_lambda.Runtime.PYTHON_3_9,
code=_lambda.InlineCode("def handler(event, context): raise"),
handler="index.handler",
# retry_attempts=0, # actually does something. I don't want to set this argument
)
self.scheduled_eventbridge_event = events.Rule(
self,
"RunEvery3Minutes",
event_bus=None,
schedule=events.Schedule.rate(Duration.minutes(3)),
)
self.scheduled_eventbridge_event.add_target(
events_targets.LambdaFunction(
handler=self.broken_lambda,
retry_attempts=0, # doesn't seem to do anything. I want to use this argument
)
)
app = App()
TempStack(app, "TempStack")
app.synth()
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.77.0 (build 06a0b19)
### Framework Version
_No response_
### Node.js Version
9.5.0
### OS
macOs Ventura 13.0
### Language
Python
### Language Version
Python 3.9.16
### Other information
_No response_
Contributor guide
Research direction
Start with the provided TempStack reproduction and inspect aws_events_targets.LambdaFunction together with aws_lambda.Function to trace how retry_attempts reaches the synthesized EventBridge target and Lambda configuration. Add or update focused tests for retry_attempts=0 and values above 2, then verify the synthesized configuration matches the target-level setting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100