Demo: Deploying Artifacts to S3 Buckets

A significant challenge with container architecture is that the storage is ephemeral by default, and all the artifacts produced are deleted once the container stops execution. So, it’s advisable not to store any state or context data in an application running in the container. That’s one of the main reasons we need to design stateless applications if we want to run them in containers.

AWS CloudBuild follows container architecture. So, if our build produces an artifact like a zip, jar, or war file, they are deleted once the build completes. To preserve them for later deployment, we must save these files in the S3 buckets before the container shuts down. We can achieve this by enabling the artifacts feature in the build.

Creating an S3 bucket

Before editing the build, let’s create the bucket that we'll add to the artifacts section if it doesn’t exist already. We can use the mb command provided by AWS CLI for this purpose, which is a short form for “make bucket.” This command accepts two arguments:

  • bucket_name: This is the name of the bucket. Please ensure the bucket name is specified in the s3://bucket_name format. Some of the other common rules that we tend to violate are as follows:

    • A bucket name must be between 3 and 63 characters long.

    • A bucket name must have all lowercase characters, numbers, dots, and hyphens.

  • region: This is the region where the bucket needs to be created. A region can be us-east-1 or us-west-1 or any other region where we choose to create the bucket. Please ensure the region name is a valid AWS region.

Get hands-on with 1200+ tech skills courses.