Amazon S3 Bucket – Creation, Lifecycle, Version, Access

What is Amazon S3 bucket

Amazon S3 bucket (Simple Storage Service) is a storage service from Amazon where you can store and retrieve objects in the cloud using a web service. The web service operation can trigger functions such as lambda. A typical use case is where you store an image in the S3 bucket and as soon as you put the image in the bucket, it triggers a lambda that takes that image, generates a thumbnail and puts the thumbnail in another bucket. The object can be anything starting from a text file to a complete video file. The object can be as small as 1 byte or as large as 5 TB. You can store as many objects as you like.

Amazon S3 bucket Event Lambda

Charges on Amazon S3 bucket

Amazon charges you for the actual storage, as well as for adding, retrieving or deleting objects.Each operation on the object is a web service call and each web service call is charged depending on the action that it performs.

What is a bucket

Buckets can be thought of as folders in a file system. Each bucket holds multiple objects. You can assign triggers to all operations in a bucket, so if you consider the earlier operation of generating a thumbnail then the original image can be in a bucket and the thumbnail can be in another bucket. If you put the thumbnail in the same bucket then it might again trigger a lambda which would create another thumbnail and so on and that would be an infinite loop. The name of each bucket is unique, so you cannot use a name that has been used by your account or any other account.

Permissions on S3 bucket

An S3 bucket or individual objects in the S3 bucket can be assigned permissions. Each user is called a ‘Grantee’ and the grantee can be assigned the following permissions for a bucket :

  • List (List objects in the bucket)
  • upload/delete (upload and delete object in the bucket
  • View permissions
  • Edit Permissions.

The grantee can be assigned the following permissions for an object

  • Open/Download object
  • View permissions on the object

Edit the permissions of the object

Hosting a website using AWS S3 bucket

You can host an entire static website using Amazon S3 bucket. Each object in the bucket can be an HTML file or resources such as CSS,js, images etc. The resources can be accessed using the S3 bucket endpoint. However, in a real world, you would probably use Amazon CloudFront and combined with router 53 to redirect your domain to this end point.

Triggering Events from Amazon S3 bucket

This is probably the most powerful functionality. You can trigger events during events such as adding an object, deleting an object etc. These events could be an SNS topic, SQS queue or a Lambda function. A good use case is when your users upload a video file. You can store the video file as an object in a bucket. This would trigger a lambda function that would convert the video to various formats that can be used in multiple devices. You would also probably add a message in an SNS topic so that you get a mail whenever a new video is added or an SQS service so that you can the next available billing processor can process a bill for it.

Versioning of object in Amazon S3 bucket

The objects in the S3 buckets can be assigned a version. When you add another object with the same name, it is stored as the new version of the object. Each version is considered one object for billing purposes so you might want to consider deleting old versions. Once you enable versioning, you cannot disable it but only suspend it.

lifecycle of an object in Amazon S3 bucket

You can specify a lifecycle for all objects in a bucket of specific objects in a bucket (identified by a prefix). The lifecycle allows you to add rules to delete the object after a specified time. It also allows you to move the object to different kinds of storage such as infrequently accessed storage and then delete it, if required. If you enable versioning, then the main object and the versioned objects can have different lifecycles.

Cross Region Replication of S3 object

You can enable cross region replication of all objects in S3 bucket. What this means is that Amazon would store a copy of your object in a different region. This makes your object highly available even if one region goes down. Imagine that you are a weather company and you store weather images in the bucket. If there is a storm the data center of a region might go down, but since you have a backup in another region, you can start using that.

Tags, requester pays and Transfer acceleration

Tags allow you to add key value pairs to the bucket and this allows you generate billing reports grouped by tags. For example. you can tag one bucket as “Project A” and then you can work out the total cost of S3 buckets for Project A in your bills.
If you allow a different account to perform operations on your bucket then you can enable Requester Pays to let that account pay for the usage and data transfer charges on the bucket.
As claimed by Amazon, transfer Acceleration makes data transfer in and out of the bucket faster and there is an extra charge for it.

Video on Amazon S3 bucket

Here’s a short video that explains the object creating and various other properties of the S3 bucket.

Leave a Reply

Your email address will not be published. Required fields are marked *