aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.82k stars 820 forks source link

'Error: No api-key configured' after upgrading Amplify and Node #11272

Closed chrodin closed 2 years ago

chrodin commented 2 years ago

Which Category is your question related to? API and/or Auth

Amplify CLI Version 10.3.2

Node Version 14.16.0

What AWS Services are you utilizing? Amplify, AppSync, Cognito, DynamoDB, API Gateway, ...

Provide additional details e.g. code snippets I've changed Node version to match min criteria for a library we're using, and at the same time I upgraded Amplify. After that I had a bunch of problems to get the project running.

I then removed node_modules and ran npm i. Still couldn't run the project.

Next step was to remove node_modules and the package-lock.json (and npm i) which made it possible to build and run the project. However, I cannot fetch any data and in the console I see this error:

Error: No api-key configured
    at GraphQLAPIClass.eval (GraphQLAPI.js?1a94:183:1)
    at step (GraphQLAPI.js?1a94:43:1)
    at Object.eval [as next] (GraphQLAPI.js?1a94:24:1)
    at eval (GraphQLAPI.js?1a94:18:1)
    at new Promise (<anonymous>)
    at __awaiter (GraphQLAPI.js?1a94:14:1)
    at GraphQLAPIClass._headerBasedAuth (GraphQLAPI.js?1a94:165:1)
    at GraphQLAPIClass.eval (GraphQLAPI.js?1a94:304:1)
    at step (GraphQLAPI.js?1a94:43:1)
    at Object.eval [as next] (GraphQLAPI.js?1a94:24:1)

There is a valid api-key in the project and (also cognito user pools) which is proven by the fact that the production env is still running properly, and also an instance of localhost that has not been refreshed since upgrades is also still running fine.

The problem The problem itself is obvious: I can't make any successful requests. The reason behind it might be supersimple but I can't figure it out. It sort of feels like the project somehow doesn't care about the aws-exports.js-file, or some configuration is messed up or something? I have run amplify pull, but has not helped.

How can I again get the project to use the credentials that obviously exists? :)

Here's our aws-exports.js:

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

const awsmobile = {
    "aws_project_region": "eu-central-1",
    "aws_cognito_identity_pool_id": "eu-central-1:"###FOOOO###BAAAR######",
    "aws_cognito_region": "eu-central-1",
    "aws_user_pools_id": "eu-central-1_##XX##YY##",
    "aws_user_pools_web_client_id": "###AAA###BBB###CCC###",
    "oauth": {
        "domain": "mydomain-prod.auth.eu-central-1.amazoncognito.com",
        "scope": [
            "phone",
            "email",
            "openid",
            "profile",
            "aws.cognito.signin.user.admin"
        ],
        "redirectSignIn": "https://www.mydomain.com/",
        "redirectSignOut": "https://www.mydomain.com/",
        "responseType": "token"
    },
    "federationTarget": "COGNITO_USER_POOLS",
    "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://abunchofnumbersandletters.appsync-api.eu-central-1.amazonaws.com/graphql",
    "aws_appsync_region": "eu-central-1",
    "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
    "aws_appsync_apiKey": "theKeyThatWorksInProduction",
    "aws_cloud_logic_custom": [
        ... <a bunch of lambdas not relevant for this error>
    ],
    "aws_user_files_s3_bucket": "theS3BucketId-prod",
    "aws_user_files_s3_bucket_region": "eu-central-1"
};

export default awsmobile;
josefaidt commented 2 years ago

Hey @chrodin :wave: thanks for raising this, and thank you for including those details! Are you able to use amplify mock with the faux API key? The aws-exports.js skeleton you posted looks correct, therefore this appears it may be an issue with the aws-amplify library. Can you post the list of dependencies you're using? I'm curious if there are any scoped (e.g. @aws-amplify/auth) installed alongside aws-amplify

danielleadams commented 2 years ago

Closing due to inactivity.

chrodin commented 2 years ago

Just closing comment to this.

I was not able to get it running, so in desperation I finally I pulled the project into a new folder and everything worked fine. Still no idea what was wrong, but that solved it for me.

There were no visible changes but I guess something must have been messed up in some settings somewhere.

Anyway, thanks @josefaidt for the reply, sorry I missed it :)

danielleadams commented 2 years ago

Thanks for the follow up @chrodin!

mjanowicz commented 1 year ago

simple solution solve this is 1) remove node_modules - folder 2) remove package-lock.json file - if using npm 3) install fresh npm modules - npm i

this solve problem with no api-key configured or no credentials after update aws-amplify