4

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?

1

2 Answers 2

13

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Following these steps, I keep getting "AWS::AppSync::ApiKey UPDATE_FAILED". Why is it so hard to update an API key????
@CaseSilva it's actually a bit convoluted...anyway, I tried yesterday my solution for a new project and it works fine. Maybe you could try a new empty project, just to try my solution, and if everything works the problem is somewhere else in your current work (maybe a misconfiguration of Amplify)
It has to do with the fact that lambdas use the api keys, that's what caused my error. Even more involved in that case, see here: github.com/aws-amplify/amplify-cli/issues/…
points for simplicity, works well for outdated api keys that you accidently delete from the console before trying to run amplify update api
This worked for me, It created a new API key in the backend. My biggest question now is how did you know how to do this? Will help me understand how to approach my troubleshooting in the future.
0

I just came across this error and after exploring various blogs, I find out that adding this ""APIKeyExpirationEpoch": -1, "CreateAPIKey": -1" ,as mentioned in comment above, is deprecated and causing this error [NoApiKey: No api-key configured]. My way is to simply run the amplify update api, having previously deleted apikey expiration epoch -1 to start with a clean slate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.