AWS CLI列出所有S3存储桶的加密状态 [英] AWS CLI to list encryption status of all S3 buckets
本文介绍了AWS CLI列出所有S3存储桶的加密状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的帐户有几百个存储桶,我需要能够显示所有这些的加密状态.我希望能够通过CLI做到这一点,我看到有一个命令"get-bucket-encryption"操作,但是我不知道如何针对所有存储桶而不是特定的存储桶运行此操作./p>
My account has a few hundred buckets, I need to be able to show the encryption status for all of these. I'd like to be able to do this via the CLI, I see there is a command 'get-bucket-encryption' operation but I can't figure out how to run this against all buckets rather than just a specific bucket.
推荐答案
您可以在例如:
for bucket_name in $(aws s3api list-buckets --query "Buckets[].Name" --output text); do
echo ${bucket_name}
encryption_info=$(aws s3api get-bucket-encryption \
--bucket ${bucket_name} 2>/dev/null)
if [[ $? != 0 ]]; then
echo " - no-encryption"
else
echo " - ${encryption_info}"
fi
done
如果存储桶没有加密,则 get-bucket-encryption
返回错误,因此在上面我假设任何错误都意味着没有加密.
If bucket has no encryption get-bucket-encryption
returns error, so I assume above that any error means that there is no encryption.
这篇关于AWS CLI列出所有S3存储桶的加密状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文