如何在春季云功能中获取路径参数
我有一个使用Spring-Cloud函数编写的Java应用程序,并在AWS lambda中部署,该应用程序连接到AWS API-GATEWAWA,
我有一个“ get” API(例如,/mosplot>/employs/{employeeeiD}
)输入参数(在这种情况下为{雇员}),并返回与参数相对应的结果(给定员工的员工详细信息)。
我尝试了谷歌搜索,但找不到一种设置此设置的方法,以使我将{雇员}传递给我的spring-cloud-unction代码并采取相应的行动。如何在Java代码中获取参数?
谁能建议如何在API-Gateway设置此问题并在我的Java Lambda代码中获得相同的参数?
谢谢。
I have a java application written using spring-cloud-functions and deployed in aws lambda which connects to aws api-gateway
I have a 'GET' api(let's say /employees/{employeeId}
) which takes an input parameter({employeeId} in this case) and returns the result(employee details for the given employeeId) corresponding to the parameter.
I tried googling but could not find a way to set this up such that I get the {employeeId} passed to my spring-cloud-function code and act accordingly. How do I get the parameter in the java code?
Can anyone suggest how to set this up in api-gateway and get the same parameter in my java lambda code?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将REST API与Lambda集成在一起。我们需要将路径参数和查询参数转换为lambda可以消耗的事件对象。
因此,在Integration选项卡中:
/I.SSTATIC.NET/S5LQG.JPG“ ALT =“映射模板”>
您可以在此处参考以获取详细信息:
aws知识中心
文章逻辑也可以应用于路径参数。
I used REST API with lambda integration. We need to convert the path params and query params to an event object that the lambda can consume.
So here goes, in integration tab:
You can refer here for details:
AWS Knowledge Centre Article
Same logic can be applied to path params as well.
对于任何类型的请求,我们都可以尝试进行解决方案,我们将获得该请求的URI。
从标头中提取URI提供的弹簧云功能的输入应为消息的类型或其他任何接受
等式标题的消息:
uri: /post /12345
URI模板可用于提取字符串中的参数。
函数接受URI和将在这种情况下
将返回地图的模板
We can try to do workaround as for any type of request we will getting uri of the request.
Extracting the uri from the headers provided the input for spring cloud function should be of type of Message or any other which accepts headers
For eq:
Uri: /post/12345
Uri Template can be used to extract the parameters in the string
The function accepts uri and the template for that which will be in this case /post/{id}
which will return a map