Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Serverless PDF download

I would like to download a PDF file using a nodejs lambda function deployed in AWS. Please let me know the configurations to be provided in serverless settings.yaml file.

I am able to download PDF by making below configuration changes from console.

1) Add Content-Type as application/pdf 2) Map the response model for application/pdf=>Empty 3) Change the content handling in integration response from passthrough (default) to Convert to Binary. I am looking for options where these can be provided in serverless configuration file

I am looking for options where content handling and response model can be set using serverless

Below is the snippet from serverless.yml

 events:
  - http:
      path: /test
      method: get
      integration: lambda
      response:
       statusCodes:
        200:
         pattern: '' # Default response method
         headers:
          Content-Type: "'application/pdf'"
like image 721
Anil Bhaskaran Avatar asked Jan 30 '26 21:01

Anil Bhaskaran


1 Answers

In your lambda function, you have to return a json object like that:

    {
      statusCode: 200,
      headers: { 'Content-Type': 'application/pdf' },
      body: YOUR_PDF_base64_encoded_string,
      isBase64Encoded: true, // important
    };

then, you can use serverless-apigw-binary plugin to config APIGateway Binary Support or you can do it by manualy: Change APIGateway setting

APIGateway Binary Support

use application/pdf instead of my image mime types.

like image 106
hoangdv Avatar answered Feb 02 '26 20:02

hoangdv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!