Skip to content

Instantly share code, notes, and snippets.

@tnolet tnolet/s3dynamo.js
Created Jan 19, 2018

Embed
What would you like to do?
const AWS = require('aws-sdk')
const s3 = new AWS.S3()
const dynamodb = new AWS.DynamoDB()
exports.handler = (event, context, callback) => {
fetchS3()
.then(data => {
console.log(data)
return putDynamoDB(data.LastModified.toString())
})
.then(data => {
console.log(data)
const result = {
"isBase64Encoded": false,
"statusCode": 200,
"headers": {},
"body": "done"
}
callback(null, result);
})
};
function fetchS3 (cb) {
return new Promise((resolve, reject) => {
const params = {
Bucket: 'staging.vamp.io',
Key: 'img/006-mock-ups/VAMP-light-laptop-v091-hero.png'
}
s3.getObject(params, (err, data) =>{
if (err) return reject(err)
resolve(data)
})
})
}
function putDynamoDB (msg) {
return new Promise((resolve, reject) => {
const params = {
Item: {
"message": {
S: msg
}
},
TableName: "loadtestlambda"
};
dynamodb.putItem(params, (err, data) => {
if (err) return reject(err)
resolve(data)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.