[英]Error: Missing credentials in config - /nodeapp/node_modules/aws-sdk/lib/request.js:31
[英]aws-sdk-js DynamoDB throwing Error: Missing credentials in config at Request.VALIDATE_REGION
我正在尝试在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)"
我已经对用户进行身份验证,该用户具有IAM角色并有权执行batchGetItem。
这是相关代码的片段:
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
});
}
如果在身份验证之前发出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.