Skip to content
Unverified Commit 5461e4fc authored by ysaito1001's avatar ysaito1001 Committed by GitHub
Browse files

Allow custom partitions to be used at runtime (#3610)

## Motivation and Context
This PR adds support for custom partition to be loaded at runtime. Use
cases for this feature are mostly private, i.e. using a pre-GA region
from the AWS SDK for Rust (or more broadly, from Smithy SDK for Rust).

## Description
Today, AWS SDK for Rust uses
[sdk-partitions.json](https://github.com/awslabs/aws-sdk-rust/blob/c6f4f53506604b8d52a5fd735b057c6225ed9aae/aws-models/sdk-partitions.json).
Unless a customer specifies a full URL using the `.endpoint_url` method,
the SDK is responsible for constructing the full URL for an endpoint
given a specified region, using a partitions file. It is essentially a
recipe for how to do so, such as providing DNS suffix like
`csp.hci.ic.gov`.

Certain customers need to use the SDK for a pre-GA region that is not
listed in the said public partitions file. When a region is not listed,
it will not be mapped to a known partition, and the SDK defaults to
construct endpoints using the patterns for the public AWS partition,
i.e. `amazonaws.com`. The assumption of "defaulting to the public
partition" may not always work for those customers. This PR, therefore,
adds an environment variable so that customers can specify a full path
to a custom partitions file.

Why look up the environment variable at runtime but not at codegen time?
The primary reason is maximum availability for the feature. Customers
can use a custom partitions file even for SDKs already published on
crates.io. If configuration were at codegen time, it wouldn't be
possible to use a custom partitions file for those SDKs.

## Testing
Since the code change uses an environment variable, no automated tests
have added for this. Instead, manually verified the following. Given a
fake custom paritions file that includes
```
  {
    "id" : "custom-partition",
    "outputs" : {
      "dnsSuffix" : "custom.com",
      "dualStackDnsSuffix" : "custom.com",
      "implicitGlobalRegion" : "us-custom-region-1",
      "name" : "custom-partition",
      "supportsDualStack" : false,
      "supportsFIPS" : true
    },
    "regionRegex" : "^us\\-custom\\-*",
    "regions" : {
      "us-custom-region-1" : {
        "description" : "US CUSTOM REGION 1"
      } 
    } 
  }
```
when we run the following test
```
#[tokio::test]
async fn test_custom_partition() {
    let (http_client, captured_request) = capture_request(None);
    std::env::set_var("SMITHY_CLIENT_SDK_CUSTOM_PARTITIONS", <full path to that custom partition>);
    let sdk_config = aws_config::from_env().region("us-custom-region-1").http_client(http_client).load().await;
    let client = Client::new(&sdk_config);
    let _ = client.list_buckets().send().await;
    dbg!(captured_request.expect_request());
}
```
`dbg!` shows a fully constructed endpoint URL:
```
    uri: Uri {
        as_string: "https://s3.us-custom-region-1.custom.com/?x-id=ListBuckets",
        parsed: H0(
            https://s3.us-custom-region-1.custom.com/?x-id=ListBuckets,
        ),
    },
```
If we do not set the environment variable in the above snippet, then we
get this endpoint URL instead:
```
    uri: Uri {
        as_string: "https://s3.us-custom-region-1.amazonaws.com/?x-id=ListBuckets",
        parsed: H0(
            https://s3.us-custom-region-1.amazonaws.com/?x-id=ListBuckets,
        ),
    },
```

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent f15e7b3d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment