Amazon S3

WIP

S3 vs S3 Glacier

“S3: Amazon Simple Storage Service (Amazon S3) is storage for the internet. You can use Amazon S3 to store and retrieve any amount of data at any time, from anywhere on the web.”

“S3 Glacier: Low-cost storage service that provides highly secure, durable, and flexible storage for data archiving and online backup.”

Code Examples

The following are the interface definitions for a facade I built using the AWS SDK for .NET. For me it made sense to create two responsibilities IBucketService to manage the bucket itself and IBucketObjectService to manage the content in the bucket.

Bucket Service

Interface: IBucketService

PutBucketAsync

Creates the given bucket, note that buckets are globally unique in name.
Will throw if the bucket already exists:

  • Amazon.S3.AmazonS3Exception : Your previous request to create the named bucket succeeded and you already own it.

  • Amazon.S3.AmazonS3Exception : The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.

  • bucketName - Globally unique bucket name

1
Task<PutBucketResponse> PutBucketAsync(string bucketName);

ListBucketsAsync

Gets a list of buckets for the authenticated user

1
Task<ListBucketsResponse> ListBucketsAsync();

CLI

1
aws s3 ls

DeleteBucketAsync

Deletes the given bucket, will throw if its not empty.

  • Amazon.S3.AmazonS3Exception : The bucket you tried to delete is not empty
1
Task<DeleteBucketResponse> DeleteBucketAsync(string bucketName);

Bucket Object Service

Interface: IBucketObjectService

GetPreSignedURL

Create a signed URL allowing access to a resource that would usually require authentication.

  • expireInHours hours in the future in which the URL will expire
1
string GetPreSignedURL(string bucketName, string key, double expireInHours);

PutTextObjectAsync

Put the plaintext object in the S3 bucket. The content type will be set to ‘text/plain’.

1
Task<PutObjectResponse> PutTextObjectAsync(string bucketName, string key, string contentBody);

GetObjectAsync

Get the value of the object on the bucket by reading response.ResponseStream

1
Task<GetObjectResponse> GetObjectAsync(string bucketName, string key);

GetObjectMetadataAsync

Retrieves metadata from an object without returning the object itself.

I think this is used as HTTP header data.

1
Task<GetObjectMetadataResponse> GetObjectMetadataAsync(string bucketName, string key);

DeleteObjectAsync

Deletes the given object (key).

1
Task<DeleteObjectResponse> DeleteObjectAsync(string bucketName, string key);

GetObjectTaggingAsync

Gets the tags as response.Tagging

1
Task<GetObjectTaggingResponse> GetObjectTaggingAsync(string bucketName, string key);

ListObjectsAsync

Gets data about the objects as response.S3Objects where .Key is the filename

1
Task<ListObjectsResponse> ListObjectsAsync(string bucketName);

References