API Key Not Found issue
These docs cover Amplify Gen 1. For new web apps, we recommend the latest AWS Amplify, with a simplified CLI and native integrations for databases, storage, and AI models. Get started with the latest AWS Amplify.
If you're encountering an "API Key Not Found" issue in your Amplify project, follow the steps below to troubleshoot and resolve the problem:
Step 1: Modify parameters.json to Remove API Key
- Navigate to the
amplify/backend/api/<api-name>/parameters.jsonfile in your project. - Add the following line to the file:
{ "CreateAPIKey": 0}Ensure that a comma is placed after the previous line if this is added at the end of the JSON object.
Step 2: Remove API Key from Lambda Function Attributes
-
Open the
amplify/backend/backend-config.jsonfile. -
Locate any JSON attribute arrays that include
GraphQLAPIKeyOutput. -
Modify the arrays by removing the
GraphQLAPIKeyOutputentry. For example:-
Change this:
amplify/backend/backend-config.json{"attributes": ["GraphQLAPIIdOutput","GraphQLAPIEndpointOutput","GraphQLAPIKeyOutput"]} -
To this:
amplify/backend/backend-config.json{"attributes": ["GraphQLAPIIdOutput","GraphQLAPIEndpointOutput"]}Perform this change for each Lambda function that utilizes the API.
-
Step 3: Apply the Changes
- Push the changes to the cloud:
amplify push -yOnce this process is complete, the API key should be removed from both the application and the associated Lambda functions.
Step 4: Restore the API Key
- Remove the
CreateAPIKey: 0entry fromamplify/backend/api/<apiName>/parameters.json. - Push the changes to restore the API key to the application:
amplify push -yAfter this step, the API key should be restored to the application but will not be associated with the Lambda functions.
Step 5: Update Lambda Function Resources
- Use the following command to update each Lambda function that was previously associated with the API:
amplify update function- Follow the prompts to remove the API from the Lambda’s resources.
- Use the same command to restore the API to each Lambda function:
amplify update function- Finally, push the changes to apply them:
amplify push -yThis should complete the process and resolve the "API Key Not Found" issue.