Simple Automation Tasks on AWS

Rahulbhatia1998
3 min readMar 15, 2021

--

Hi all, in this blog I will try to do some of the tasks in AWS using AWS-CLI as well as the use of Cloud formation.

  1. Create a key pair
  2. Create a security group
  3. Launch an instance using the above created key pair and security group.
  4. Create an EBS volume of 1 GB.
  5. The final step is to attach the above created EBS volume to the instance I have created in the previous steps.

Here is the Youtube link for the demo version of the same

I have automated the above AWS tasks using Python Scripting using AWS-CLI.

You can refer to the code here for automation of the complete task.

https://github.com/Launchpad5682/ARTH-Tasks/tree/launchpad5682_branch/task-8/AWS

I have also done the same using Cloud Formation.

Code for Cloud Formation

You can also find the code here

For the current Configuration:

  1. I am working in us-east-1 Region, I have taken the AMI-ID specific to that region for RHEL8 based instance since(Cloud formation is a regional service)
  2. I have opened ports for 22 and 80 for incoming traffic.

Note: if you want you can change the configuration according to your liking.

Upload the Template onto the Cloud Formation Service on the Management Console.

You can also view the Infrastructure in Design mode by clicking on View In Designer

Or you can go ahead and click on next

In Designer Mode, you can drag and drop elements and the yaml code will be automatically generated

After you click on next , the next page you have to fill parameter details for

  1. Device: This is used for EBS Volume Device Mapping, when you associate a volume to a particular EC2 instance.
  2. KeyPair: Key pair will come according to the region in which you uplaoded the template.

Note: you can not create a new Key Pair through Cloud Formation. As Cloud formation has no way of storing the private key on your machine as a part of the stack initialization.

https://stackoverflow.com/questions/59985243/can-we-dynamically-create-keypair-through-aws-cloudformation-and-copy-the-pem-f

You also would have to specify the name of the stack for audit purposes

Click on next, and proceed to the Create Stack Option in the next Window

Now you’re stack would start to provision.

Your Stack Creation would have started now, keep refreshing the console for checking the status
Your Resources creation would be complete now, and you will get a Events Tab like this

Head over to the Resources section to the check the different resources created.

Your Resources tab would be something like this, now you can click on the physical id, and it will take you to the respective Resources.

Here you can see an EC2 instance is created with the required security Group where I have opened port 22 and 80 for incoming traffic.

Here is the output of the 1 GB EBS volume that it attached to the EC2 instance

Thanks for reading, if you like it , do give it a clap :)

If you would like to learn more about Cloud formation, you can follow this github url

--

--

No responses yet