-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.py
36 lines (31 loc) · 1.01 KB
/
s3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from imports import json, aws, FileAsset, mimetypes, os
PulumiBucket = aws.s3.Bucket("PulumiBucket", acl="public-read")
content_dir = "assets"
for file in os.listdir(content_dir):
filepath = os.path.join(content_dir, file)
mime_type, _ = mimetypes.guess_type(filepath)
obj = aws.s3.BucketObject(
file, bucket=PulumiBucket.id, source=FileAsset(filepath), content_type=mime_type
)
def public_read_policy_for_bucket(bucket_name):
return json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource": [
f"arn:aws:s3:::{bucket_name}/*",
],
}
],
}
)
bucket_name = PulumiBucket.id
bucket_policy = aws.s3.BucketPolicy(
"bucket-policy",
bucket=bucket_name,
policy=bucket_name.apply(public_read_policy_for_bucket),
)