spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 355 forks source link

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

Closed Shiva-789 closed 2 years ago

Shiva-789 commented 2 years ago

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.

sdeleuze commented 2 years ago

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.

Shiva-789 commented 2 years ago

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