#✅ - Can't add additional route
24 messages · Page 1 of 1 (latest)
Additional information, how to reproduce (without changing the codebase):
- amplify api add
/posts
/posts/{postId}
- different Lambda functions
- amplify push
- got error
It's a strange for me and couldn't find the solution..
Please help me with the advice.
Thanks before!
This is what i've understood from your request for help. You created a REST api with a path: /posts. With this api you have a handler function.
You get an issue when you try to create an additional path: /posts/{postId}. With this api you are unable to create the handler function.
If my understanding is correct... i would suggest you the handle the /posts/:postId route in your first postshandler function.
@tiny ingot Thanks, I have tried this option before, but it's not help me...
For now, I'm tried yet one and have an error..
Steps:
? Select from one of the below mentioned services: REST
√ Select the REST API you want to update: · PostApi
√ What would you like to do? · Remove path
? Select the path to remove /posts/{postId}
✅ Successfully updated resource```
```amplify function remove PostHandle
? Are you sure you want to delete the resource? This action deletes all files related to this resource from the backend
directory. Yes
✅ Successfully removed resource```
```amplify remove api PostApi
? Are you sure you want to delete the resource? This action deletes all files related to this resource from the backend
directory. Yes
✅ Successfully removed resource```
```amplify api update
? Select from one of the below mentioned services: REST
Only one option for [Select the REST API you want to update:]. Selecting [PostsApi].
√ What would you like to do? · Add another path
√ Provide a path (e.g., /book/{isbn}): · /posts/{postId}
√ The path /posts/{postId} overlaps with /posts. Users authorized to access /posts will also have access to /posts/{postId}. Are you sure you want to continue? (y/N) · yes
√ Choose a Lambda source · Use a Lambda function already added in the current Amplify project
Only one option for [Choose the Lambda function to invoke by this path]. Selecting [PostsHandle].
√ Restrict API access? (Y/n) · no
√ Do you want to add another path? (y/N) · no
✅ Successfully updated resource```
```amplify push```
Why are you creating one post handler for /posts and a second post handler for /posts/{postId}?
@tiny ingot Probably, I some confused you. At the end, I left only PostsApi and PostsHandle
If the purpose of this is to test it out and see how it works, I'd suggest doing an amplify delete and start from the beginning. Because there could be something hanging around from the addition and removals of functions and api's
In general with express. You would create the path for /posts. then in the handler have two routes GET /posts GET /posts/:id
So, just one api and just one path and just one handler.
Got it... Okay, thanks! I'll try this approach and write down the result
If you don't have much experience of express routes, there's plenty of tutorials online.
Happy hunting!
@tiny ingot I'm sorry... could you please give the example of tutorial with adding two routes?
What's I done:
amplify init
amplify add api
>>> REST
>>> PostsApi
>>> /posts
>>> PostsHandle
>>> NodeJS
>>> Hello world
>>> without advanced settings configuration
>>> without editing the local lambda function now
>>> Restring API access? no
>>> Do you want to add another path? No
amplify push```
=> Deployment completed.
```amplify add api
? Select from one of the below mentioned services: REST
√ Would you like to add a new path to an existing REST API: (y/N) · yes
Only one option for [Select the REST API you want to update:]. Selecting [PostsApi].
√ What would you like to do? · Add another path
√ Provide a path (e.g., /book/{isbn}): · /posts/{postId}
√ The path /posts/{postId} overlaps with /posts. Users authorized to access /posts will also have access to /posts/{postId}. Are you sure you want to continue? (y/N) · yes
√ Choose a Lambda source · Use a Lambda function already added in the current Amplify project
Only one option for [Choose the Lambda function to invoke by this path]. Selecting [PostsHandle].
√ Restrict API access? (Y/n) · no
√ Do you want to add another path? (y/N) · no
✅ Successfully added resource PostsApi locally
amplify push```
=> error...
I found the documentation how to add the one route, but not found the documentation how to correctly add the subpath... @tiny ingot Could you please give the link for relative tutorial?
Thanks in advance!
You don't need to do the second add api.
Start from scratch again but when you select the function template instead of 'hello world' select 'Serverless express function (Integration with Amazon API Gateway)'
In the created function you will see how the different routes are handled.
As far as tutorials... this guy is really good. though the node express tutorial is 5 years old. it will teach you the essentials
Learn to build a REST API with Node js & Express in just 1 hour!
🔥Get the complete Node course: http://bit.ly/2NfkpOC
Subscribe for more videos:
https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1
Want to learn more from me? Check out my blog and courses:
Courses: https://codewithmosh.com
Blog: https://programmingwi...
@tiny ingot Thanks a lot for the option with Serverless express function!
I have an experience with ExpressJS and customized these two routes!
Also, thanks for the ExpressJS tutorial!
Great! Enjoy the coding 🙂
✅ - Can't add additional route