【发布时间】:2021-04-17 08:26:39
【问题描述】:
我正在尝试执行 dynamodb db 操作并生成一个运行良好的报告,但在生产中有时会看到错误 - CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 using identity poolid。因此,我更新了代码以刷新令牌,如下所示 -
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.789.0.min.js"></script>
var GetWallboardx = () => {
AWS.config.region = 'eu-west-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'eu-west-2:xxxxxxxxxxxxxxxxx0e8',
});
//refreshes credentials using AWS.CognitoIdentity.getCredentialsForIdentity()
AWS.config.credentials.refresh(error => {
if (error) {
console.error(error);
} else {;
var docClient = new AWS.DynamoDB.DocumentClient();
}
});
docClient.scan(params, function(err, data) {
-- some db operation --
})
setTimeout(GetWallboardx,RefreshInterval)// run this every 5 seconds
}
GetWallboardx()
如果我尝试使用这种“刷新方法”,看起来就像错误所说的无法访问发电机数据库 - 错误:: ResourceNotFoundException: 未找到请求的资源。谁能帮帮我吗。当我之前没有像这样使用“刷新”时,我没有得到这个异常 -
var docClient;
AWS.config.region = 'eu-west-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'eu-west-2:xxxxxxxxxxxxxxxxx0e8',
});
docClient = new AWS.DynamoDB.DocumentClient();
【问题讨论】:
标签: amazon-web-services amazon-dynamodb amazon-cognito