简体   繁体   English

如何在AWS Lambda函数中访问路径变量(GET)

[英]How to access path variable (GET) in AWS Lambda function

I am working aws lambda with API gateway. 我正在使用API​​网关工作aws lambda。 for my compare-yourself-api resource I created a sub resource called field (please refer screenshot). 对于我的compare-yourself-api资源,我创建了一个名为field的子资源(请参阅截图)。

when I am testing it, I can see the request uri: /compare-yourself-api/test1. 当我测试它时,我可以看到请求uri:/ compare-yourself-api / test1。 I can see test1 in request but not sure how to access that field in my functionhandler. 我可以在请求中看到test1,但不知道如何在我的functionhandler中访问该字段。 I tried Map<String,String> as input in place of object but still the same issue. 我尝试使用Map<String,String>作为输入来代替对象,但仍然是同样的问题。 I was getting empty value. 我的价值空虚。

my output from Gateway Method Test screen is: "{} Hello from Lambda!" 我从Gateway Method Test屏幕输出的结果是:“{} Lambda的你好!”

Empty curly braces with out any object. 空的花括号与任何对象。

Here is my lambda function. 这是我的lambda函数。

package com.amazonaws.lambda.demo;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class LambdaFunctionHandler implements RequestHandler<Object, String> {

    @Override
    public String handleRequest(Object input, Context context) {
        context.getLogger().log("Input: " + input);


        // TODO: implement your handler
        return input+"   Hello from Lambda!";
    }

}

Please suggest me how can I get the pathvariable in Lambda function handler java. 请建议我如何在Lambda函数处理程序java中获取pathvariable。

网关资源和方法

Your parameter is passed as query string. 您的参数作为查询字符串传递。 You can find it from request. 您可以根据要求找到它。 Something like this How to pass a querystring value from AWS API Gateway to a Lambda C# function 这样的事情如何将AWS API网关中的查询字符串值传递给Lambda C#函数

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM