Skip to content

Instantly share code, notes, and snippets.

@jflasher
Created July 2, 2020 12:03
Show Gist options
  • Save jflasher/3a1e4310012639d66f3e45e698360725 to your computer and use it in GitHub Desktop.
Save jflasher/3a1e4310012639d66f3e45e698360725 to your computer and use it in GitHub Desktop.
Lambda function to make an S3 Invetory object publicly accessible
console.log('Loading function');
const aws = require('aws-sdk');
const s3 = new aws.S3({ apiVersion: '2006-03-01' });
exports.handler = (event, context, callback) => {
// Get the object from the event and show its content type
const bucket = event.Records[0].s3.bucket.name;
const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
const params = {
Bucket: bucket,
Key: key,
GrantRead: "uri=http://acs.amazonaws.com/groups/global/AllUsers"
};
s3.putObjectAcl(params, (err, data) => {
return callback(err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment