PutBucketAsync() 공개 메소드

Initiates the asynchronous execution of the PutBucket operation.
public PutBucketAsync ( PutBucketRequest request, System cancellationToken = default(CancellationToken) ) : Task
request PutBucketRequest Container for the necessary parameters to execute the PutBucket operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
리턴 Task
        public async Task EnsureBucketExistsAsync()
        {
            using (var s3Client = new AmazonS3Client(credentials, s3ConfigurationProvider.RegionEndpoint))
            {
                var getBucketLocationResponse = await s3Client.ListBucketsAsync();
                if (
                    getBucketLocationResponse.Buckets.Any(
                        bucket => bucket.BucketName == s3ConfigurationProvider.BucketName))
                {
                    loggerProvider.GetLogger().Debug("Bucket {bucketName} exists.", s3ConfigurationProvider.BucketName);
                }
                else
                {
                    loggerProvider.GetLogger()
                        .Debug("Bucket {bucketName} does not exist. Creating...", s3ConfigurationProvider.BucketName);
                    await s3Client.PutBucketAsync(s3ConfigurationProvider.BucketName);
                }

                await EnsureExpirationRuleOnBucketAsync(s3Client);
            }
        }
        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));
            }
        }