Skip to content

Instantly share code, notes, and snippets.

@tnolet
Created January 19, 2018 09:15
Show Gist options
  • Save tnolet/a56c338581f95a1a8b462791c8464d5b to your computer and use it in GitHub Desktop.
Save tnolet/a56c338581f95a1a8b462791c8464d5b to your computer and use it in GitHub Desktop.
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