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

Region is missing error when using fromTemporaryCredentials #2958

Closed
kperkins-godaddy opened this issue Oct 29, 2021 · 6 comments
Closed

Region is missing error when using fromTemporaryCredentials #2958

kperkins-godaddy opened this issue Oct 29, 2021 · 6 comments
Assignees
Labels
bug This issue is a bug. investigating Issue is being investigated and/or work is in progress to resolve the issue. p3 This is a minor priority issue workaround-available This issue has a work around available.

Comments

@kperkins-godaddy
Copy link

kperkins-godaddy commented Oct 29, 2021

Describe the bug

I get an unhandled exception (similar to #1466) when trying to read a document from dynamo using fromTemporaryCredentials in my client configuration:

Error: Region is missing
    at default (/src/social-data-api/node_modules/@aws-sdk/credential-providers/node_modules/@aws-sdk/config-resolver/dist-cjs/regionConfig/config.js:10:15)
    at /src/social-data-api/node_modules/@aws-sdk/credential-providers/node_modules/@aws-sdk/node-config-provider/dist-cjs/fromStatic.js:6:77
    at /src/social-data-api/node_modules/@aws-sdk/property-provider/dist-cjs/chain.js:11:28
    at async coalesceProvider (/src/social-data-api/node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:13:24)
    at async Object.isConstant [as region] (/src/social-data-api/node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:24:28)
    at async Object.getEndpointFromRegion (/src/social-data-api/node_modules/@aws-sdk/credential-providers/node_modules/@aws-sdk/config-resolver/dist-cjs/endpointsConfig/utils/getEndpointFromRegion.js:7:20)
    at async buildHttpRpcRequest (/src/social-data-api/node_modules/@aws-sdk/credential-providers/node_modules/@aws-sdk/client-sts/dist-cjs/protocols/Aws_query.js:1201:68)
    at async /src/social-data-api/node_modules/@aws-sdk/middleware-serde/dist-cjs/serializerMiddleware.js:5:21
    at async /src/social-data-api/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:22
    at async /src/social-data-api/node_modules/@aws-sdk/credential-providers/dist-cjs/fromTemporaryCredentials.js:19:33 {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

Here is the reproduction:

const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
const { DynamoDBDocumentClient, GetCommand } = require('@aws-sdk/lib-dynamodb');
const { fromTemporaryCredentials } = require("@aws-sdk/credential-providers");

(async () => {
  try {

    const marshallOptions = {
      convertEmptyValues: false,
      removeUndefinedValues: false,
      convertClassInstanceToMap: false
    };

    const unmarshallOptions = {
      wrapNumbers: false
    };

    const opts = {
      region: 'us-west-2',
      credentials: fromTemporaryCredentials({ params: { RoleArn: "arn:aws:iam::1234512345:role/some-role-name" } })
    }

    const dynamoClient = new DynamoDBClient(opts);

    const translateConfig = { marshallOptions, unmarshallOptions };

    const docClient = DynamoDBDocumentClient.from(dynamoClient, translateConfig);

    const params = {
      Key: {
        account_id: 'some_id',
        data_type: `fb|insights`
      },
      TableName: 'social-data'
    };

    let data = await docClient.send(new GetCommand(params));

  } catch (e) {
    console.error(e);
  }
})();

Your environment

$ uname -a
Darwin LM-C02D76CYMD6R 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64

SDK version number

$ cat node_modules/@aws-sdk/client-dynamodb/package.json | jq .version
"3.38.0"
$ cat node_modules/@aws-sdk/lib-dynamodb/package.json | jq .version
"3.38.0"
$ cat node_modules/@aws-sdk/credential-providers/package.json | jq .version 
"3.39.0"

Is the issue in the browser/Node.js/ReactNative?

Node v12

Details of the browser/Node.js/ReactNative version

$ node --version
v12.4.0

Steps to reproduce

Run the code above.

@kperkins-godaddy kperkins-godaddy added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 29, 2021
@vudh1 vudh1 self-assigned this Oct 29, 2021
@vudh1
Copy link

vudh1 commented Nov 26, 2021

Hi @kperkins-godaddy , thanks for reaching out. I can reproduce your issue, will investigate this more. In that mean time, there is a workaround solution (add another layer of region config)

    const opts = {
        region: 'us-west-2',
        credentials: fromTemporaryCredentials({
            params: {
                // Required. ARN of role to assume.
                RoleArn: "arn:aws:iam::....",
              },
              clientConfig: { region : 'us-west-2'},
        }
      )
    }  

    const dynamoClient = new DynamoDBClient(opts);

Please let me know if this is helpful.

@vudh1 vudh1 removed the needs-triage This issue or PR still needs to be triaged. label Nov 26, 2021
@keplerk
Copy link

keplerk commented Jan 19, 2022

Thanks a lot, i was having the same problem but with pinpoint and i was very confused due trying to set region as a property itself inside the fromTemporaryCredentials until i reached this answerd in the page 1X to end in the following answer.

I thought the region would be picked up from the identitypool string i was wrong.

const Voice = new PinpointSMSVoiceClient({
	region: "us-west-2",
	credentials: fromCognitoIdentityPool({
		identityPoolId: "us-west-2:uniqueuuid",
		clientConfig: { region: "us-west-2" },
	})
});

@vudh1 vudh1 added the workaround-available This issue has a work around available. label Feb 21, 2022
@vudh1 vudh1 removed their assignment Mar 15, 2022
@valoricDe
Copy link

Lol, I hit the exact same problem. Missing/overlooked the clientConfig property. Maybe the error message could contain that region could be located in clientConfig?

@RanVaknin RanVaknin added needs-review This issue/pr needs review from an internal developer. p2 This is a standard priority issue p3 This is a minor priority issue and removed p2 This is a standard priority issue labels Feb 9, 2023
@mukuld
Copy link

mukuld commented Oct 23, 2023

I have exactly the same issue.

When I use static credentials aka ACCESS_KEYS, then the code works just fine. When I use the fromTemporaryCredentials method, I consistently get "Error: Region is missing"

    at asSdkError (http://localhost:3000/static/js/bundle.js:21231:41)
    at http://localhost:3000/static/js/bundle.js:21152:70
    at async http://localhost:3000/static/js/bundle.js:11719:22
    at async http://localhost:3000/static/js/bundle.js:11196:9
    at async coalesceProvider (http://localhost:3000/static/js/bundle.js:21842:18)
    at async SignatureV4.credentialProvider (http://localhost:3000/static/js/bundle.js:21860:18)
    at async SignatureV4.signRequest (http://localhost:3000/static/js/bundle.js:22469:25)
    at async http://localhost:3000/static/js/bundle.js:11998:14
    at async http://localhost:3000/static/js/bundle.js:21142:13
    at async http://localhost:3000/static/js/bundle.js:11719:22  

My code is:

// import { fromTemporaryCredentials } from "@aws-sdk/credential-providers";

function GetTables() {
  // const credentials = fromTemporaryCredentials({
  //   masterCredentials: fromTemporaryCredentials({
  //     params: {
  //       RoleArn:
  //         "arn:aws:sts::123456789012:assumed-role/RoleA",
  //     },
  //   }),
  //   params: {
  //     RoleArn: "arn:aws:iam::123456789012:role/RoleB",
  //   },
  //   clientConfig: { region: "us-east-1" },
  // });

  const credentials = {
    accessKeyId: "KEY_ID",
    secretAccessKey: "SECRET_KEY",
    sessionToken:
      "SESSIONTOKEN",
    expiration: 1698426361000,
  };
  const client = new DynamoDBClient({
    region: "us-east-1",
    credentials: credentials,
  });
  const command = new ListTablesCommand();

  async function ListTables() {
    await client
      .send(command)
      .then((response) => {
        return response.TableNames[1];
      })
      .then((data) => {
        console.log(data);
      });
  }
  ListTables();
}
export default GetTables;

When I switch the credentials I get the desired response.

I also have set the ~/.aws/config with the correct region.

Can someone guide me?

@aBurmeseDev aBurmeseDev added investigating Issue is being investigated and/or work is in progress to resolve the issue. and removed needs-review This issue/pr needs review from an internal developer. labels Nov 22, 2023
@RanVaknin
Copy link
Contributor

Hi everyone on the thread,

I've reproduced this issue with the latest version [email protected] and the region is passed down to fromTemporaryCredentials() successfully:

import AWS from 'aws-sdk';

const s3 = new AWS.S3({
    region: 'us-east-1',
    credentials: new AWS.TemporaryCredentials({
        RoleArn: 'arn:aws:iam::REDACTED:role/my_role'
    })
});

s3.listBuckets((err, data) => {
  if (err) {
    console.log("Error", err);
  } else {
    console.log("Bucket List", data.Buckets);
  }
});

/*
Bucket List [
  { Name: 'REDACTED-REDACTED', CreationDate: 2022-08-02T21:03:10.000Z },
  {
    Name: 'REDACTED',
    CreationDate: 2022-05-05T21:00:37.000Z
  },
  {
    Name: 'amazon-REDACTED-REDACTED',
    CreationDate: 2023-07-27T19:51:44.000Z
  },
  ...
*/

Thank you for your patience.
Ran~

Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Dec 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. investigating Issue is being investigated and/or work is in progress to resolve the issue. p3 This is a minor priority issue workaround-available This issue has a work around available.
Projects
None yet
Development

No branches or pull requests

7 participants