Skip to content

Commit 708814c

Browse files
committed
fix: Use aws.iam.get_policy_document_output
1 parent 79288e1 commit 708814c

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

pulumi/test_datasets/__main__.py

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""An AWS Python Pulumi program"""
22

3-
import json
43
import pulumi
54
import pulumi_aws as aws
65

@@ -45,29 +44,26 @@
4544
opts=pulumi.ResourceOptions(protect=True),
4645
)
4746

48-
# Step 2: Create a bucket policy for public read access
49-
public_read_policy = json.dumps(
50-
{
51-
"Version": "2012-10-17",
52-
"Statement": [
53-
{
54-
"Effect": "Allow",
55-
"Principal": "*", # Allow access to anyone
56-
"Action": [
57-
"s3:GetObject",
58-
"s3:ListBucket",
59-
],
60-
"Resource": [
61-
test_datasets_bucket.arn.apply(lambda arn: f"{arn}/*"),
62-
], # Access all objects in the bucket
63-
}
64-
],
65-
}
47+
allow_access_from_anyone = aws.iam.get_policy_document_output(
48+
statements=[
49+
{
50+
"principals": [{"identifiers": ["*"], "type": "AWS"}],
51+
"actions": [
52+
"s3:GetObject",
53+
"s3:ListBucket",
54+
],
55+
"resources": [
56+
test_datasets_bucket.arn,
57+
test_datasets_bucket.arn.apply(lambda arn: f"{arn}/*"),
58+
],
59+
}
60+
]
6661
)
6762

68-
# Step 3: Apply the bucket policy to the bucket
69-
bucket_policy = aws.s3.BucketPolicy(
70-
"testData-bucketPolicy", bucket=test_datasets_bucket.id, policy=public_read_policy
63+
allow_access_from_anyone_bucket_policy = aws.s3.BucketPolicy(
64+
"allow_access_from_anyone",
65+
bucket=test_datasets_bucket.id,
66+
policy=allow_access_from_anyone.json,
7167
)
7268

7369
# Define the policy which allows users to put objects in the S3 bucket

0 commit comments

Comments
 (0)