Skip to content

Instantly share code, notes, and snippets.

@johndstein
Created September 24, 2019 14:18
Show Gist options
  • Save johndstein/b6ac0b3b31406cfb66c32ce6fa99df49 to your computer and use it in GitHub Desktop.
Save johndstein/b6ac0b3b31406cfb66c32ce6fa99df49 to your computer and use it in GitHub Desktop.
Lambda for listing s3 files
const AWS = require('aws-sdk')
if (process.env.AWS_PROFILE) { // eslint-disable-line
AWS.config.credentials = new AWS.SharedIniFileCredentials({
profile: process.env.AWS_PROFILE // eslint-disable-line
})
AWS.config.logger = console
}
const s3 = new AWS.S3({ apiVersion: '2006-03-01' })
exports.handler = async(event, context) => {
const objects = await s3.listObjects(event).promise();
return objects.Contents.map((o) => o.Key)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment