I am using AWS API gateway to invoke my aws lambda functions. They are REST web-services that will return response back to the caller. Some of the responses are more than 20 MB. Due to the nature of the response data (data is polylines that represents complex structures) I cannot use pagination here. AWS Lambda got the limitation of lambda response body cannot exceed 6MB size and due to this limitation some of my responses that are above 6MB are failing with 'body size is too long' message. I would like to know is there a way to increase the 6MB limitation of lambda responses?
5
votes
Possible duplicate: Have you considered this suggestion? stackoverflow.com/questions/40989800/…
- srikanth Nutigattu
As @srikanthNutigattu indicated, no there isn't. The duplicate question has you writing to S3. From there you could create a signed URL or other method of transporting to the client. Does this work for your situation?
- stdunbar
Possible duplicate of Increase invoke Response payload size in AWS Lambda to 15 mb
- stdunbar
1 Answers
4
votes
Thanks for the comments, I have implemented in the same way as mentioned in the comments
Uploaded the response to s3 bucket, and provided a redirect url to the caller. Here is the sample code that works. You may also enable CORS at s3 bucket level to make it work well. You may change to the correct region
public String uploadToS3(Set<MyClass> myclassSet, String bucketName) throws IOException {
Region region = Regions.getCurrentRegion();
if (region == null) {
region = Region.getRegion(Regions.US_EAST_1);
}
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withRegion(region.getName())
.withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.build();
ObjectMapper mapper = new ObjectMapper();
String jsonClass = mapper.writeValueAsString(myclassSet);
s3Client.putObject(bucketName, "random_key.json", jsonClass);
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, "random_key.json");
URL url = s3Client.generatePresignedUrl(req);
String redirectUrl = url.toString();
return redirectUrl;
}