スクリプトエラー:無効なバケット名

スクリプトエラー:無効なバケット名

私の使命は、私のアカウントのすべてのs3バケットをチェックし、デフォルトのkms暗号化を使用して暗号化されていないバケットを見つけることです。各バケット名を繰り返して暗号化レベルを確認するループを使用して、次の2つのコマンドのドラフトを作成しました。

output="$(aws s3api list-buckets --query 'Buckets[*].Name')"

for i in $output; do aws s3api get-bucket-encryption --bucket $i; done

スクリプトで次のエラーが発生します。

Invalid bucket name ""cdktoolkit-stagingbucket-30v8nlr122c0",": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:s3:[a-z\-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-]{1,63}$"

今、最初の部分で動作し、助けてくれてありがとう。出力変数に疑問符が含まれなくなりました。

しかし、さらに2番目のcliコマンド "for i in $output; do aws s3api get-bucket-encryption --bucket $i; done"を実行すると、別のJSON形式の出力が返されます。 AES256暗号化が有効になっています。

Jasons-Air:~ jason$ for i in $output; do aws s3api get-bucket-encryption --bucket $i; done
{
    "ServerSideEncryptionConfiguration": {
        "Rules": [
            {
                "ApplyServerSideEncryptionByDefault": {
                    "SSEAlgorithm": "aws:kms"
                }
            }
        ]
    }
}

An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found

An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found

An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found
{
    "ServerSideEncryptionConfiguration": {
        "Rules": [
            {
                "ApplyServerSideEncryptionByDefault": {
                    "SSEAlgorithm": "AES256"
                }
            }
        ]
    }
}

"--query 'ServerSideEncryptionConfiguration[" を追加してみました。].ルール[].ApplyServerSideEncryptionByDefault[*].SSEAlgorithm'"を私のコマンドに適用しましたが、結果は "AES256"の代わりに "null"と表示されます。

Jasons-Air:~ jason$ for i in $output; do aws s3api get-bucket-encryption --bucket $i --query 'ServerSideEncryptionConfiguration[*].Rules[*].ApplyServerSideEncryptionByDefault[*].SSEAlgorithm'; done
null

An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found

An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found

An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found
null
null
null

ベストアンサー1

おすすめ記事