Skip to content
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

Send x-amzn-query-mode to inform a service with the awsQueryCompatible trait that SDK is operating in that mode #3883

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

ysaito1001
Copy link
Contributor

@ysaito1001 ysaito1001 commented Oct 17, 2024

Motivation and Context

If a client SDK is generated from a service model that has the awsQueryCompatible trait, the SDK now sends x-amzn-query-mode in the request header for the service.

Description

The change in the PR itself is pretty simple, as said in the title. It's more important to understand why we are making these changes. The rest of the description will focus on the reason driving this change.

The awsQueryCompatible trait, added by a service, is specifically for deserializing errors. It allows for deserializing errors in a backward compatible manner when the service migrates away from the AWS Query protocol.

With the awsQueryError trait, the AWS Query supports customizing error codes that is not supported in any other AWS protocol, e.g.

@awsQueryError(
    code: "AWS.SimpleQueueService.NonExistentQueue",
    httpResponseCode: 400
)
@error("client")
structure QueueDoesNotExistException {
    message: String
}

In short, the awsQueryCompatible trait makes it possible to continue using the custom error codes even when the service drops support for the AWS Query protocol and switches to other protocols such as awsJson1_0 and rpcv2Cbor (see example snippet in the Smithy documentation)

The changes in this PR would be unnecessary if a service had originally supported only @awsQuery and had atomically updated its Smithy model to replace @awsQuery with @awsQueryCompatible and @awsJson1_0 in lockstep. However, that's not always the case in practice.

Consider a service whose Smithy model supports two protocols: @awsQuery and @awsJson1_0. While the Rust SDK maintains an ordered map of protocols to determine which one to use, it’s possible for two groups of client SDKs to be generated over time, depending on which protocol was added first to the service:

  1. Client SDKs that understand the awsQuery protocol (this group can interpret custom error codes sent in responses from the service)
  2. Client SDKs that understand the awsJson1_0 protocol (this group does not interpret custom error codes)

Now, imagine if the service updated its Smithy model to remove @awsQuery and add @awsQueryCompatible (likely it would add the awsQueryError trait to an error structure somewhere as well). The supported protocols would then be @awsJson1_0 and @awsQueryCompatible. Group 1 remains unaffected, as they can continue deserializing responses with custom error codes. However, group 2 would now be broken, as they would begin receiving custom error codes in responses due to the awsQueryCompatible trait.

To prevent the issue for group 2 above, the x-amzn-query-mode header in this PR informs the service that it should only send back custom error codes if the client SDK is built with the awsQueryCompatible trait. With this update, client SDKs built only with the awsJson1_0 will remain unaffected, as they do not send the x-amzn-query-mode header to the service and, therefore, will not receive custom error codes in response.

Testing

  • Added a Kotlin test to check for the x-amzn-query-mode header
  • Added x-amzn-query-mode as a required header to a protocol test for the awsQueryCompatible

Checklist

  • For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "aws-sdk-rust" in the applies_to key.

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

Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@ysaito1001 ysaito1001 marked this pull request as ready for review October 18, 2024 17:26
@ysaito1001 ysaito1001 requested review from a team as code owners October 18, 2024 17:26
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link

A new generated diff is ready to view.

  • No codegen difference in the AWS SDK
  • Client Test (ignoring whitespace)
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@ysaito1001 ysaito1001 added this pull request to the merge queue Oct 18, 2024
Merged via the queue into main with commit 4b66264 Oct 18, 2024
44 checks passed
@ysaito1001 ysaito1001 deleted the ysaito/additional-header-for-aws-query-compatible branch October 18, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants