Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`body` parameter is absent in AWS Lambda Authorizer `event` object

Tags:

aws-lambda

The event object is missing body and isBase64Encoded properties. But they should be there according to the docs The full structure is the following:

{
    "type": "REQUEST",
    "methodArn": "arn:aws:execute-api:us-west-2:*******:*******/development/POST/auth/login",
    "resource": "/{proxy+}",
    "path": "/auth/login",
    "httpMethod": "ANY",
    "headers": {
       .....
    },
    "queryStringParameters": {
        "test": "123"
    },
    "pathParameters": {
        "proxy": "auth/login"
    },
    "stageVariables": {
        "lambdaVersion": "development"
    },
    "requestContext": {
        "path": "/development/auth/login",
        "accountId": "*****",
        "resourceId": "f8wvnk",
        "stage": "development",
        "requestId": "****",
        "identity": {
            ....
        },
        "resourcePath": "/{proxy+}",
        "httpMethod": "POST",
        "apiId": "********"
    }
}

Does anyone have the similar issue?

like image 996
megapixel23 Avatar asked Nov 16 '17 16:11

megapixel23


People also ask

How do you get the request body in Lambda?

You can opt to have Lambda@Edge expose the body in a request for writable HTTP methods (POST, PUT, DELETE, and so on), so that you can access it in your Lambda function. You can choose read-only access, or you can specify that you'll replace the body.

How do I enable CORS in Lambda proxy integration?

To enable CORS for the Lambda proxy integration, you must add Access-Control-Allow-Origin: domain-name to the output headers . domain-name can be * for any domain name. The output body is marshalled to the frontend as the method response payload.


2 Answers

In custom authorizer request type there is no body in the passed event to the authorizer. According to the documentation:

For a custom authorizer of the REQUEST type, API Gateway passes the required request parameters to the authorizer Lambda function as part of the event object. The affected request parameters include headers, path parameters, query string parameters, stage variables, and some of request context variables.

NO Body is there!

like image 188
G. Bahaa Avatar answered Sep 23 '22 20:09

G. Bahaa


https://aws.amazon.com/blogs/compute/using-enhanced-request-authorizers-in-amazon-api-gateway/

Enhanced request authorizer Lambda functions receive an event object that is similar to proxy integrations. It contains all of the information about a request, excluding the body.

like image 23
user48656 Avatar answered Sep 19 '22 20:09

user48656