Skip to content

Instantly share code, notes, and snippets.

@amr-swalha
Created December 7, 2018 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amr-swalha/803f2bfd17d026547b21593cd6a3c87f to your computer and use it in GitHub Desktop.
Save amr-swalha/803f2bfd17d026547b21593cd6a3c87f to your computer and use it in GitHub Desktop.
Enhanced Bucket creation code
static void CreateABucket()
{
try
{
PutBucketRequest request = new PutBucketRequest();
request.BucketName = bucketName;
var result = client.PutBucket(request);
if (result.HttpStatusCode == HttpStatusCode.OK)
{
Console.WriteLine("Bucket created");
}
}
catch (AmazonS3Exception amazonS3Exception)
{
if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
{
Console.WriteLine("Please check the provided AWS Credentials.");
Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
}
else
{
Console.WriteLine("An Error, number {0}, occurred when creating a bucket with the message '{1}", amazonS3Exception.ErrorCode, amazonS3Exception.Message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment