0
votes

I am new to learning AWS Lambda, and want to implement Authorizer for API gateway in Java. What is the method header for Request type Authorizers? This is what I have so far:

public class Authorize implements RequestHandler<Object, AuthPolicy> {


public AuthPolicy handleRequest(InputStream inputStream,  OutputStream outputStream, Context context) throws IOException {
//Logic for Authorizer
return new AuthPolicy("xxxx", AuthPolicy.PolicyDocument.getAllowAllPolicy(System.getenv("AWS_REGION"), context.getIdentity().getIdentityId(), "GET", "1"));

}

}

I am returning AuthPolicy Object as given in AWS-labs example:
https://github.com/awslabs/aws-apigateway-lambda-authorizer-blueprints/blob/master/blueprints/java/src/example/APIGatewayAuthorizerHandler.java

The above structure is for token type, and I need request type. I am getting this error:
Authorizer result body before parsing
Execution failed due to configuration error: Invalid JSON in response:

Please help.

1

1 Answers

0
votes

I've been having similar problems to you with getting a valid JSON response back to the API gateway. I think you are on the right path with using the input/output streams as the AWS lambda JSON serializer can mess with any JSON returned (changing the case of the policy properties). See this Handler Input/Output Types (Java) (at the end of the document)

Looking at your code it looks like you need to stream the response back to the outputStream rather than return the POJO?

You've probably sorted this already but putting this up there for others.