Search code examples
amazon-web-servicesaws-amplifyaws-appsync

Amplify API GraphQL - Unable to change local API Key with the one generated online


To update my API key, I used to go on AWS AppSync → Settings and generate a new one.

After that, inside my local app, find and replace my old API key with the new one... Until yesterday this worked fine but now, no matter what I do, when I run amplify status it outputs my old API key.

I also tried amplify update api with no luck. Later I tried amplify pull to see if it updates my local API key with the new one from the web app (AppSync) still no luck.

I already have a valid API key generated online, why I'm not able to update my local API key with the same key?


Solution

  • Try this solution:

    1. open this folder inside your project amplify/backend/<api>/parameters.json

    2. add these lines:

      "APIKeyExpirationEpoch": -1, "CreateAPIKey": -1

    3. From terminal run amplify push.

    This should delete the API key from the stack. Now, remove APIKeyExpirationEpoch and CreateAPIKey from parameters.json, and create a new key using the CLI:

    amplify update api
    

    Here, in most cases, you have to select:

    ? Select from one of the below mentioned services: -> GraphQL (or rest API, it depends on your needs)
    ? Select a setting to edit -> Authorization modes
    ? Choose the default authorization type for the API -> API key
    ✔ After how many days from now the API key should expire (1-365): ->365
    ? Configure additional auth types? ->No
    

    And finally run:

    amplify push
    

    With this solution you can renew your API key for 1 year.