Skip to content

Instantly share code, notes, and snippets.

@anushshukla
Last active April 22, 2021 17:42
Show Gist options
  • Select an option

  • Save anushshukla/21cfad1f13775a2e3953c3d3053462fb to your computer and use it in GitHub Desktop.

Select an option

Save anushshukla/21cfad1f13775a2e3953c3d3053462fb to your computer and use it in GitHub Desktop.
AWS > S3 > Objects > Update > ACL
import AWS from 'aws-sdk';
import fs from 'fs';
const makeObjectsPrivate = () => {
console.log('====================');
const data = JSON.parse(fs.readFileSync('data.json', 'utf8'));
console.log('data', data);
const {
accessKeyId,
secretAccessKey,
Bucket,
region,
ACL,
keyPropName,
documents
} = data;
AWS.config.update({
accessKeyId,
secretAccessKey
});
const awsS3 = new AWS.S3({
region
});
documents.forEach(document => {
console.log('------------------');
console.log('document', document);
awsS3.putObjectAcl({
ACL,
Bucket,
Key: document[keyPropName],
}, (error, data) => {
error ? console.error('error', error) : console.log('data', data);
});
});
}
makeObjectsPrivate()
# install nvm
curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh -o install_nvm.sh \
# reload terminal to use nvm
reset
# install current LTS node version
nvm install --lts \
# install dependecy: AWS SDK of JS
npm i aws-sdk \
# run the node file with output and error logsrun node file
node aws-s3-make-objects-public >output.log 2>error.log
{
"accessKeyId": "",
"secretAccessKey": "",
"Bucket": "",
"region": "",
"ACL": "public",
"keyPropName": "somePropName"
"documents": [
{
"somePropName": "AWS-S3-KEY-NAME"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment