0

I am trying to access a relative file(which I need to put there accessible to Lambda) So that I could change the content of that file and send the response as part of API gateway response. I am able to generate an entirely new .xlsx file and send to the client. But the requirement is to change the content of given .xls (from filesystem relative path).

let XlsxPopulate = require('xlsx-populate');
exports.handler = async (event, ctx, cb) => {

    XlsxPopulate.fromFileAsync('./sample.xlsx')
                .then(workbook => {
                    //.... Modfy content
                    return {
                           statusCode: 200,
                           headers: {
                               'access-control-allow-origin': '*',
                           },
                           body: modifiedWorkbook,
                           isBase64Encoded: true
                       }
        });
};
3
  • You can use the the /tmp location to save or process a file Commented May 11, 2018 at 6:35
  • @Mukund How can I put the file in temp in the first place ? How can I put my xls file at ./tmp/sample.xlsx Commented May 11, 2018 at 6:36
  • if u download the excel from S3 , download it to the /tmp location. If you are creating an new excel, create it in the /tmp/ folder remove the dot, it should be /tmp/sample.xlsx Commented May 11, 2018 at 6:40

1 Answer 1

1

An AWS Lambda only has access to /tmp and this location is limited to 512 MB. See https://docs.aws.amazon.com/lambda/latest/dg/limits.html.

However do not that Lambda functions are supposed to be stateless, don't count on having storing anything and having it accessible in the next call as the Lambda functions instance might be diff.

A good strategy would be to put the files in S3 and modify them locally.

As @Mukund mentioned as you can copy from S3 to /tmp and update them locally and then upload back to S3.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.