Retrieve aws s3 bucket policy in json pretty format

Viewed 577

Retrieving AWS S3 bucket policy in pretty json format.

aws \
--profile AWS_PROFILE  \
s3api get-bucket-policy \
--bucket AWS_S3_BUCKET \
--query Policy --output text | jq .
1 Answers

You can try the following:

aws s3api get-bucket-policy \
    --bucket <AWS_S3_BUCKET> \
    --query Policy --output text --profile la | jq

Example output:

{
  "Version": "2008-10-17",
  "Statement": [
    {
      "Sid": "AllowPublicRead",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::<bucket-name>/*"
    }
  ]
}

Related