12

I use the serverless framework to deploy my lambda functions. Serverless uses API Gateway to make my endpoints. I know that it's possible to pass the parameters in methods such as GET and use it in lambda by using the event object. The frontend is already deployed and they were using the following URL to call an endpoint:

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.  
 }

which EG43 is a key that the previous backend was returning the result based on that key. My question is that if it's possible to somehow know what the URL is. the following doc from AWS shows the parameters that can be read by using the handler arguments, but it doesn't have URL.

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

2
  • Please provide your coded attempts. Commented Apr 8, 2018 at 7:28
  • @wayneOS edited. Commented Apr 8, 2018 at 8:29

1 Answer 1

10

You should be able to access these details two ways:

a. Setup a mapping template, and pass in the details you need as part of the payload. The mapping template is a velocity template with certain variables accessible. See this for details of what you can access.

b. You can setup the lambda in Proxy Integration mode. With this you have access to the raw request. See this for more details.

Here's how you should setup the Lambda in Proxy Integration Mode:

Lambda Proxy Integration Setup

And when the Lambda is setup in Proxy Integration way here's what you get in the event:

{
    "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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.