Setting Up Our First S3 Bucket Using CloudFormation

Let’s start a simple CloudFormation to set up an S3 Bucket.

What is CloudFormation?

CloudFormation is one of the services provided by AWS to help set up Web Service resources. This means much less time is needed to set up a resource and concentrate on other applications/services which run across AWS.

How do we manage an AWS Resource?

The right answer will be - using Stack.

What is a Stack?

Stack is something like a grouping of n number of resources into a single unit. The resources which are defined in a stack are called templates. 

So, to start with the stack, we just need some basic idea of writing JSON or YAML files and the services involved in AWS. To start here, I am going to show a demo on CloudFormation templates for creating a simple S3 Bucket. As I am running this on a Windows machine, I will be installing AWS CLI and then will be executing the templates.

To Install AWS CLI

  1. Browse the URL ->
  2. On the top left side, you could see the link to download for Windows 64-bit or 32-bit. Select the appropriate version needed and install it.
    Setup Your First S3 Bucket Using CloudFormation
  1. Once installed, open the command prompt and enter the following command.

    aws configure

    Setup Your First S3 Bucket Using CloudFormation

    It will prompt for AWS Access KeyID and Secret Key. Enter the credentials which were downloaded from the AWS account.

    1. Log in to AWS Web -> click on Security credentials under the name of yours listed on the top left corner.
    2. Click on Access Keys and note the keys listed. If not generated before, click on 'Create new Access Key' which will be downloaded in an Excel format.
  1. So once the Access keyID and Secret Key is provided in cmd prompt, we are ready to start with the Templates creation. 

Creation of Simple S3 Bucket

Now, we will step into the template creation of simple S3 Bucket.

To start with simple basic steps, will write only a few lines of a JSON file.

Setup Your First S3 Bucket Using CloudFormation 

In the command line, try to execute the following.

awscloudformation create-stack --stack-name myBucket --template-body file://AWSS3Bucket.json

AWSS3Bucket -> Is the file name of the template described above

Once the stack is successful, we will be getting the Stack ID which was created.

  1. {  
  2.    "StackId""arn:aws:cloudformation:ap-south-1:411900209772:stack/myBucket/01921490-3156-11e9-a9b9-06c541265f78"  
  3. }  


Setup Your First S3 Bucket Using CloudFormation


Now, let us try to log in to AWS Web and check on the S3 Bucket.

Setup Your First S3 Bucket Using CloudFormation 

Also, in the Search bar, type CloudFormation and check on the UI page.

Setup Your First S3 Bucket Using CloudFormation 

Setup Your First S3 Bucket Using CloudFormation 

The created stack should be listed with STATUS -> CREATE_COMPLETE.

If any error occurs, the stack created will rollback completely and the STATUS will be shown as ROLLBACK with the necessary reason for the rollback.

Also, we have different types of parameters which need to be called to start with the AWS Resources.

For example, to create an EC2 Instance, we need parameters, like different flavors of ImageID, different flavors of Instance type, key name, security group, subnets, etc.

To learn in brief about the parameters, check out this link which describes the available parameters and services.

What next ….

I will be covering the creation of EC2 and VPC using CloudFormation.

Similar Articles