Skip to content

Instantly share code, notes, and snippets.

@jsmithdev
Last active May 15, 2019 00:41
Show Gist options
  • Save jsmithdev/a67df6120bb39781a3dd350b09b5dbf6 to your computer and use it in GitHub Desktop.
Save jsmithdev/a67df6120bb39781a3dd350b09b5dbf6 to your computer and use it in GitHub Desktop.
lambda-s3-trigger.js - to be triggered off an S3 CRED action like create. Set env var HOSTNAME to the hostname of where you want to send the file's metadata when action occurs.
const hostname = process.env.HOSTNAME
const https = require('https')
exports.handler = (event, context, callback) => {
const data = JSON.stringify({ records: event.Records })
const opts = {
hostname,
method: 'POST',
path: '/aws-door',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data)
}
}
const req = https.request(opts, (res) => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', (d) => {
process.stdout.write(d)
})
})
req.on('error', console.log)
req.write(data)
req.end()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment