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.
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.
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.
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.
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.
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
- Run the below commands
chmod +x spin-ec2-windows.sh terminate-ec2.sh
- To spin up an EC2 instance
- After a while, it will display the credentials as shown below
To terminate this spanned instance, run the below command.
<!-- /wp:button -->
Once the repo is cloned, you can configure the below parameters in
Importantly, change the
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
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)