I have an AWS Lambda (python3.7 runtime) that runs certain task, and its MaximumRetryAttempts is set to 1 (meaning it can fail once, then have 1 more try).
For a reasons I won't get into, I want to know, at runtime, if this is the first attempt or the second. Is there any way to achieve that?
Alternative, To query aws cloud watch, you can also use AWS System Parameter Store with aws_request_id as part of Parameter name to uniquely identify it. Furthermore, keep lambda retry count as value of this Parameter. Increment it per execution of lambda based on aws_request_id. If threshold reach then handle as per your logic and delete the AWS System Parameter Store with name having the aws_request_id for which threshold is reached. Summary- you just need some storage which keeps mapping of aws_request_id and retry count.