Error when pushing to existing environment: API key not found
Describe the bug When I push to an existing environment to update the api, I get an error saying "API key not found"
Amplify CLI Version amplify -v 3.17.0 To Reproduce I'm not sure what led to this.
Expected behavior I would expect it to work.
So did you add the line?:
https://aws-amplify.github.io/docs/cli-toolchain/graphql#apikeyexpirationepoch
{
"APIKeyExpirationEpoch": "-1"
}
if yes, but you dont use API Key in your API, than delete this line.
@mwarger could you please confirm that the API key has expired and was deleted by the Service is the case for you?
If yes, these steps help to let CF know about the missing Api Key and get it into a consistent state.
After that if you add: { "APIKeyExpirationEpoch": "-1" } to parameters.json, you can disable the API Key creation, or just do a whitespace change in the schema and push the project as it is, it will recreate the API key with the configured API key expiration (7 days by default), what you can update with amplify api update.
There is an open PR around API key management fixes: https://github.com/aws-amplify/amplify-cli/pull/2678
I deleted the line, and it failed. I tried to create a new environment, and it failed. @attilah @kaustavghosh06 This is trying my patience. I will get back to this with more logs later.
@attilah
If yes, these steps help to let CF know about the missing Api Key and get it into a consistent state.
Could you explain which steps you're referring to? Having the same problem.
stuck in the same place. tried { "APIKeyExpirationEpoch": "-1" }. there should be something in the console that allows you to manually change the API Key.
Ok well this worked for me - I went into CloudFormation and manually edited the stack (the root stack) and set CreateApiKey to 0 and saved it.. This allowed the stack to get into a consistent state. Then I went back to amplify cli and did the following
amplify env checkout prod (this may not be necessary?)
amplify env pull (this may not be necessary?)
amplify api update -> went ahead and reconfigured my API, specifically telling it to use an API Key (my app uses it)
after that, amplify push worked and it created a new API key (although it seemed to not honor my the 365 day expiration date I told it to use during amplify api update) -- but I'm at least back up and running.
I opened a PR for the expiration date issue I mentioned
Hey folks I just updated amplify to the latest version and added { "APIKeyExpirationEpoch": "-1" } and it worked
This just magically worked the next time I tried to deploy it. I dunno.
@mwarger @attilah can you please reopen this issue? This randomly hit my production environment as well and I'm currently sitting in a broken state with no changes on my end. My API Key was set up originally to expire 180 days out, it certainly hasn't been that long, so it's extremely concerning that this issue just cropped up on its own.
What steps need to be taken to "get CF into a consistent state?"
@kaustavghosh06 might you know the answer to this?
@davekiss just curious - is API Key your primary auth provider or a secondary one?
@chadkouse it's secondary, am also using IAM auth and userPools (User Pools is primary)
These manual steps can help to recover into a stable state from CFN point of view, from that point APIKeyExpirationEpoch can be used as documented. CreateAPIKey usage is fixed and will be included in the next release.
The steps: There is a solution to recover from this by doing a change set deployment on the nested stack of the API.
Here are the steps:
- Go to CloudFormation Console and turn on nested stacks
- Locate and select the API nested stack which failed to update due to the removed API key, it should have the same prefix as the root stack followed by the API name
- Click on the Update button
- Select the "Update nested stack" option and click "Update stack"
- Select the "Use current template" option and click next
- Set APIKeyExpirationEpoch to -1
- Set CreateAPIKey to 0
- Click "Next"
- Click "Next" on the "Configure stack options screen"
- Check the acknowledgement checkbox(es) in the Capabilities section
After the Changes are calculated you should see a "Remove" action for the "GraphQLAPIKey", if that's the case, proceed.
- Click "Update stack"
The API now should be in an updatable state.
@davekiss see this ticket and this PR (merged - but i do not believe released yet) for explanation of why your api key's expiration date got ignored / reset to the default (7 days)
@attilah @chadkouse thank you for your help, this solves the issue. I am sure bugs like this are hard to watch unfold. It brings up a bigger question for me as two days downtime in production due to bugs like this can literally be the end my business –– are we sure this project is production ready?
Also, honest question –– what is the best way to expedite support in cases like this to ensure a timely fix? I am guessing that internally at AWS, the folks writing the CLI code are the ones that would need to provide a resolution to issues like this, but the expectation that you can provide speedy support and write production code along with all of your other responsibilities seems unfeasible. I understand this is semi-OSS but because it is tied to paid AWS services I'd like to know what is possible.
I don't mean to sound entitled but as mentioned above, bringing production systems down to a halt just isn't an option if I want to stay in business. Is my best option really to click around and precariously tweak settings in the console to try and find the bug in code that I didn't write?
Encountered a similar issue after manually deleting the API keys via the AppSync view of the AWS Managment Console.
@attilah's troubleshooting steps worked perfect. Thanks!
These manual steps can help to recover into a stable state from CFN point of view, from that point
APIKeyExpirationEpochcan be used as documented.CreateAPIKeyusage is fixed and will be included in the next release.The steps: There is a solution to recover from this by doing a change set deployment on the nested stack of the API.
Here are the steps:
- Go to CloudFormation Console and turn on nested stacks
- Locate and select the API nested stack which failed to update due to the removed API key, it should have the same prefix as the root stack followed by the API name
- Click on the Update button
- Select the "Update nested stack" option and click "Update stack"
- Select the "Use current template" option and click next
- Set APIKeyExpirationEpoch to -1
- Set CreateAPIKey to 0
- Click "Next"
- Click "Next" on the "Configure stack options screen"
- Check the acknowledgement checkbox(es) in the Capabilities section
After the Changes are calculated you should see a "Remove" action for the "GraphQLAPIKey", if that's the case, proceed.
- Click "Update stack"
The API now should be in an updatable state.
Had this problem today, and after following these steps, I was able to do a successful amplify push again.
@attilah Thank you for this fix! Worked great.
Hi, i've tried @attilah 's meethod since i had a stuck stack after some Api Key expiration issues but now it seems that it changed someting in my amplify auth feature, i'm getting errors from everywhere when i try to push ...
I would really enjoy some help with this since i am kind of a new amplify user. here is some of the errors i'm getting :
`josephvasse@MacBook-Pro TEST % amplify status
Current Environment: devclone
| Category | Resource name | Operation | Provider plugin |
|---|---|---|---|
| Api | villeoamplify | Update | awscloudformation |
| Auth | villeoamplify5f42c19e | No Change | awscloudformation |
| Storage | photos | No Change | awscloudformation |
GraphQL endpoint: https://qzd2upt3enfv7l5ypsrfyzaxa4.appsync-api.eu-west-1.amazonaws.com/graphql GraphQL API is configured to use API_KEY authentication, but API Key deployment is disabled, don't forget to create one.
Hosted UI Endpoint: https://villeoamplify5f42c19e-5f42c19e-devclone.auth.eu-west-1.amazoncognito.com/ Test Your Hosted UI Endpoint: https://villeoamplify5f42c19e-5f42c19e-devclone.auth.eu-west-1.amazoncognito.com/login?response_type=code&client_id=52tuvku5qh506hhcafav8s7pas&redirect_uri=villeo://
josephvasse@MacBook-Pro TEST % amplify push ✔ Successfully pulled backend environment devclone from the cloud.
Current Environment: devclone
| Category | Resource name | Operation | Provider plugin |
|---|---|---|---|
| Api | villeoamplify | Update | awscloudformation |
| Auth | villeoamplify5f42c19e | No Change | awscloudformation |
| Storage | photos | No Change | awscloudformation |
| ? Are you sure you want to continue? Yes |
The following types do not have '@auth' enabled. Consider using @auth with @model - CommCommune - Mairie - Actualite - Evenement - Signalement - Tag - Catsignalement - Region - Departement Learn more about @auth here: https://docs.amplify.aws/cli/graphql-transformer/auth
GraphQL schema compiled successfully.
Edit your schema at /Users/josephvasse/Desktop/test/TEST/amplify/backend/api/villeoamplify/schema.graphql or place .graphql files in a directory at /Users/josephvasse/Desktop/test/TEST/amplify/backend/api/villeoamplify/schema ? Do you want to update code for your updated GraphQL API Yes ? Do you want to generate GraphQL statements (queries, mutations and subscription) based on your schema types? This will overwrite your current graphql queries, mutations and subscriptions Yes ⠏ Updating resources in the cloud. This may take a few minutes...
UPDATE_IN_PROGRESS authvilleoamplify5f42c19e AWS::CloudFormation::Stack Thu Apr 08 2021 13:15:51 GMT+0200 (heure d’été d’Europe centrale)
UPDATE_IN_PROGRESS apivilleoamplify AWS::CloudFormation::Stack Thu Apr 08 2021 13:15:51 GMT+0200 (heure d’été d’Europe centrale)
UPDATE_IN_PROGRESS storagephotos AWS::CloudFormation::Stack Thu Apr 08 2021 13:15:51 GMT+0200 (heure d’été d’Europe centrale)
UPDATE_IN_PROGRESS amplify-villeoamplify-devclone-95626 AWS::CloudFormation::Stack Thu Apr 08 2021 13:15:46 GMT+0200 (heure d’été d’Europe centrale) User Initiated
⠼ Updating resources in the cloud. This may take a few minutes...
UPDATE_IN_PROGRESS amplify-villeoamplify-devclone-95626-apivilleoamplify-UM7B3L82AICC AWS::CloudFormation::Stack Thu Apr 08 2021 13:15:52 GMT+0200 (heure d’été d’Europe centrale) User Initiated ⠇ Updating resources in the cloud. This may take a few minutes...
UPDATE_COMPLETE storagephotos AWS::CloudFormation::Stack Thu Apr 08 2021 13:15:52 GMT+0200 (heure d’été d’Europe centrale) ⠹ Updating resources in the cloud. This may take a few minutes...
UPDATE_IN_PROGRESS amplify-villeoamplify-devclone-95626-authvilleoamplify5f42c19e-SRV0ZTXV3MQE AWS::CloudFormation::Stack Thu Apr 08 2021 13:15:52 GMT+0200 (heure d’été d’Europe centrale) User Initiated ⠙ Updating resources in the cloud. This may take a few minutes...
UPDATE_IN_PROGRESS HostedUIProvidersCustomResourceInputs Custom::LambdaCallout Thu Apr 08 2021 13:16:00 GMT+0200 (heure d’été d’Europe centrale) ⠹ Updating resources in the cloud. This may take a few minutes...
CREATE_COMPLETE GraphQLAPIKey AWS::AppSync::ApiKey Thu Apr 08 2021 13:16:02 GMT+0200 (heure d’été d’Europe centrale)
CREATE_IN_PROGRESS GraphQLAPIKey AWS::AppSync::ApiKey Thu Apr 08 2021 13:16:02 GMT+0200 (heure d’été d’Europe centrale) Resource creation Initiated
UPDATE_IN_PROGRESS GraphQLSchema AWS::AppSync::GraphQLSchema Thu Apr 08 2021 13:16:00 GMT+0200 (heure d’été d’Europe centrale)
CREATE_IN_PROGRESS GraphQLAPIKey AWS::AppSync::ApiKey Thu Apr 08 2021 13:16:00 GMT+0200 (heure d’été d’Europe centrale)
⠋ Updating resources in the cloud. This may take a few minutes...
UPDATE_ROLLBACK_IN_PROGRESS amplify-villeoamplify-devclone-95626-authvilleoamplify5f42c19e-SRV0ZTXV3MQE AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:05 GMT+0200 (heure d’été d’Europe centrale) The following resource(s) failed to update: [HostedUIProvidersCustomResourceInputs].
UPDATE_FAILED HostedUIProvidersCustomResourceInputs Custom::LambdaCallout Thu Apr 08 2021 13:16:04 GMT+0200 (heure d’été d’Europe centrale) Failed to update resource. See the details in CloudWatch Log Stream: 2021/04/08/[$LATEST]30f64d7908c6460f884ee17a6f6020e7
UPDATE_IN_PROGRESS HostedUIProvidersCustomResourceInputs Custom::LambdaCallout Thu Apr 08 2021 13:16:04 GMT+0200 (heure d’été d’Europe centrale) Requested update required the provider to create a new physical resource
⠧ Updating resources in the cloud. This may take a few minutes...
UPDATE_FAILED authvilleoamplify5f42c19e AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:14 GMT+0200 (heure d’été d’Europe centrale) Embedded stack arn:aws:cloudformation:eu-west-1:656863241730:stack/amplify-villeoamplify-devclone-95626-authvilleoamplify5f42c19e-SRV0ZTXV3MQE/005b85a0-938a-11eb-8ad8-026a669677dd was not successfully updated. Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: The following resource(s) failed to update: [HostedUIProvidersCustomResourceInputs]. ⠸ Updating resources in the cloud. This may take a few minutes...
UPDATE_FAILED GraphQLSchema AWS::AppSync::GraphQLSchema Thu Apr 08 2021 13:16:15 GMT+0200 (heure d’été d’Europe centrale) Resource update cancelled UPDATE_ROLLBACK_IN_PROGRESS amplify-villeoamplify-devclone-95626-apivilleoamplify-UM7B3L82AICC AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:14 GMT+0200 (heure d’été d’Europe centrale) Initiated by parent stack ⠹ Updating resources in the cloud. This may take a few minutes...
UPDATE_ROLLBACK_IN_PROGRESS amplify-villeoamplify-devclone-95626 AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:26 GMT+0200 (heure d’été d’Europe centrale) The following resource(s) failed to update: [apivilleoamplify, authvilleoamplify5f42c19e].
UPDATE_FAILED apivilleoamplify AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:25 GMT+0200 (heure d’été d’Europe centrale) Resource update cancelled
⠙ Updating resources in the cloud. This may take a few minutes...
UPDATE_COMPLETE storagephotos AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:30 GMT+0200 (heure d’été d’Europe centrale) UPDATE_IN_PROGRESS authvilleoamplify5f42c19e AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:30 GMT+0200 (heure d’été d’Europe centrale) UPDATE_IN_PROGRESS apivilleoamplify AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:30 GMT+0200 (heure d’été d’Europe centrale) UPDATE_IN_PROGRESS storagephotos AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:30 GMT+0200 (heure d’été d’Europe centrale) ⠴ Updating resources in the cloud. This may take a few minutes...
UPDATE_COMPLETE HostedUIProvidersCustomResourceInputs Custom::LambdaCallout Thu Apr 08 2021 13:16:39 GMT+0200 (heure d’été d’Europe centrale) ⠧ Updating resources in the cloud. This may take a few minutes...
UPDATE_IN_PROGRESS GraphQLSchema AWS::AppSync::GraphQLSchema Thu Apr 08 2021 13:16:40 GMT+0200 (heure d’été d’Europe centrale) ⠼ Updating resources in the cloud. This may take a few minutes...
UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS amplify-villeoamplify-devclone-95626-authvilleoamplify5f42c19e-SRV0ZTXV3MQE AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:43 GMT+0200 (heure d’été d’Europe centrale) ⠦ Updating resources in the cloud. This may take a few minutes...
UPDATE_COMPLETE authvilleoamplify5f42c19e AWS::CloudFormation::Stack Thu Apr 08 2021 13:16:52 GMT+0200 (heure d’été d’Europe centrale) ⠼ Updating resources in the cloud. This may take a few minutes...
UPDATE_COMPLETE GraphQLSchema AWS::AppSync::GraphQLSchema Thu Apr 08 2021 13:17:42 GMT+0200 (heure d’été d’Europe centrale) ⠼ Updating resources in the cloud. This may take a few minutes...
UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS amplify-villeoamplify-devclone-95626-apivilleoamplify-UM7B3L82AICC AWS::CloudFormation::Stack Thu Apr 08 2021 13:17:45 GMT+0200 (heure d’été d’Europe centrale) ⠋ Updating resources in the cloud. This may take a few minutes...
UPDATE_COMPLETE storagephotos AWS::CloudFormation::Stack Thu Apr 08 2021 13:17:50 GMT+0200 (heure d’été d’Europe centrale) UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS amplify-villeoamplify-devclone-95626 AWS::CloudFormation::Stack Thu Apr 08 2021 13:17:48 GMT+0200 (heure d’été d’Europe centrale) UPDATE_COMPLETE apivilleoamplify AWS::CloudFormation::Stack Thu Apr 08 2021 13:17:48 GMT+0200 (heure d’été d’Europe centrale) ⠇ Updating resources in the cloud. This may take a few minutes...
UPDATE_ROLLBACK_COMPLETE amplify-villeoamplify-devclone-95626 AWS::CloudFormation::Stack Thu Apr 08 2021 13:18:00 GMT+0200 (heure d’été d’Europe centrale) UPDATE_COMPLETE apivilleoamplify AWS::CloudFormation::Stack Thu Apr 08 2021 13:18:00 GMT+0200 (heure d’été d’Europe centrale) UPDATE_COMPLETE authvilleoamplify5f42c19e AWS::CloudFormation::Stack Thu Apr 08 2021 13:18:00 GMT+0200 (heure d’été d’Europe centrale) ⠼ Updating resources in the cloud. This may take a few minutes...Error updating cloudformation stack ⠼ Updating resources in the cloud. This may take a few minutes...
Following resources failed
Resource Name: 2021/04/08/[$LATEST]30f64d7908c6460f884ee17a6f6020e7 (Custom::LambdaCallout) Event Type: update Reason: Failed to update resource. See the details in CloudWatch Log Stream: 2021/04/08/[$LATEST]30f64d7908c6460f884ee17a6f6020e7 URL: https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/arn%3Aaws%3Acloudformation%3Aeu-west-1%3A656863241730%3Astack%2Famplify-villeoamplify-devclone-95626-authvilleoamplify5f42c19e-SRV0ZTXV3MQE%2F005b85a0-938a-11eb-8ad8-026a669677dd/events
Resource Name: jbnaxp2s2bcgtkonqkwkc37ms4GraphQLSchema (AWS::AppSync::GraphQLSchema) Event Type: update Reason: Resource update cancelled URL: https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/arn%3Aaws%3Acloudformation%3Aeu-west-1%3A656863241730%3Astack%2Famplify-villeoamplify-devclone-95626-apivilleoamplify-UM7B3L82AICC%2F861bca10-8700-11eb-aeff-061b0e84a7fb/events
✖ An error occurred when pushing the resources to the cloud
Resource is not in the state stackUpdateComplete An error occurred during the push operation: Resource is not in the state stackUpdateComplete `
I'm using GraphQL, after removing the API key from AppSync console manually, from the backend. I started to have the same error message. I think this happens because some of my lambda functions were using/depending on the AppSync API key I removed to execute operations on my GraphQL API. Check your "Environment variables" section in your lambda console to verify. In my case I did the following:
- Run
amplify update apicommand - select "my GraphQL API"
- select "Walkthrough all configurations"
- select "Yes, I want to make some additional changes"
- select "y" for "Configure additional auth types?"
- disable "API Key" option if selected
- Run
amplify update functioncommand - Go through every lambda function in your project and select the "Resource access permissions " option
- Disable permission access to your GraphQL API in the function that you had granted the permission to previously
- Run
amplify push --ycommand - Go to your lambda console and check the "Environment variables" section to verify your lambda function is not depending on the messing API key anymore
Good luck
These manual steps can help to recover into a stable state from CFN point of view, from that point
APIKeyExpirationEpochcan be used as documented.CreateAPIKeyusage is fixed and will be included in the next release.The steps: There is a solution to recover from this by doing a change set deployment on the nested stack of the API.
Here are the steps:
- Go to CloudFormation Console and turn on nested stacks
- Locate and select the API nested stack which failed to update due to the removed API key, it should have the same prefix as the root stack followed by the API name
- Click on the Update button
- Select the "Update nested stack" option and click "Update stack"
- Select the "Use current template" option and click next
- Set APIKeyExpirationEpoch to -1
- Set CreateAPIKey to 0
- Click "Next"
- Click "Next" on the "Configure stack options screen"
- Check the acknowledgement checkbox(es) in the Capabilities section
After the Changes are calculated you should see a "Remove" action for the "GraphQLAPIKey", if that's the case, proceed.
- Click "Update stack"
The API now should be in an updatable state.
I used the above solutions for a few months, got sick of doing that every couple weeks when i had updates to push up, and asked aws support for help. we ended up updating amplify cli to latest version (from v4.13... to v4.50...) and push commands started working with no issues. You might need to just update amplify cli. I did run into an issue here when trying to run the global update command where i had to rename a nested file, which it mentioned in the error message i got in the terminal. no issues after this. however, we'll see if it persists longterm.