aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

[client-cloudfront] Region should not be required

Open vudh1 opened this issue 4 years ago • 2 comments

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.

vudh1 avatar Nov 17 '21 21:11 vudh1

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'
        });

live680g avatar Aug 05 '22 03:08 live680g

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.

adityachandak287 avatar Aug 22 '22 12:08 adityachandak287

@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~

RanVaknin avatar Feb 18 '23 00:02 RanVaknin

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.

github-actions[bot] avatar Mar 05 '23 00:03 github-actions[bot]