Skip to content

Commit d5ce1b5

Browse files
authored
update: improve REST API configuration clarity (#8440)
1 parent 5b03986 commit d5ce1b5

File tree

1 file changed

+45
-2
lines changed
  • src/pages/[platform]/build-a-backend/add-aws-services/rest-api/set-up-rest-api

1 file changed

+45
-2
lines changed

src/pages/[platform]/build-a-backend/add-aws-services/rest-api/set-up-rest-api/index.mdx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ npm add aws-amplify @aws-amplify/react-native
204204
## Initialize Amplify API
205205

206206
<InlineFilter filters={['javascript', "angular", "react", "vue", "react-native", "nextjs"]}>
207+
208+
<Callout info="true">
209+
210+
**Important**: Custom REST APIs require explicit configuration. Unlike built-in Amplify resources (Auth, Data), custom APIs are not automatically included when calling `Amplify.configure(outputs)`.
211+
212+
</Callout>
213+
207214
To initialize the Amplify API category you need to configure Amplify with `Amplify.configure()`.
208215

209216
Import and load the configuration file in your app. It's recommended you add the Amplify configuration step to your app's root entry point. For example `index.js` in React or `main.ts` in Angular.
@@ -221,7 +228,7 @@ Amplify.configure(
221228
...amplifyConfig,
222229
API: {
223230
...amplifyConfig.API,
224-
REST: outputs.custom.API,
231+
REST: outputs.custom.API, // ← Required for custom REST APIs
225232
},
226233
},
227234
{
@@ -250,7 +257,7 @@ Amplify.configure(
250257
...amplifyConfig,
251258
API: {
252259
...amplifyConfig.API,
253-
REST: outputs.custom.API,
260+
REST: outputs.custom.API, // ← Required for custom REST APIs
254261
},
255262
},
256263
{
@@ -271,4 +278,40 @@ Amplify.configure(
271278
Make sure you call `Amplify.configure` as early as possible in your application’s life-cycle. A missing configuration or `NoCredentials` error is thrown if `Amplify.configure` has not been called before other Amplify JavaScript APIs. Review the [Library Not Configured Troubleshooting guide](/[platform]/build-a-backend/troubleshooting/library-not-configured/) for possible causes of this issue.
272279

273280
</Callout>
281+
282+
<Callout warning="true">
283+
284+
**Critical Configuration Step**: The line `REST: outputs.custom.API` is **required** to register your custom REST API. Without this, you'll encounter the error `API name is invalid` when trying to call your API.
285+
286+
</Callout>
287+
288+
## Troubleshooting
289+
290+
### "API name is invalid" Error
291+
292+
If you encounter the error `API name is invalid` when calling your REST API, ensure you have:
293+
294+
1. **Added the custom API configuration**: Include `REST: outputs.custom.API` in your `Amplify.configure()` call
295+
2. **Used the correct API name**: The API name should match the `restApiName` defined in your `backend.ts` file
296+
3. **Called `Amplify.configure()`**: Make sure configuration happens before any API calls
297+
298+
**Example of incorrect configuration** (missing custom API):
299+
```javascript
300+
// ❌ This will cause "API name is invalid" error
301+
Amplify.configure(outputs); // Missing custom REST API configuration
302+
```
303+
304+
**Correct configuration**:
305+
```javascript
306+
// ✅ This includes custom REST APIs
307+
const amplifyConfig = parseAmplifyConfig(outputs);
308+
Amplify.configure({
309+
...amplifyConfig,
310+
API: {
311+
...amplifyConfig.API,
312+
REST: outputs.custom.API, // Required for custom APIs
313+
},
314+
});
315+
```
316+
274317
</InlineFilter>

0 commit comments

Comments
 (0)