aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
[client-cloudfront] Region should not be required
Is your feature request related to a problem? Please describe.
When working with #3024, I find that CloudFront needs to set region in configuration in order to work even though AWS_SDK_LOAD_CONFIG is not set. However, in the latest version of v2, this is not the case (AWS_SDK_LOAD_CONFIG is introduced in https://github.com/aws/aws-sdk-js/pull/1391).
import { CloudFront } from “@aws-sdk/client-cloudfront”; // v3.41.0
const accessKeyId = “accessKeyId”;
const secretAccessKey = “secretAccessKey”;
const sessionToken = “sessionToken”;
const credentials = { accessKeyId, secretAccessKey, sessionToken };
const client = new CloudFront({ credentials });
This is the error: Region is missing
Describe the solution you'd like
CloudFront v3 SDK should not look for region.
In this documentation, region should not be included when initiating CloudFront client.
The error Region is missing is also appear when I init S3Client.
import { S3Client } from '@aws-sdk/client-s3'; // "@aws-sdk/client-s3": "^3.142.0",
new S3Client({
credentials: {
accessKeyId: '...',
secretAccessKey: '...',
sessionToken: '...',
}
forcePathStyle: true,
apiVersion: 's3v4'
});
import { CloudFrontClient } from '@aws-sdk/client-cloudfront';
const client = new CloudFront({ region: 'definitely-not-a-valid-region' });
The value for region can be any non-empty string and it doesn't throw the Region is missing error.
@vudh1 ,@adityachandak287 this is intentional.
The AWS SDK requires a region for the client so it can route to the appropriate Cloudfront endpoint for the partition associated with the given region. https://docs.aws.amazon.com/general/latest/gr/cf_region.html
With regards to non-empty string, that is because we don’t strip the region identifiers and treat them as entirely opaque. What you are witnessing by such behavior is that if they given a non zero length string that the SDK doesn’t know how to explicitly handle as a region, it will just by default fallback to the AWS partition and try to form a URL using that region identifier. In this case since the service is not a regional service, it will just fallback to the service’s partition endpoint. The SDK does this for forwards compatibility reasons so that new regions “just work” without requiring users to update.
Thanks, Ran~
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.