BreenDeen
BreenDeen

Reputation: 732

Using smithy aws client library fails with Region is missing

I am using the AWS S3 client with the following AWS libraries in my package.json @aws-sdk/client-s3": "^3.540.0", "@smithy/node-http-handler": "^2.5.0"

I created the S3 Client properties specifying them like this:

            getAgent(): Agent {
                 const agent = new Agent({
                        rejectUnauthorized: true,
                      });
                return agent;
            } 


           async getClient (): Promise<S3Client> {
               const agent = this.getAgent()
               const endPoint: EndpointV2  = {url: new URL('url')} as EndpointV2 
               const s3Config = {
                region: 'us-west-2',
                endpoint: endPoint,
                credentials: {
                  accessKeyId: 'myKey' ,
                  secretAccessKey: 'mySecret'
                },
               requestHandler:new NodeHttpHandler({
                  httpAgent: agent,
                  httpsAgent: agent
               }),
               retryStrategy: new ConfiguredRetryStrategy(
                   13, 3000
               )
              } 
              const client = new S3Client([s3Config]);
              return client
          }


However, when I instantiate the client I get the following error

Error is Error: Region is missing at default (/home/app/src/node_modules/@smithy/config-resolver/dist-cjs/index.js:117:11) at /home/app/src/node_modules/@smithy/node-config-provider/dist-cjs/index.js:72:104 at /home/app/src/node_modules/@smithy/property-provider/dist-cjs/index.js:79:33 at async coalesceProvider (/home/app/src/node_modules/@smithy/property-provider/dist-cjs/index.js:106:18) at async /home/app/src/node_modules/@smithy/property-provider/dist-cjs/index.js:117:20 at async region (/home/app/src/node_modules/@smithy/config-resolver/dist-cjs/index.js:142:30) at async /home/app/src/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:89:28 at async /home/app/src/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:120:14 at async /home/app/src/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22

The region is clearly present. This error only started when I updated my application to use the smithy library since the previous library has been deprecated. Please help in resolving this

Upvotes: 0

Views: 1185

Answers (1)

BreenDeen
BreenDeen

Reputation: 732

My mistake, I am passing the properties in an array, when creating the client It should be created like this

 const client = new S3Client(s3Config);
 instead of
 
 const client = new S3Client([s3Config]);


 

Upvotes: 1

Related Questions