spring-native icon indicating copy to clipboard operation
spring-native copied to clipboard

Response from java aws authorizer is wrapped and sent as APIGatewayProxyResponseEvent object

Open Shiva-789 opened this issue 3 years ago • 0 comments

Hi Team,

 Created aws java authorizer to validate the incoming token and generate Iampolicy response. With jar lambda is working as expected and generating below reponse.
{
    "policyDocument": {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Action": "execute-api:Invoke",
                "Resource": "arn:aws:execute-api:region:accountid:apiid/stage/GET/*",
                "Effect": "Allow"
            }
        ]
    },
    "context": {
        "sub": "Sample"
    },
    "principalId": null
}

When we converted same lambda to native image the response is wrapped as APIGatewayProxyResponseEvent object. Below is the response we got from api gateway logs.

{
    "isBase64Encoded": false,
    "headers": {
        "date": "Tue, 09 Aug 2022 10:53:00 GMT",
        "transfer-encoding": "chunked",
        "lambda-runtime-trace-id": "",
        "aws-api-gateway": "true",
        "lambda-runtime-aws-request-id": "99b3-c10da8d41cfb",
        "id": "339781a6-535f-dc19-e079-f32ae48a744o",
        "contentType": "application/json",
        "lambda-runtime-invoked-function-arn": "arn",
        "lambda-runtime-deadline-ms": "1660042443373",
        "timestamp": "1660042380735"
    },
    "body": "{\"principalId\":\"principleId\",\"policyDocument\":{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"execute-api:Invoke\",\"Effect\":\"Allow\",\"Resource\":\"arn:resource\"}]},\"context\":{\"sub\":\"SamplecontextObject\"}}",
    "statusCode": 200
}

The policy document is set as part of APIGatewayProxyResponseEvent body where my return type from handler is a pojo. [ tried sending stringified json directly from handler but observed same response.]

Please any input/suggestion will be helpful. Thanks in advance.

Shiva-789 avatar Aug 09 '22 15:08 Shiva-789

Hi, with the provided elements it is hard to tell what happen. There are maybe missing hints that ends up to this difference. You can maybe use the tracing agent on the JVM to generate and identify the missing hints and then reuse them on native side, see related documented.

sdeleuze avatar Aug 19 '22 07:08 sdeleuze

Hello, Sure @sdeleuze. Removed logicfrom function and return string as a lambda response for this also response is wrapped as above. Attaching lambda function Lambda

Shiva-789 avatar Aug 19 '22 07:08 Shiva-789