Articles → AWS SDK AND CSHARP → Create A S3 Bucket Using C#
Create A S3 Bucket Using C#
Code To Create S3 Bucket
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
using System;
using System.Threading.Tasks;
namespace dotnetS3
{
class Program
{
public static void Main(string[] args)
{
string bucketName = "gyansangrah-bucket";
Console.WriteLine("bucket creation started.....");
CreateS3Bucket(bucketName).Wait();
}
static async Task CreateS3Bucket(string bucketName)
{
var region = RegionEndpoint.GetBySystemName("ap-south-1");
AWSCredentials credentails = new BasicAWSCredentials("<Access Key>", "<Secret Key>");
AmazonS3Client s3Client = new AmazonS3Client(credentails, region);
var createResponse = await s3Client.PutBucketAsync(bucketName);
if (createResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
{
Console.WriteLine("bucket created.....");
Console.ReadLine();
}
}
}
}
Output
Click to Enlarge
Click to Enlarge