如何访问调用我的lambda函数的url

Mas*_*son 6 handler amazon-web-services node.js aws-lambda

我使用无服务器框架来部署我的lambda函数.无服务器使用API​​网关来创建我的端点.我知道可以在GET等方法中传递参数,并使用事件对象在lambda中使用它.前端已经部署,他们使用以下URL来调用端点:

example.com/api/EG43

`exports.myHandler = async function(event, context) {
        ...

        // somehow access the URL which was used by the frontend 
        // to grab that EG43 and then return the result based on that key.
        // return information to the caller.  
 }
Run Code Online (Sandbox Code Playgroud)

哪个EG43是前一个后端根据该键返回结果的键.我的问题是,如果可以以某种方式知道URL是什么.AWS的以下文档显示了可以使用处理程序参数读取的参数,但它没有URL.

https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html

Yog*_*h_D 7

您应该能够通过两种方式访问​​这些详细信息:

一个.设置映射模板,并作为有效负载的一部分传递您需要的详细信息.映射模板是一个速度模板,可以访问某些变量.有关可以访问的内容的详细信息,请参阅此处

湾 您可以在代理集成模式下设置lambda.有了这个,您就可以访问原始请求.有关详细信息,请参阅本.

以下是如何在代理集成模式下设置Lambda:

Lambda代理集成设置

当Lambda以Proxy Integration方式设置时,这里是您在事件中获得的内容:

{
    "resource": "/abc/version/test",
    "path": "/abc/version/test",
    "httpMethod": "GET",
    "headers": null,
    "queryStringParameters": null,
    "pathParameters": null,
    "stageVariables": null,
    "requestContext": {
        "path": "/abc/version/test",
        "accountId": "1234",
        "resourceId": "resourceId",
        "stage": "Stage",
        "requestId": "AWS Request ID",
        "identity": {
            "cognitoIdentityPoolId": null,
            "cognitoIdentityId": null,
            "apiKey": "API Key",
            "cognitoAuthenticationType": null,
            "userArn": "arn:aws:iam::<acc_Id>:user/yogesh",
            "apiKeyId": "api-key-id",
            "userAgent": "aws-internal/3",
            "accountId": "<AccId>",
            "caller": "<Some caller ID>",
            "sourceIp": "test-invoke-source-ip",
            "accessKey": "<Access Key>",
            "cognitoAuthenticationProvider": null,
            "user": "<Some User Id>"
        },
        "resourcePath": "/abc/version/test",
        "httpMethod": "GET",
        "extendedRequestId": "test-invoke-extendedRequestId",
        "apiId": "API ID, is typically the API GW ID"
    },
    "body": null,
    "isBase64Encoded": false
}
Run Code Online (Sandbox Code Playgroud)