Create EventBridge Rule with Retry Policy Using AWS CLI

Use AWS CLI to create Amazon EventBridge Rules with schedule expressions and configure retry policies (MaximumRetryAttempts & MaximumEventAgeInSeconds) targeting AWS Lambda

This snippet demonstrates how to create Amazon EventBridge scheduled rules with retry policies using the AWS CLI, leveraging aws events put-rule to create a scheduled rule and aws events put-targets to attach a Lambda target with a configured retry policy that controls MaximumRetryAttempts (0-185) and MaximumEventAgeInSeconds (60-86400) to handle failed invocations.

Copy the commands on your CLI and replace the LAMBDA_ARN. Modidy the schedule expressions and retry policy values as desired

aws events put-rule \
  --name "retry-rule-test" \
  --schedule-expression "rate(5 minutes)" \
  --state ENABLED \
  --description "Runs every 5 minutes with retry policy" \
&& \
aws events put-targets \
  --rule "retry-rule-test" \
  --event-bus-name "default" \
  --targets "$(cat <<EOF
[
  {
    "Id": "my-target-id",
    "Arn": "<LAMBDA_ARN>",
    "RetryPolicy": {
      "MaximumRetryAttempts": 3,
      "MaximumEventAgeInSeconds": 3600
    }
  }
]
EOF
)"
                                


Created by:

Archana V

Archana V

Solutions Architect at AWS

Follow on LinkedIn