最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to write file in memory or to file in Lambda aws? - Stack Overflow

programmeradmin6浏览0评论

I want to use lambda to get database from dynamodb and generate pute data to cvs file.

Then attach this file with email send to customer.

Step

  1. Get data from dynamodb. (I know how to do it .)

  2. Write to file .CSV ( need help).

Because lambda doesn't have persisted data. How to write to file

  1. Attach .CSV to email and send to customer. ( need help)

I want to use lambda to get database from dynamodb and generate pute data to cvs file.

Then attach this file with email send to customer.

Step

  1. Get data from dynamodb. (I know how to do it .)

  2. Write to file .CSV ( need help).

Because lambda doesn't have persisted data. How to write to file

  1. Attach .CSV to email and send to customer. ( need help)
Share Improve this question edited Mar 8, 2015 at 22:17 Bergi 666k161 gold badges1k silver badges1.5k bronze badges asked Mar 8, 2015 at 20:13 riseresriseres 3,1924 gold badges29 silver badges41 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Do you have an existing setup for sending email? You don't necessarily need to save a file to create a file attachment when sending an email.

simply ignore the fs.readFile statement in the response below

Sending mails with attachment via NodeJS

If you're writing a CSV, you'll probably need to stream the data to S3. Lambda has a pretty good example here for streaming image data from a buffer. Obviously you're not using an image but the concept is about the same.

  1. get your data from db
  2. format it how you need it. I'd remend looking into streams with something like csv-write-stream.
  3. stream data to s3 with something like s3-streaming-upload or the aws-sdk.
  4. as part of the response from the SDK, you'd get the location of your file.
  5. i'd use mandrill (https://mandrillapp./api/docs/messages.html) because it's free, easy, and awesome. you can set the attachment content as base64. Yours might look something like this:

    "attachments": [
      {
        "type": "text/csv",
        "name": "myfile.csv",
        "content": new Buffer( myCsvContent ).toString('base64')
       }
    ]
    

I haven't tested this but did something similar recently and this general approach should work for you.

发布评论

评论列表(0)

  1. 暂无评论