Skip to content

Instantly share code, notes, and snippets.

@slaughtr
Last active April 25, 2018 20:51
Show Gist options
  • Save slaughtr/e5a2f543afd971184edad664ee65c282 to your computer and use it in GitHub Desktop.
Save slaughtr/e5a2f543afd971184edad664ee65c282 to your computer and use it in GitHub Desktop.
Helpful async/await for AWS
// get a JSON file from S3 and immediately parse the JSON to a JS object
const testObj = JSON.parse(await s3.getObject({ Bucket: 'test', Key: test }).promise().then(res => res.Body.toString()));
// get all keys from an S3 listObjectV2 as an array (assuming no pagination of results)
const keysArr = (await s3.listObjectsV2({Bucket: 'test', Prefix: 'test'}).promise().then(res => res.Contents)).map(item => item.Key);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment