unauthRole/CognitoIdentityCredentials is not authorized to perform: geo:ListGeofences

Viewed 340

I am trying to use the AWS SDK to access Location object.

location.batchUpdateDevicePosition works fine.

but location.listGeofences complains that CognitoIdentityCredentials is not authorized to perform: geo:ListGeofences on resource: arn:aws:geo:us-west-2::*

geo:ListGeofences is already in the role policy, why it is still complaining?

Any ideas?

#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');
        });

    });
1 Answers

I have run into the same problem, I have even opened a similar thread here in SO.

The problem with this is that unauthorized users cannot use most of the service actions.

AWS says literally this in the docs:

You can use IAM policies associated with unauthenticated identity roles with the following actions:

geo:GetMap*

geo:SearchPlaceIndex*

geo:BatchUpdateDevicePosition

geo:CalculateRoute

Including other Amazon Location actions will have no effect, and unauthenticated identities will be unable to call them.

This is specified within the following link: https://docs.aws.amazon.com/location/latest/developerguide/authenticating-using-cognito.html

So, if you want to use that specific action and also the rest, you must do it through federated identities: https://docs.aws.amazon.com/cognito/latest/developerguide/getting-started-with-identity-pools.html

Related