Skip to content

Instantly share code, notes, and snippets.

@MeRahulAhire
Last active May 13, 2021 06:48
Show Gist options
  • Save MeRahulAhire/b1ee85c0eb4800815a2ce7ed355f7fe3 to your computer and use it in GitHub Desktop.
Save MeRahulAhire/b1ee85c0eb4800815a2ce7ed355f7fe3 to your computer and use it in GitHub Desktop.
Get the List of S3 buckets with Encryption enabled
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
s3.listBuckets(function(err, data) {
if (err) console.log(err, err.stack);
let bucketData = data.Buckets;
let bucketLength = data.Buckets.length;
for (let i = 0; i < bucketLength; i++) {
var params = {
Bucket: `${bucketData[i].Name}` /* required */
};
s3.getBucketEncryption(params, function(err, data) {
try { // first it will print all non encypted buckets and then vice versa
if(err){
console.log(bucketData[i].Name) // Non Encrypted Bucket List
}
if (data) {
console.log(bucketData[i].Name); // Encrpted Bucket List
}
} catch (err) {}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment