Como ejemplo propongo una función lambda recibiendo un POST con un JSON en el body, directamente guardamos en contenido del POST en un archivo JSON
const AWS = require('aws-sdk');
console.log("Loading...");
const uploadData = (filename, fileContent) => {
return new Promise((resolve, reject) => {
const s3 = new AWS.S3();
const params = {
Bucket: process.env.S3_Bucket,
Key: `${filename}.json`,
Body: fileContent
}
s3.upload(params, (err, data) => {
if (err) {
reject(err)
}
resolve(data.Location)
})
});
}
exports.handler = async function(event, context) {
if (event.path==="/" && event.httpMethod==="POST") {
await uploadData(context.awsRequestId, event.body);
}
return {
statusCode: 200,
body: JSON.stringify({ requestId: context.awsRequestId })
}
}