Path: blob/master/code_examples/dotnet_examples/S3Examples/ManageingBucketACLTest.cs
4084 views
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-s3-developer-guide/blob/master/LICENSE-SAMPLECODE.)
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Threading.Tasks;
namespace Amazon.DocSamples.S3
{
class ManagingBucketACLTest
{
private const string newBucketName = "*** bucket name ***";
// Specify your bucket region (an example region is shown).
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
private static IAmazonS3 client;
public static void Main()
{
client = new AmazonS3Client(bucketRegion);
CreateBucketUseCannedACLAsync().Wait();
}
private static async Task CreateBucketUseCannedACLAsync()
{
try
{
// Add bucket (specify canned ACL).
PutBucketRequest putBucketRequest = new PutBucketRequest()
{
BucketName = newBucketName,
BucketRegion = S3Region.EUW1, // S3Region.US,
// Add canned ACL.
CannedACL = S3CannedACL.LogDeliveryWrite
};
PutBucketResponse putBucketResponse = await client.PutBucketAsync(putBucketRequest);
// Retrieve bucket ACL.
GetACLResponse getACLResponse = await client.GetACLAsync(new GetACLRequest
{
BucketName = newBucketName
});
}
catch (AmazonS3Exception amazonS3Exception)
{
Console.WriteLine("S3 error occurred. Exception: " + amazonS3Exception.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
}
}