|
1 | 1 | """An AWS Python Pulumi program"""
|
2 | 2 |
|
3 |
| -import json |
4 | 3 | import pulumi
|
5 | 4 | import pulumi_aws as aws
|
6 | 5 |
|
|
45 | 44 | opts=pulumi.ResourceOptions(protect=True),
|
46 | 45 | )
|
47 | 46 |
|
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 | + ] |
66 | 61 | )
|
67 | 62 |
|
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, |
71 | 67 | )
|
72 | 68 |
|
73 | 69 | # Define the policy which allows users to put objects in the S3 bucket
|
|
0 commit comments