admin管理员组文章数量:1390618
I've generated an REST express server with Amplify.
I tried adding to more endpoints to it:
// using serverless express
app.post('/myendpoint', function(req, res) {
console.log('body: ', req.body)
res.json(req.body)
});
// using serverless express
app.get('/myendpoint', function(req, res) {
res.json({success: 'get call to my endpoint succeed!', url: req.url});
});
After running amplify push
I don't see these endpoints in the console, and I can't make requests to them via amplify.
The endpoints that were generated as part of the initial configuration work.
What is the correct way to add more REST endpoints? I have a feeling that I'm missing some additional configuration step.
I've generated an REST express server with Amplify.
I tried adding to more endpoints to it:
// using serverless express
app.post('/myendpoint', function(req, res) {
console.log('body: ', req.body)
res.json(req.body)
});
// using serverless express
app.get('/myendpoint', function(req, res) {
res.json({success: 'get call to my endpoint succeed!', url: req.url});
});
After running amplify push
I don't see these endpoints in the console, and I can't make requests to them via amplify.
The endpoints that were generated as part of the initial configuration work.
What is the correct way to add more REST endpoints? I have a feeling that I'm missing some additional configuration step.
Share Improve this question asked Feb 19, 2020 at 3:40 OleOle 47.5k70 gold badges238 silver badges445 bronze badges3 Answers
Reset to default 5After deploy the API and function, to add additional path you should use "amplify update api"
As Kevin Le stated running "amplify update api" will allow you to add another "root" path such as "/items" or "/customers", but I have been running into problems adding nested paths such as "/customer/addAddress" after the initial api creation.
What I have tried:
- I can add them during the initial creation of the API, but not during an update
- I can change the cloud formation template to include them in the API gateway, but any calls to the nested path are picked up by the root paths proxy.
- I can add them in the express lambda function ( defeats the purpose of API Gateway )
They need to add a few enhancements to amplify rest API so we can take advantage of the API Gateway. It's not truly serverless until we can separate functions for GET, POST, PUT, etc.
UPDATE: I wanted to follow up after futher investigation. A solution I found is to remove the "root" path's {proxy} endpoint in the cloud formation file for the API gateway. The file should be located at: "project root"/amplify/backend/api/"api name"/"api name"-cloudformation-template.json. Then remove the path located at Resources->"api name"->Properties->Body->paths->"api name"/{proxy+}.
FURTHER INVESTIGATION: I have not tried this yet, but the order of the path's in the cloud formation file might have an affect on how the requests are processed, so if you move the "root" proxy to the last path, you might not have to remove it. Also thanks to Piotr for fixing my poor grammar!
You can run "amplify update api" then choose to add a new endpoint and choose assign new(old) lambda function for this endpoint
本文标签: javascriptHow to add an additional endpoint to the AWS Amplify Express ServerStack Overflow
版权声明:本文标题:javascript - How to add an additional endpoint to the AWS Amplify Express Server? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744639443a2617030.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论