Reputation: 3182
I want to use lambda
to get database from dynamodb
and generate compute data to cvs
file.
Then attach this file with email send to customer.
Step
Get data from dynamodb. (I know how to do it .)
Write to file .CSV ( need help).
Because lambda doesn't have persisted data. How to write to file
Upvotes: 3
Views: 6366
Reputation: 20584
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.
i'd use mandrill (https://mandrillapp.com/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.
Upvotes: 2
Reputation: 754
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
Upvotes: 3