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.]
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:
Support
there is Edit Identity Pool
. Click that.Unauthenticated role
and 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With