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


Picture showing the console application executed using visual studio
Click to Enlarge



Picture showing the s3 bucket created using the C# code
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, February 10, 2022

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250