question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Disable automatic retries for lambda invoke

See original GitHub issue

tldr

When calling client.invoke for lambda functions, I want to disable automatic retries upon timeout.

Steps to reproduce:

import boto3
import json
client = boto3.client('lambda')
response = client.invoke(
    InvocationType='RequestResponse',
    FunctionName='my_lambda',
    LogType='Tail',
    Payload=json.dumps({})
)

Where my_lambda is configured to timeout after 100 seconds, but the code itself requires more time than that.

Desired behaviour

For my particular case, I want client.invoke to return in no more than 100 seconds. If the function requires more than that, client.invoke should raise a botocore.vendored.requests.exceptions.ReadTimeout exception after 100 seconds (or maybe 101 seconds if you factor in overhead).

Observed Behaviour

client.invoke raises the exception botocore.vendored.requests.exceptions.ReadTimeout after 626 seconds. The CloudWatch logs show that the lambda function was invoked 8 times, even though client.invoke was only called once.

(Yes, I know that (8-1) * 100 > 626. I’m confused by that too)

Justification

For this particular case, I know with certainty that if the lambda timed out the first time, it will time out the next 5 times also. So there’s no point retrying. I understand that normally automatic retries may be handy. So I propose that an option is added to client.invoke, which allows you to disable automatic retries.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
ryantuckcommented, Apr 27, 2018

Looks like this was fixed with a cleaner solution in boto/botocore#1260:

import boto3
import botocore.config

cfg = botocore.config.Config(retries={'max_attempts': 0})
client = boto3.client('lambda', config=cfg)
7reactions
tnpxucommented, May 31, 2017

this is my workaround about this issue

config = botocore.config.Config(connect_timeout=300, read_timeout=300)
client = boto3.client('lambda', region_name='us-east-1', config=config)
....
....
# set retry config for lambda = 0
client.meta.events._unique_id_handlers['retry-config-lambda']['handler']._checker.__dict__['_max_attempts'] = 0
....
....
response = client.invoke(
                    FunctionName='',
                    InvocationType='',
                    LogType='',
                    Payload=''
                )
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling and automatic retries in AWS Lambda
When you invoke a function, two types of error can occur. Invocation errors occur when the invocation request is rejected before your function...
Read more >
AWS Lambda - How to stop retries when there is a failure
Put your Lambda inside a state machine (using AWS Step Functions). You can only then disable retries. This blog post I've written gives...
Read more >
Simple Steps to Avoid the Retry Behavior from AWS Lambda
We have covered a few strategies and best practices to follow in order to avoid your Lambda functions from triggering an auto-retry invocation....
Read more >
How AWS Lambda Retry really works - Serverless Framework
Synchronous events (such as API Gateway): will not trigger any auto-retry policy. · Async Events (such as SQS and SNS): will trigger two...
Read more >
How to handle automatic retries in AWS Lambda ... - YouTube
Welcome to the video tutorial on How to handle default retry behavior in the AWS Lambda function. In this tutorial, I have explained...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found