Last active
April 22, 2021 17:42
-
-
Save anushshukla/21cfad1f13775a2e3953c3d3053462fb to your computer and use it in GitHub Desktop.
AWS > S3 > Objects > Update > ACL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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