Make a S3 bucket public
- 1 minutes read - 159 wordsAccess control list (ACL):
give Everyone (public access) object lists and bucket ACL read.
Policy
Policy to attach to a role, so the role can be used to upload resources and put the ACL on the uploaded objects.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::demo"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::demo/*"
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::demo-public"
},
{
"Sid": "VisualEditor3",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::demo-public/*"
}
]
}
Uploading
command line bash scripts
aws s3 sync --acl public-read local-dir/ s3://demo-public/test/
C# source code
using (var client = new AmazonS3Client(RegionEndpoint.USWest2))
{
try
{
PutObjectRequest request = new PutObjectRequest()
{
InputStream = imageStream,
BucketName = BucketName,
Key = key,
CannedACL= S3CannedACL.PublicRead
};
client.PutObject(request);
success = true;
}
catch (Exception ex)
{
// swallow everything for now.
}
}