简体   繁体   English

aws-sdk-js DynamoDB引发错误:Request.VALIDATE_REGION的配置中缺少凭据

[英]aws-sdk-js DynamoDB throwing Error: Missing credentials in config at Request.VALIDATE_REGION

I'm trying to do a batchGetItem with DynamoDB on react-native and it's throwing the following error: 我正在尝试在React react-native上使用DynamoDB进行batchGetItem,并抛出以下错误:

Error: Missing credentials in config
    at Request.VALIDATE_REGION (aws-sdk-react-native.js:10326)
    at Request.callListeners (aws-sdk-react-native.js:10112)
    at Request.emit (aws-sdk-react-native.js:10084)
    at Request.emit (aws-sdk-react-native.js:14062)
    at Request.transition (aws-sdk-react-native.js:13413)
    at AcceptorStateMachine.runTo (aws-sdk-react-native.js:14199)
    at Request.runTo (aws-sdk-react-native.js:13788)
    at Request.send (aws-sdk-react-native.js:13752)
    at features.constructor.makeUnauthenticatedRequest (aws-sdk-react-native.js:6689)
    at features.constructor.getId (aws-sdk-react-native.js:9118) "ConfigError: Missing credentials in config
    at Request.VALIDATE_REGION (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:89572:43)
    at Request.callListeners (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:89495:17)
    at Request.emit (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:89470:10)
    at Request.emit (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:92539:15)
    at Request.transition (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:92283:11)
    at AcceptorStateMachine.runTo (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:92642:13)
    at Request.runTo (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:92362:16)
    at Request.send (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:92352:11)
    at features.constructor.makeUnauthenticatedRequest (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:87518:31)
    at features.constructor.getId (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:88786:17)"

I've authenticated a user, the user has a IAM role and permission to perform the batchGetItem. 我已经对用户进行身份验证,该用户具有IAM角色并有权执行batchGetItem。

Here's a snippet of the relevant code: 这是相关代码的片段:

    import { Config, CognitoIdentityCredentials, DynamoDB } from 'aws-sdk/dist/aws-sdk-react-native';
    import { AuthenticationDetails, CognitoUser, CognitoUserPool, CognitoUserAttribute } from 'react-native-aws-cognito-js';

    const appConfig = {
      region: 'us-east-1',
      IdentityPoolId: 'us-east-1:foo-bar',
      UserPoolId: 'us-east-1_foo-bar',
      ClientId: '1f2o3o4b5a6r',
    };

    Config.region = appConfig.region;

    class AWS_testpage extends Component {

      constructor(props) {
        super(props);

        this.state = {
          username: 'someUsername',
          password: 'somePassword',
        };

    login() {
        const { username, password } = this.state;

        const authenticationData = {
          Username: username,
          Password: password,
        };

        const authenticationDetails = new AuthenticationDetails(authenticationData);

        const poolData = {
          UserPoolId: appConfig.UserPoolId,
          ClientId: appConfig.ClientId
        };

        const userPool = new CognitoUserPool(poolData);
        console.log('USERPOOOL', userPool);

        const userData = {
          Username: username,
          Pool: userPool
        };

        const cognitoUser = new CognitoUser(userData);

        cognitoUser.authenticateUser(authenticationDetails, {
          onSuccess: (result) => {
            console.log(`ACCESS TOKEN =====> ${result.getAccessToken().getJwtToken()}`);
            Config.credentials = new CognitoIdentityCredentials({
              IdentityPoolId: appConfig.IdentityPoolId,
              Logins: {
                [`cognito-idp.${appConfig.region}.amazonaws.com/${appConfig.UserPoolId}`]: result.getIdToken().getJwtToken()
              }
            });

            alert('Success');
          },
          onFailure: (error) => {
            alert(error);
          },
          newPasswordRequired: () => {
            console.log('NEW PASSWORD REQUIRED');
          }
        });
      }

    onDynamoPress() {
        const dynamodb = new DynamoDB(Config);
        console.log('DYNAMODB', dynamodb);


        const paramsDB = {
        RequestItems: {
        Readings: {
        Keys: [{
          hwid: {
            S: 'ThisIsFake'
          },
          timestamp: {
            S: 'Now'
          }
        }],
        ProjectionExpression: 'received' // this is what element you want back
      }
    }
  };

  dynamodb.batchGetItem(paramsDB, (err, data) => {
    if (err) console.log(err, err.stack); // an error occurred
    else console.log(data);           // successful response

  });
}

If I make the batchGetItem request before authenticating I get the following error: 如果在身份验证之前发出batchGetItem请求, batchGetItem出现以下错误:

Error: Missing credentials in config
    at credError (aws-sdk-react-native.js:7490)
    at Config.getCredentials (aws-sdk-react-native.js:7529)
    at Request.VALIDATE_CREDENTIALS (aws-sdk-react-native.js:10313)
    at Request.callListeners (aws-sdk-react-native.js:10108)
    at Request.emit (aws-sdk-react-native.js:10084)
    at Request.emit (aws-sdk-react-native.js:14062)
    at Request.transition (aws-sdk-react-native.js:13413)
    at AcceptorStateMachine.runTo (aws-sdk-react-native.js:14199)
    at Request.runTo (aws-sdk-react-native.js:13788)
    at Request.send (aws-sdk-react-native.js:13752) "CredentialsError: Missing credentials in config

我创建了一个新的联合身份池,并且有效!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:配置中缺少凭据 - /nodeapp/node_modules/aws-sdk/lib/request.js:31 - Error: Missing credentials in config - /nodeapp/node_modules/aws-sdk/lib/request.js:31 AWS Dynamodb 配置中缺少凭证,如果使用 AWS_CONFIG_FILE,则设置 AWS_SDK_LOAD_CONFIG=1 - AWS Dynamodb Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 Amazon AWS 错误:config node.js 中缺少凭据 - Amazon AWS Error: Missing credentials in config node.js 带有 Angular 4 的 AWS Cognito:错误:配置中缺少区域 - AWS Cognito with Angular 4: Error: Missing region in config 配置错误:配置中缺少区域 (AWS) - Configuration Error: Missing Region in Config (AWS) 将aws-sdk-js与CognitoSync服务一起使用时出现InvalidSignatureException - InvalidSignatureException while using aws-sdk-js with CognitoSync service 如何使用 jest mock 模拟 aws-sdk,出现错误“配置中缺少区域” - How to mock aws-sdk using jest mock, getting error "Missing region in config" AWS Cognito-ConfigError:JavaScript SDK的配置中缺少区域 - AWS Cognito - ConfigError: Missing region in config for JavaScript SDK 如何使用 aws-sdk-js 列出日期范围内的对象? - How to list objects in a date range with aws-sdk-js? AWS QLDB [错误] [Node.js QLDB 示例代码] 无法创建分类帐:ConfigError: Missing region in config - AWS QLDB [ERROR] [Node.js QLDB Sample Code] Unable to create the ledger: ConfigError: Missing region in config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM