DEV Community

Cover image for Gifted my wife an AWS EC2 Automation Script
NaveenKumar Namachivayam ⚡ for AWS Community Builders

Posted on • Originally published at qainsights.com

Gifted my wife an AWS EC2 Automation Script

For this new year, I gifted my wife an AWS EC2 automation script. Read on to know more about this in this blog about our problem statement and its simple solution.

Problem Statement

We have one of the national bank accounts in India to do financial transactions every month. Recently, we couldn't log in to the account as it is blocking foreign IPs. I tried it from a couple of VPNs to access it, but no luck.

Solution

Then, I spun an EC2 instance Windows instance in the ap-south-1 region. It worked. For every month, I manually log in into my AWS console to spin up an instance, then I provide her with the credentials. This has continued for the last couple of months.

Better Solution

Got bored with the manual steps. Enter automation. I could have done this with Terraform or Ansible, but it would be too techie for my wife. Hence, the bash.

Prerequisites

The following are the prerequisites to implement this simple solution. Initially, I had to set this up on her laptop.

  • AWS Account
  • AWS CLI
  • IAM Role to create, describe, and terminate EC2
  • PEM file to decrypt password

As I mentioned above, you would need to have an AWS account with the right IAM role and the key pair. Also, you need to have AWS CLI configured with the right API Access Key and Secret.

How to?

Once the setup is done, follow the steps below to create an EC2 instance.

  • Clone this repo git clone https://github.com/QAInsights/aws-ec2-windows.git
  • cd aws-ec2-windows
  • Run the below commands
chmod +x spin-ec2-windows.sh terminate-ec2.sh
  • To spin up an EC2 instance
./spin-ec2-windows.sh
  • After a while, it will display the credentials as shown below

Gifted my wife an AWS EC2 Automation Script
Gifted my wife an AWS EC2 Automation Script

To terminate this spanned instance, run the below command.
./terminate-ec2.sh

Terminate EC2
Terminate EC2

GitHub Repo

<!-- /wp:button -->

Configuration

Once the repo is cloned, you can configure the below parameters in spin-ec2-windows.sh

Importantly, change the name, pem_location, key_name, security_group, image_id, and region parameters. Running with the default parameters will fail to create an instance.

region="ap-south-1" #mumbai
pem_location="/mnt/c/aws/"
image_id="ami-0de07eb85c12b8dbb"
instance_type="t2.medium"
key_name="win11-mum"
count=1
security_group="sg-43ec5f28"
name="Your_Name"
windows_username="Administrator"

While creating the instance, the script will display random love quotes from https://api.quotable.io/random?tags=love

If you want to disable this, comment out the function get_random_quote

Final Thoughts

My wife loves this and makes it easy for her so that she is not dependent on me. The above script can be improved further by installing dependencies on its own. But I do not want to overcomplicate things. Hope this helps someone. If you have any comments, please let me know.

Top comments (1)

Collapse
 
lakincoder profile image
Lakin Mohapatra

Superb man