-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix flaky lambda test event retry reserved concurrency #12441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joe4dev
merged 6 commits into
master
from
fix-flaky-lambda-test-event-retry-reserved-concurrency
Mar 28, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5385f44
Add no retry client fixture
joe4dev aad2f8f
Fix flaky async event concurrency test
joe4dev f3bc61d
Make notify explicit and dynamic
joe4dev d9fb8b4
Move `aws_client_no_retry` fixture to the LocalStack testing fixtures
joe4dev ff17ef5
Add env_var and label to notifier Lambda
joe4dev d090501
Add clarification about specific errors
joe4dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import datetime | ||
import json | ||
import os | ||
import time | ||
|
||
import boto3 | ||
|
||
sqs_client = boto3.client("sqs", endpoint_url=os.environ.get("AWS_ENDPOINT_URL")) | ||
|
||
|
||
def handler(event, context): | ||
"""Example: Send a message to the queue_url provided in notify and then wait for 7 seconds. | ||
The message includes the value of the environment variable called "FUNCTION_VARIANT". | ||
aws_client.lambda_.invoke( | ||
FunctionName=fn_arn, | ||
InvocationType="Event", | ||
Payload=json.dumps({"notify": queue_url, "env_var": "FUNCTION_VARIANT", "label": "01-sleep", "wait": 7}) | ||
) | ||
|
||
Parameters: | ||
* `notify`: SQS queue URL to notify a message | ||
* `env_var`: Name of the environment variable that should be included in the message | ||
* `label`: Label to be included in the message | ||
* `wait`: Time in seconds to sleep | ||
""" | ||
if queue_url := event.get("notify"): | ||
message = { | ||
"request_id": context.aws_request_id, | ||
"timestamp": datetime.datetime.now(datetime.UTC).isoformat(), | ||
} | ||
if env_var := event.get("env_var"): | ||
message[env_var] = os.environ[env_var] | ||
if label := event.get("label"): | ||
message["label"] = label | ||
print(f"Notify message: {message}") | ||
sqs_client.send_message(QueueUrl=queue_url, MessageBody=json.dumps(message)) | ||
|
||
if wait_time := event.get("wait"): | ||
print(f"Sleeping for {wait_time} seconds ...") | ||
time.sleep(wait_time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
Yo
2D02
u must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can clarify here, that this is mostly needed when exceptions are tested which have retries? So all listed in here: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html#legacy-retry-mode (or matching the http status codes also listed there).
For a "ResourceNotFound" exception for example, this is not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, we are indeed using the legacy retry mode, which makes things even worse 😬 .
I wanted to keep it simple and long-term given there are no adverse effects of using the no_retry client with a non-retrying exception. Nevertheless, I added the clarification for most accurate and actionable advice at the current status.