401 error returned on graphQL api on react.js app hosted by aws-amplify (AuthMode: “AMAZON_COGNITO_USER_POOLS”)

401 error returned on graphQL api on react.js app hosted by aws-amplify (AuthMode: “AMAZON_COGNITO_USER_POOLS”)


0

I’m trying to set up a web app using react.js hosted by amplify on AWS, which I will need to store user preferences of certain categories in a dynamoDB table.

Users must authenticate with Cognito before being able to view/interact with their preferences. I have been having a hard time trying to connect to DynamoDB table that came from the graphQL api which was created with the amplify. In particular, I have been receiving the following error:

Error: Request failed with status code 401 at createError

Currently, I try to authenticate the api through "AMAZON_COGNITO_USER_POOLS", however, I have also tried authenticating through IAM, as the answer to this question suggested (Appsync return 401 errors when connecting with cognito).

I have also tried to add more permissions (graphQL and appsync authorization, along with the expected dynampDB permissions) to the identity pool which is the identity provider for the user group which defines the Cognito user pool.

Here is my code for /src/aws-export.js:

// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-east-2",
    "aws_cognito_identity_pool_id": "us-east-2:*",
    "aws_cognito_region": "us-east-2",
    "aws_user_pools_id": "us-east-2_*",
    "aws_user_pools_web_client_id": "3ls*",
    "oauth": {},
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ],
    "aws_appsync_graphqlEndpoint": "https://*.appsync-api.us-east-2.amazonaws.com/graphql",
    "aws_appsync_region": "us-east-2",
    "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS"
};


export default awsmobile;

and my api call:

const create_user_response = await API.graphql({
          query: createUser, 
          variables: { input },
          authMode: "AMAZON_COGNITO_USER_POOLS"
        });

This web app is my first, so it is entirely possible that I’m missing something obvious. Also, please correct me if my jargon is incorrect or confusing.

I’m more than happy to provide more code if necessary.

Thanks for your help!

Share


Load 4 more related questions


Show fewer related questions

0

Reset to default



Browse other questions tagged

or ask your own question.

Leave a Reply

Your email address will not be published. Required fields are marked *