Skip to content

Send the amz-sdk-invocation-id and amz-sdk-request headers from AWS clients - #947

Open
AlexDaines wants to merge 3 commits into
developfrom
adaines/amz-sdk-invocation-id
Open

AlexDaines wants to merge 3 commits into
developfrom
adaines/amz-sdk-invocation-id

Conversation

@AlexDaines

@AlexDaines AlexDaines commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Issue #, if available: N/A

Description of changes:

AWS clients don't send the amz-sdk-invocation-id and amz-sdk-request headers. The headers let a service group the attempts of one call and see the attempt number. botocore sets both in add_retry_headers.

This change adds RetryHeadersInterceptor to smithy_aws_core.interceptors.retry_headers, and a generator integration that adds it to every client of a service with the aws.api#service trait:

  • amz-sdk-invocation-id holds a random UUID. The interceptor sets it once for each call, before the first attempt, so every attempt of the call sends the same value and the signature covers it.
  • amz-sdk-request holds attempt=N; max=M. max is the max_attempts of the call's retry strategy. When that value is missing or isn't a positive integer, the header holds only attempt=N. This change doesn't send the ttl part, which botocore adds on a retry from the Date header of the previous response and the read timeout (_calculate_ttl).

If the caller set either header, the interceptor overwrites it. That's deliberate: the values describe the SDK's own attempts, and a botocore request also goes out with botocore's values.

The two headers are in separate commits. The commit for amz-sdk-invocation-id also has the generator integration and the regenerated protocol test clients. The commit for amz-sdk-request changes only smithy-aws-core, not the generator.

In aws-sdk-python, test_should_set_retry_headers is skipped with a TODO for these headers. I ran it against a Lambda client generated from this change, and it passes. I'll remove that skip once a release has this change.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Every attempt of a call now carries the same random UUID in
amz-sdk-invocation-id, and each call gets a new one, so a service can
tell which requests are attempts of the same call. The header is set
once, before the retry loop, so it is signed with the request.
Each attempt now carries its attempt number and the most attempts the
call's retry strategy allows, as in attempt=2; max=3, so a service can
see how the SDK retries. When the strategy has no max_attempts of 1 or
more, the header carries only the attempt number. The header is set on
each attempt before it is signed.
@AlexDaines
AlexDaines marked this pull request as ready for review November 20, 2026 19:52
@AlexDaines
AlexDaines requested a review from a team as a code owner November 20, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant