[英]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?
我使用什么事件或其他属性来获取查询参数,或者我需要进行什么设置或更改?
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.