public PutBucketPolicyAsync ( PutBucketPolicyRequest request, System cancellationToken = default(CancellationToken) ) : Task |
||
request | PutBucketPolicyRequest | Container for the necessary parameters to execute the PutBucketPolicy operation. |
cancellationToken | System | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// |
return | Task |
private async Task CreateCloudFrontBucket(string bucketName) { using ( var client = new AmazonS3Client(cfConfigurationProvider.AccessKey, cfConfigurationProvider.SecretKey, cfConfigurationProvider.RegionEndpoint)) { await client.PutBucketAsync(bucketName); await client.PutCORSConfigurationAsync(bucketName, new CORSConfiguration { Rules = { new CORSRule { AllowedHeaders = {"Authorization"}, AllowedMethods = {"GET"}, AllowedOrigins = {"*"}, MaxAgeSeconds = 3000 } } }); var policy = new BucketPolicy { Version = "2012-10-17", Statement = new Statement { Sid = "AddPerm", Effect = "Allow", Principal = "*", Action = "s3:GetObject", Resource = $"arn:aws:s3:::{bucketName}/*" } }; await client.PutBucketPolicyAsync(bucketName, JsonConvert.SerializeObject(policy)); } }