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
- Browse the URL -> https://aws.amazon.com/cli/
- 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.
- Once installed, open the command prompt and enter the following command.
.
aws configure
It will prompt for AWS Access KeyID and Secret Key. Enter the credentials which were downloaded from the AWS account.
- Log in to AWS Web -> click on Security credentials under the name of yours listed on the top left corner.
- 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.
- 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.
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.
- {
- "StackId": "arn:aws:cloudformation:ap-south-1:411900209772:stack/myBucket/01921490-3156-11e9-a9b9-06c541265f78"
- }
Now, let us try to log in to AWS Web and check on the S3 Bucket.
Also, in the Search bar, type CloudFormation and check on the UI page.
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.