简体   繁体   English

如何将事件信息从 aws API 网关传递到 Lambda?

[英]How to pass event info from aws API Gateway get to Lambda?

How do I refer to API Gateway GET query string parameters in a Lambda function?如何在Lambda function中引用API网关GET查询字符串参数?

When I test I can use my local test event with "username": "larry"当我测试时,我可以使用带有"username": "larry"的本地测试事件
When I test with a post I can use the body parameters as the event with "username": "larry"当我使用帖子进行测试时,我可以将正文参数用作带有"username": "larry"
With a get request, I don't have a body.有了获取请求,我没有正文。 How could I use query string parameters and then refer to them in the request.我如何使用查询字符串参数,然后在请求中引用它们。 What event or other attribute do I use to get at the query param or what setting or change do I need to make?我使用什么事件或其他属性来获取查询参数,或者我需要进行什么设置或更改?

Method request方法请求

在此处输入图像描述

Integration request集成请求

在此处输入图像描述

Query String请求参数

在此处输入图像描述

When testing I've referred to event["username", what do I do for an API request passing it as a query string parameter?测试时我提到了 event["username",对于将其作为查询字符串参数传递的 API 请求,我该怎么办?

Login and click to API gateway and click on method - GET method登录并点击 API 网关并点击方法 - GET 方法

Go to Method Execution - select URL Query String Parameter and add query String parameter username Go 到方法执行 - select URL 查询字符串参数并添加查询字符串参数用户名

Now go to Integration Request tab Choose Body Mapping Template,现在 go 到集成请求选项卡选择身体映射模板,

        "content type application/json"

Generate Template like below生成如下模板

{
"username":  "$input.params('username')"
}

Now write;ambda which accept key value in pair.现在写; ambada,它接受成对的键值。

module.exports.get = (event, context, callback) => {
  const { username } = event.pathParameters;
  console.log("username", username); 
}

Now go and deploy your api on apigetway and find url and hit in browser example现在 go 并在 apigetway 上部署您的 api 并找到 url 并点击浏览器示例

          https://xxx.yyy-api.us-east-2.amazonaws.com/prod/username?vaquarkhan

Hope it will help希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 API 网关将事件参数传递给 AWS Lambda function? - How to pass event parameters to AWS Lambda function using API Gateway? Java:如何从 API Gateway 获取 AWS Lambda 事件的请求对象? - Java : How to get a Request object for your AWS Lambda event from API Gateway? 如何将数据从AWS API Gateway自定义授权者传递到AWS Lambda函数? - How to pass data from AWS API Gateway Custom Authorizer to an AWS Lambda function? 将QueryString参数从API网关传递到AWS Lambda c# - pass QueryString Paramaters from API Gateway to AWS Lambda c# 如何将POST变量传递给运行Lambda函数的AWS API Gateway? - How to pass POST variables to an AWS API Gateway running a lambda function? AWS:如何将 API 网关中定义的资源传递给 lambda? - AWS: How to pass the resource defined in API gateway to lambda? 如何将参数从 POST 从 Amazon API Gateway 传递到 AWS Lambda - How to pass a params from POST to AWS Lambda from Amazon API Gateway 如何让 AWS API 网关在 AWS Lambda function 中调用 URL? - How to get AWS API Gateway invoke URL in an AWS Lambda function? 如何将查询字符串或路由参数从 Amazon API 网关传递到 AWS Lambda - How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway 如何在AWS Lambda函数中从AWS API Gateway URI访问请求和路径变量 - How do I get access to the request and path variables from AWS API Gateway URI in an AWS Lambda function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM