9

I'm using: https://github.com/aws-amplify/amplify-js

Is there any working example how to use authenticated access to AWS? I'm using this:

Amplify.configure({ Auth: { identityPoolId: configs.broker.identityPoolId, region: configs.broker.aws_pubsub_region, userPoolId: configs.broker.userPoolId, userPoolWebClientId: configs.broker.userPoolWebClientId, } }); Amplify.addPluggable(new AWSIoTProvider(configs.broker)); Auth.signIn(configs.broker.username, configs.broker.password) .then(user => { resolve({ code: 200, message: 'Authorized access to AWS is used' }) }) .catch(singInErr => resolve({ code: 500, message: singInErr.message })); 

And if it is OK (it is ok):

 PubSub.publish(configs.broker.topic, JSON.stringify(data)) .then(res => resolve({ code: 200, message: 'OK' })) .catch(err => resolve({ code: 500, message: err.toString() })); 

But I keep getting:

[Unhandled promise rejection: NotAuthorizedException: Unauthenticated access is not supported for this identity pool.]

1 Answer 1

10

Did you setup auth with amplify-cli? I had a similar issue with graphql and cognito. Solved it by going to Identity pool settings and setting up Unauthenticated role and Authenticated role. I've just used the ones which where created with amplify cli.

I'm trying to recall this from memory so there might be some parts missing. But rough steps are:

  1. Go to https://eu-west-1.console.aws.amazon.com/cognito/federated
  2. From the top bar select the region you are in.
  3. If you have identity pools you should see a table. Above it there is a link to its settings. Click that.
  4. In the top right corner, below Support there is Edit Identity Pool. Click that.
  5. You should see a screen with two options Unauthenticated roleand Authenticated role. Click the select boxes and select the appropriate roles. If you created amplify stacks it should have two roles which have words unauthdRole and authRole select those.

It should work now. That's assuming that you have right identity pool and user pool setup.

Sign up to request clarification or add additional context in comments.

1 Comment

And what you did exactly? Can you add some link on a step by step manual?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.