AWS Security ChangesHomeSearch

AWS AmazonS3: Restructure get/put bucket policy examples with Deny statement

Service: AmazonS3 · 2026-11-01 · Documentation medium

File: AmazonS3/latest/developerguide/s3_example_s3_GetBucketPolicy_section.md · Type: authz

Summary

Reformats the get-bucket-policy and put-bucket-policy examples into two labeled examples, adds a sample policy.json containing an Allow for s3:GetObject and a Deny for s3:GetObject on the secret/* prefix, and adds a link to bucket policy docs.

Security assessment

The added sample policy demonstrates an explicit Deny on s3:GetObject for the secret/* prefix, illustrating least-privilege/access-control practice. It is documentation of authorization behavior, not a fix for a specific vulnerability.

Evidence

                "Effect": "Deny",

Diff

diff --git a/AmazonS3/latest/developerguide/s3_example_s3_GetBucketPolicy_section.md b/AmazonS3/latest/developerguide/s3_example_s3_GetBucketPolicy_section.md
index a9a3d79..d84696a 100644
--- a//AmazonS3/latest/developerguide/s3_example_s3_GetBucketPolicy_section.md
+++ b//AmazonS3/latest/developerguide/s3_example_s3_GetBucketPolicy_section.md
@@ -63 +63 @@ CLI
-The following command retrieves the bucket policy for a bucket named `amzn-s3-demo-bucket`:
+**Example 1: To retrieve a bucket policy**
@@ -64,0 +65 @@ The following command retrieves the bucket policy for a bucket named `amzn-s3-de
+The following `get-bucket-policy` example retrieves the bucket policy for a bucket named `amzn-s3-demo-bucket`.
@@ -66 +67,3 @@ The following command retrieves the bucket policy for a bucket named `amzn-s3-de
-    aws s3api get-bucket-policy --bucket amzn-s3-demo-bucket
+    
+    aws s3api get-bucket-policy \
+        --bucket amzn-s3-demo-bucket
@@ -76 +79,14 @@ Output:
-Get and put a bucket policyThe following example shows how you can download an Amazon S3 bucket policy, make modifications to the file, and then use `put-bucket-policy` to apply the modified bucket policy. To download the bucket policy to a file, you can run:
+**Example 2: To get and put a bucket policy**
+
+The following `get-bucket-policy` example shows how you can download an Amazon S3 bucket policy, make modifications to the file, and then use `put-bucket-policy` to apply the modified bucket policy. To download the bucket policy to a file, run the following command.
+    
+    
+    aws s3api get-bucket-policy \
+        --bucket amzn-s3-demo-bucket \
+        --query Policy \
+        --output text > policy.json
+    
+
+This command produces no output.
+
+You can then modify the `policy.json` file as needed. Finally you can apply this modified policy back to the S3 bucket by running the following command.
@@ -79 +95,3 @@ Get and put a bucket policyThe following example shows how you can download an A
-    aws s3api get-bucket-policy --bucket amzn-s3-demo-bucket --query Policy --output text > policy.json
+    aws s3api put-bucket-policy \
+        --bucket amzn-s3-demo-bucket \
+        --policy file://policy.json
@@ -81 +98,0 @@ Get and put a bucket policyThe following example shows how you can download an A
-You can then modify the `policy.json` file as needed. Finally you can apply this modified policy back to the S3 bucket by running:
@@ -83 +100 @@ You can then modify the `policy.json` file as needed. Finally you can apply this
-`policy.json` file as needed. Finally you can apply this modified policy back to the S3 bucket by running:
+Contents of `policy.json`:
@@ -85 +101,0 @@ You can then modify the `policy.json` file as needed. Finally you can apply this
-file as needed. Finally you can apply this modified policy back to the S3 bucket by running:
@@ -86,0 +103,21 @@ file as needed. Finally you can apply this modified policy back to the S3 bucket
+    {
+        "Version":"2012-10-17",
+        "Statement": [
+            {
+                "Sid": "",
+                "Effect": "Allow",
+                "Principal": "*",
+                "Action": "s3:GetObject",
+                "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
+            },
+            {
+                "Sid": "",
+                "Effect": "Deny",
+                "Principal": "*",
+                "Action": "s3:GetObject",
+                "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/secret/*"
+            }
+        ]
+    }
+
+This command produces no output.
@@ -88 +125 @@ file as needed. Finally you can apply this modified policy back to the S3 bucket
-    aws s3api put-bucket-policy --bucket amzn-s3-demo-bucket --policy file://policy.json
+For more information, see [Bucket policies for Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-policies.html) in the _Amazon S3 User Guide_.