GraphQLError request failed with status code 401
See original GitHub issueWhich Category is your question related to? Auth / GraphQL
What AWS Services are you utilizing? AWS AppSync
Provide additional details e.g. code snippets
In our schema.graphql
, we added @function
directive to the field inside the Query
type, in order to invoke our recoverUsername
lambda function:
type Query {
recoverUsername(email: String): String
@function(name: "recoverUsername-${env}")
@aws_iam
}
It works when I execute this query in the AWS AppSync console by selecting IAM auth provider, but when I try to call it from the app with:
API.graphql({
query: recoverUsername,
variables: {
email,
},
authMode: 'AWS_IAM',
});
aws-exports.js
const awsmobile = {
aws_appsync_authenticationType: 'AWS_IAM',
...
}
I get GraphQLError request failed with status code 401
We are using older version of aws-amplify
(1.2.4), but I also tried with latest version, same error.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
GraphQLError: Request failed with status code 401 #2783
I am currently deploying through the AWS Amplify console through bitbucket. I noticed that aws-exports.js file is automatically ignored by .
Read more >Resolve unauth errors for GraphQL requests in AWS AppSync
401 Unauthorized: The request is denied by either AWS AppSync or the authorization mode because the credentials are missing or invalid. 200 OK ......
Read more >AWS Amplify AppSync IAM 401 - Stack Overflow
I'm getting GraphQLError: Request failed with status code 401. I followed the automatic configuration instructions from:.
Read more >AWS AppSync Error: Request failed with status code 401
I need help with this 401 error status, how do I go about fixing it, as I can't run my query this way....
Read more >GraphQL Error (Code: 401): {"response":{"data":[{"id":"
The error happens client-side where it seems that the client does not have access to NEXT_ENV_DATOCMS_API_TOKEN. That's why it only works when ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@cc-bojan when you’re logged into the AWS Console you’re probably using an administrator role credentials that does not need to have a specific policy to invoke AppSync mutations, that’s the probable reason why it works.
If you use the AppSync service supported native directives like
@aws_iam
the Amplify CLI will not generate any policies for you for the Auth and Unauth roles, so when from the client application you call the Amplify service and specifying IAM as authentication mode, it will use the AWS credentials of the currently logged in user, and that user’s role (Auth or Unauth) has no attached policies defined that would grant access for AppSync service to invoke that Lambda function.Could you please confirm that the above is correct? And if it is correct create a policy and verify that it is working?
@attilah You were right. I attached:
arn:aws:appsync:eu-central-1:<account-id>:apis/<api-id>/types/Query/fields/recoverUsername
- Resource to the existingUnauthRolePolicy
, and now it’s working. Thanks.