amazon web services - Increasing AWS Lambda response body payload size

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?

1 Answer

  1. Joseph- Reply


    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.

    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()
        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;

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>