|
| 1 | +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; |
| 2 | + |
| 3 | +export const meta = { |
| 4 | + title: 'API Key Not Found issue', |
| 5 | + description: 'Resolving API Key Not Found issue', |
| 6 | + platforms: [ |
| 7 | + 'angular', |
| 8 | + 'javascript', |
| 9 | + 'nextjs', |
| 10 | + 'react', |
| 11 | + 'react-native', |
| 12 | + 'vue' |
| 13 | + ] |
| 14 | +}; |
| 15 | + |
| 16 | +export const getStaticPaths = async () => { |
| 17 | + return getCustomStaticPath(meta.platforms); |
| 18 | +}; |
| 19 | + |
| 20 | +export function getStaticProps(context) { |
| 21 | + return { |
| 22 | + props: { |
| 23 | + platform: context.params.platform, |
| 24 | + meta |
| 25 | + } |
| 26 | + }; |
| 27 | +} |
| 28 | + |
| 29 | +If you're encountering an "API Key Not Found" issue in your Amplify project, follow the steps below to troubleshoot and resolve the problem: |
| 30 | + |
| 31 | +## Step 1: Modify `parameters.json` to Remove API Key |
| 32 | + |
| 33 | +1. Navigate to the `amplify/backend/api/<api-name>/parameters.json` file in your project. |
| 34 | +2. Add the following line to the file: |
| 35 | + |
| 36 | + ```json title="amplify/backend/api/<api-name>/parameters.json" |
| 37 | + { |
| 38 | + "CreateAPIKey": 0 |
| 39 | + } |
| 40 | + ``` |
| 41 | + Ensure that a comma is placed after the previous line if this is added at the end of the JSON object. |
| 42 | + |
| 43 | +## Step 2: Remove API Key from Lambda Function Attributes |
| 44 | + |
| 45 | +1. Open the `amplify/backend/backend-config.json` file. |
| 46 | +2. Locate any JSON attribute arrays that include `GraphQLAPIKeyOutput`. |
| 47 | +3. Modify the arrays by removing the `GraphQLAPIKeyOutput` entry. For example: |
| 48 | + |
| 49 | + * Change this: |
| 50 | + |
| 51 | + ```json title="amplify/backend/backend-config.json" |
| 52 | + { |
| 53 | + "attributes": [ |
| 54 | + "GraphQLAPIIdOutput", |
| 55 | + "GraphQLAPIEndpointOutput", |
| 56 | + "GraphQLAPIKeyOutput" |
| 57 | + ] |
| 58 | + } |
| 59 | + ``` |
| 60 | + |
| 61 | + * To this: |
| 62 | + |
| 63 | + ```json title="amplify/backend/backend-config.json" |
| 64 | + { |
| 65 | + "attributes": [ |
| 66 | + "GraphQLAPIIdOutput", |
| 67 | + "GraphQLAPIEndpointOutput" |
| 68 | + ] |
| 69 | + } |
| 70 | + ``` |
| 71 | + Perform this change for each Lambda function that utilizes the API. |
| 72 | + |
| 73 | + |
| 74 | +## Step 3: Apply the Changes |
| 75 | + |
| 76 | +1. Push the changes to the cloud: |
| 77 | + |
| 78 | + ```terminal |
| 79 | + amplify push -y |
| 80 | + ``` |
| 81 | + Once this process is complete, the API key should be removed from both the application and the associated Lambda functions. |
| 82 | + |
| 83 | +## Step 4: Restore the API Key |
| 84 | + |
| 85 | +1. Remove the `CreateAPIKey: 0` entry from `amplify/backend/api/<apiName>/parameters.json`. |
| 86 | +2. Push the changes to restore the API key to the application: |
| 87 | + |
| 88 | + ```terminal |
| 89 | + amplify push -y |
| 90 | + ``` |
| 91 | + After this step, the API key should be restored to the application but will not be associated with the Lambda functions. |
| 92 | + |
| 93 | + |
| 94 | +## Step 5: Update Lambda Function Resources |
| 95 | + |
| 96 | +1. Use the following command to update each Lambda function that was previously associated with the API: |
| 97 | + |
| 98 | + ```terminal |
| 99 | + amplify update function |
| 100 | + ``` |
| 101 | +2. Follow the prompts to remove the API from the Lambda’s resources. |
| 102 | +3. Use the same command to restore the API to each Lambda function: |
| 103 | + |
| 104 | + ```terminal |
| 105 | + amplify update function |
| 106 | + ``` |
| 107 | +4. Finally, push the changes to apply them: |
| 108 | + |
| 109 | + ```terminal |
| 110 | + amplify push -y |
| 111 | + ``` |
| 112 | + This should complete the process and resolve the "API Key Not Found" issue. |
0 commit comments