Skip to main content

Create Bucket

You must create a bucket before you can upload your files. The following code can be used to create one.

Components

Bucket Name

Pay attention to the following details when naming the bucket:

  • The bucket's name must be unique. The uniqueness of this name will be verified over the entire Arvancloud Object Storage.
  • Special characters like the dot (. ), the hyphen (-), and the asterisk (!) should not be used in the bucket's name.
  • Both capital and lowercase characters may be used to specify the bucket's name. However, after the bucket is created, the name will be changed to lowercase.
  • Only English lettering should be used for the bucket's name.
  • The bucket's name must have at least three letters.

Bucket ACL

The access level of the bucket defines how to access the information inside it.

  • Private
  • Public-read
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX - License - Identifier: Apache - 2.0

using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Threading.Tasks;

namespace CreateBucket
{
public class CreateBucket
{
// This example shows how to use Amazon Simple Storage Service (Amazon S3)
// to create a new Amazon S3 bucket. The examples uses AWS SDK for .NET 3.5 and
// .NET 5.0.

private static IAmazonS3 _s3Client;

// Specify the name of the new bucket.
private const string NEW_BUCKET_NAME = "<BUCKET_NAME>";

static async Task Main()
{
var awsCredentials = new Amazon.Runtime.BasicAWSCredentials("<ACCESS-KEY>", "<SECRET-KEY>");
var config = new AmazonS3Config { ServiceURL = "<ENDPOINT>" };
_s3Client = new AmazonS3Client(awsCredentials, config);
Console.WriteLine($"\nCreating a new bucket, named: {NEW_BUCKET_NAME}.");

await CreatingBucketAsync(_s3Client, NEW_BUCKET_NAME);

}

/// <summary>
/// Uses Amazon SDK for .NET PutBucketAsync to create a new
/// Amazon S3 bucket.
/// </summary>
/// <param name="client">The client object used to connect to Amazon S3.</param>
/// <param name="bucketName">The name of the bucket to create.</param>
static async Task CreatingBucketAsync(IAmazonS3 client, string bucketName)
{
try
{
var putBucketRequest = new PutBucketRequest
{
BucketName = bucketName,
UseClientRegion = true
};

var putBucketResponse = await client.PutBucketAsync(putBucketRequest);

}
catch (AmazonS3Exception ex)
{
Console.WriteLine($"Error creating bucket: '{ex.Message}'");
}
}
}
}