如何为两个api网关创建调用相同的lambda函数 [英] How to create invoke same lambda function for the two api-gateway
问题描述
我aws创建了2个api网关
I aws create a 2 api-gateway
- 第一个
https://xx. xx-api.us-east-1.amazonaws.com/v1/uploadapi/?search=all
然后我的lambda函数将在下面调用
then my lambda function will invoke below
searchone = es.search(index="my-index", body={"query": {"match_all": {}}})
return searchone
searchtwo = es.search(index="my-index", body={"query": {"match": {"name":"computer"}}})
return searchtwo
基本上需要创建single
lambda函数
Basically need to create single
lambda function
如果api url是第一个,则返回searchone
;如果api url是第二个,则返回searchtwo
if api url is first one then return searchone
if the api url is second one then return searchtwo
免责声明?我是否需要为以上两个API创建单独的Lambda函数
Disclaimer ? DO i need to create separate Lambda function for above two api's
推荐答案
否,您不需要多个lambda函数.在您指定的两个url中,更改仅是查询参数.
No, you do not need multiple lambda functions. Among the two url's that you have specified, what changes is only the query params.
...? search = all
...? search = matchphrase = name_computer
...?search=all
...?search=matchphrase=name_computer
搜索参数用于此类条件,即在服务器需要以某种特定方式处理请求时通知服务器. 您可以在lambda函数中访问它们.
Search parameters are used for such conditions i.e. to notify the server if it needs to handle the request in some specific way. You can access them in the lambda function.
在继续之前,我建议您考虑以下架构:
Before we move ahead, I would suggest you consider the following schema:
...? search = all -> ?search_type = match_all
...? search = matchphrase = name_computer -> ...? search_type = match_some& match_phrase = name_computer
...?search=all --> ?search_type=match_all
...?search=matchphrase=name_computer -> ...?search_type=match_some&match_phrase=name_computer
现在,如果您探索传递给lambda函数的event
对象,则会在event.requestContext.queryStringParameters
处找到这些查询参数.看起来像这样:
Now, if you explore the event
object that is passed to the lambda function, you will find these query parameters at event.requestContext.queryStringParameters
. It would look something like this:
{
<...>
'resource': '/v1/uploadapi',
'requestContext': {
'queryStringParameters': {
'search_type': 'match_some',
'match_phrase': 'name_computer'
},
<...>
}
您现在可以使用它在其之上构建逻辑.
You can now use this to build logic on top of it.
这篇关于如何为两个api网关创建调用相同的lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!