Skip to content

Commit 90a873f

Browse files
authored
Resolving API Key Not Found issue
1 parent 3a21b61 commit 90a873f

File tree

1 file changed

+96
-0
lines changed
  • src/pages/gen1/[platform]/build-a-backend/troubleshooting/apikey-not-found

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Amplify 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+
1. Navigate to the api/[name]/parameters.json file in your project.
33+
2. Add the following line to the file:
34+
```sh
35+
"CreateAPIKey": 0
36+
```
37+
Ensure that a comma is placed after the previous line if this is added at the end of the JSON object.
38+
39+
## Step 2: Remove API Key from Lambda Function Attributes
40+
41+
1. Open the `backend/backend-config.json` file.
42+
2. Locate any JSON attribute arrays that include `GraphQLAPIKeyOutput`.
43+
3. Modify the arrays by removing the `GraphQLAPIKeyOutput` entry. For example:
44+
- Change this:
45+
```json
46+
"attributes": [
47+
"GraphQLAPIIdOutput",
48+
"GraphQLAPIEndpointOutput",
49+
"GraphQLAPIKeyOutput"
50+
]
51+
```
52+
53+
- To this:
54+
```json
55+
"attributes": [
56+
"GraphQLAPIIdOutput",
57+
"GraphQLAPIEndpointOutput"
58+
]
59+
```
60+
Perform this change for each Lambda function that utilizes the API.
61+
62+
63+
## Step 3: Apply the Changes
64+
65+
Push the changes to the cloud:
66+
```sh
67+
amplify push -y
68+
```
69+
Once this process is complete, the API key should be removed from both the application and the associated Lambda functions.
70+
71+
## Step 4: Restore the API Key
72+
73+
1. Remove the CreateAPIKey: 0 entry from api/[name]/parameters.json.
74+
2. Push the changes to restore the API key to the application:
75+
```sh
76+
amplify push -y
77+
```
78+
After this step, the API key should be restored to the application but will not be associated with the Lambda functions.
79+
80+
81+
## Step 5: Update Lambda Function Resources
82+
83+
1. Use the following command to update each Lambda function that was previously associated with the API:
84+
```sh
85+
amplify update function
86+
```
87+
2. Follow the prompts to remove the API from the Lambda’s resources.
88+
3. Use the same command to restore the API to each Lambda function:
89+
```sh
90+
amplify update function
91+
```
92+
4. Finally, push the changes to apply them:
93+
```sh
94+
amplify push -y
95+
```
96+
This should complete the process and resolve the "API Key Not Found" issue.

0 commit comments

Comments
 (0)