【发布时间】:2021-07-09 07:46:03
【问题描述】:
我正在尝试使用 AWS 开发工具包访问 Location 对象。
location.batchUpdateDevicePosition 工作正常。
但是location.listGeofences 抱怨CognitoIdentityCredentials is not authorized to perform: geo:ListGeofences on resource: arn:aws:geo:us-west-2::*
geo:ListGeofences已经在角色策略里了,为什么还在报怨?
有什么想法吗?
#policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "geo:*",
"Resource": "*"
},
{
"Sid": "GetDevicePositions",
"Effect": "Allow",
"Action": [
"geo:ListGeofences",
"geo:BatchGetDevicePosition",
"geo:GetDevicePosition",
"geo:GetDevicePositionHistory"
],
"Resource": "*"
}
]
}
import Amplify, {Auth, PubSub} from 'aws-amplify';
import awsconfig from '../aws-exports';
import AWS from 'aws-sdk';
import Location from 'aws-sdk/clients/location';
Amplify.configure(awsconfig);
Auth.currentCredentials().then(credentials => {
console.log(Auth.essentialCredentials(credentials));
console.log(AWS);
const location = new Location({
region: awsconfig.aws_project_region,
credentials: Auth.essentialCredentials(credentials),
});
const updateDevicePosition = new Promise((resolve, reject) => {
console.log({ params });
location.batchUpdateDevicePosition(params, function (err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
reject(err);
} else {
console.log('->>>>>TRACKER: ', data);
resolve(data);
} // successful response
});
});
const listGeofences = new Promise((resolve, reject) => {
location.listGeofences({CollectionName: 'explore.geofence-collection'}, (err, data) => {
if (err) {
console.log(err, err.stack); // an error occurred
reject(err);
} else {
console.log('listGeofences: ', data);
resolve(data);
} // successful response
});
});
listGeofences.then(()=>console.log('LIST'))
updateDevicePosition.then(() => {
console.log('complete');
});
});
【问题讨论】:
标签: aws-sdk amazon-cognito amazon-iam