-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (40 loc) · 1.29 KB
/
Copy pathindex.js
File metadata and controls
51 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// dependencias
var AWS = require('aws-sdk');
var util = require('util');
var async = require('async');
var s3 = new AWS.S3();
/* ========================== */
exports.handler = function(event, context) {
// Lendo opcoes do evento.
console.log("Evento:\n", util.inspect(event, {depth: 5}));
var json = event;
var arquivo = JSON.stringify(json);
async.waterfall([
function upload(callback) {
var params = {
Bucket: 'lambda-cms',
Key: 'json/posts.json',
ACL: 'public-read',
Body: arquivo
};
s3.putObject(params, function(err, data) {
if (err) {
console.log(err)
callback(err, null);
} else {
console.log("SUCESSO");
console.log(data);
callback(null, 'Terminado');
}
}
);
}], function (err, result) {
if (err) {
console.error(err);
context.succeed(err);
} else {
console.log('Tudo certo');
context.succeed('Sucesso');
}
});
}