• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Gokul Deepak

Gokul Deepak

GoCool and Debug

  • Home
  • Terraform
  • WordPress
  • Android
  • How to
  • About Me

Gokul Deepak S

Running crontab on AWS auto scaling group

December 30, 2023 by Gokul Deepak S Leave a Comment

Linux has a convenient feature of running cronjob which will get executed at the correct time. In AWS we have a great feature of scaling out multiple instances based on traffic.

There are some requirements where the admin has to write a cron job which will be saved in the AWS AMI and provisioned in Autoscalling. As the multiple instances will be running a cron job, The single cron job will get executed parallelly in all the instances in ASG(Autoscaling group). This will get conflicted if we want to run the cron job only once.

The script which is provided below will handle the situation in Auto scaling and get only one cron job trigger even if multiple instances are running in AWS ASG.

Running crontab on AWS auto scaling group:

Step 1:

Log in to the instance where you are preparing the Golden Image. If you wonder what the golden image is. It simply means the customized AMI for our application.

Step 2:

vi /opt/asg-cron-script.sh

save the bash script in any location or with any file name as per your requirement.

#!/bin/bash

# Collect some information about the instance

INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)

INSTANCE_REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/.$//')

INSTANCE_ASG=$(aws autoscaling describe-auto-scaling-instances --region $INSTANCE_REGION --instance-ids $INSTANCE_ID --query "AutoScalingInstances[].AutoScalingGroupName" --output text)

# Query the ASG

FIRST_INSTANCE_ID=$(aws autoscaling describe-auto-scaling-groups --region $INSTANCE_REGION --auto-scaling-group-name $INSTANCE_ASG --query "AutoScalingGroups[].Instances[0].InstanceId" --output text)

if [ "$FIRST_INSTANCE_ID" == "$INSTANCE_ID" ]; then

        exit 0 #WRITE YOUR SCRIPT HERE BY REPLACING exit 0

else

        exit 1

fi

To save the file press Esc + wq!

Step 3:

To  call the above script we have to edit the crontab. Enter the below command

crontab -e

Edit the file by adding the below line

* * * * * /bin/bash /opt/asg-cron-script.sh

Step 4:

Go to the AWS console -> IAM services -> Policies -> Create new policy

Add the below json file

{
  "Statement": [
    {
      "Action": [
        "autoscaling:DescribeAutoScalingGroups",
        "autoscaling:DescribeAutoScalingInstances",
        "ec2:DescribeInstanceAttribute",
        "ec2:DescribeInstanceStatus",
        "ec2:DescribeInstances"
      ],
      "Effect": "Allow",
      "Resource": [
        "*"
      ]
    }
  ]
}

Step 5:

Create a role

AWS console -> IAM services -> Roles  -> Create new Role

Step 6:

Attach policy to the new role created and attach the role to the ASG instances/Launch configuration  (“IAM Instance Profile” within the Launch Configuration)

—-Tada—-

Mission Completed

Filed Under: AWS, Linux

Learn with Gokul

December 30, 2023 by Gokul Deepak S Leave a Comment

As famous Tamil poet Auvaiyar said “Katradhu Kai Mann Alavu, Kallathathu Ulaga Alavu” which is equivalent to  “Known is a drop, unknown is an ocean.” Even though we may have used some of the DevOps tools for some of the projects it is never complete. There will be a lot of scope to learn about using the specific tool.  

I’m good(self-certified) at exploring new tools and implementing them in the projects but the features of that tool may be more than what I have explored and new features may have been added in the newer versions. So I wanted to relearn some of the tools with all of you.  I’m planning to start a new series of Vlogs, “Learn with Gokul”.

I enjoy learning and building something technical. Have a broad range of interests too. Always wanted to share the world whatever I learn or build. I hope this will be helpful for me too. I wanted to break anything too technical to a layman’s language.

Topics:

As of now, I have some topics on my mind to explore or relearn. The list will expand for sure.

  1. Terraform
  2. Kubernetes
  3. Docker
  4. Jenkins
  5. Azure DevOps
  6. Linux
  7. Ansible
  8. AWS
  9. Azure
  10. GCP
  11. Kotlin
  12. Git
  13. SonarQube
  14. Nginx
  15. Apache Webserver
  16. Apache Tomcat
  17. WordPress
  18. PHP
  19. Python
  20. Shell Script

Filed Under: How to

Terraform Cheat sheet

December 27, 2023 by Gokul Deepak S Leave a Comment

Terraform Cheatsheet with pdf. You can download Terraform Cheatsheet pdf with all Terraform CLI commands needed.

The mentioned list is the most used Terraform commands. If you need more additional information on each of the commands you can find it in the below link.

  • terraform version : Get terraform version
  • terraform -help : Get the list of all commands with descriptions.
  • terraform init : Initalizes terraform working directory
  • terraform init -migrate-state : Reconfigure the backend and will migrate the backend
  • terraform validate : Validates syntax and arguments of terraform files
  • terraform plan : Runs execution plan
  • terraform plan -out=pathofplan : Runs execution plan and saves in a file
  • terraform plan -destroy : Runs an execution plan for destroy
  • terraform apply : Create and update infrastructure
  • terraform apply -auto-approve : Updates infrastructure without expecting ‘yes’
  • terraform apply -var=”instance_type=t2.micro” : Runs apply with value for the variable
  • terraform apply -var-file=”varfile.tfvars” : Runs apply with variable values mentioned in the file 
  • terraform apply filename : Runs apply over the plan output created in file
  • terraform apply -target=”aws_instance.this” : Runs apply only to particular resource
  • terraform apply -parallelism=5 : Creates resources paralley. Default value is 10
  • terraform destroy : Destroys all resources in statefile
  • terraform destroy –auto-approve : Destroys infrastructure without expecting ‘yes’
  • terraform destroy -target=”aws_instance.this” : Destroys particular resource
  • terraform fmt : Formats terraform code
  • terraform fmt –recursive : Formats terraform code including subdirectories
  • terraform fmt  –diff : Displays difference after formating
  • terraform get : Downloads modules

Filed Under: Terraform

Strategy to prepare for Terraform Associate Exam Preparation

December 27, 2023 by Gokul Deepak S Leave a Comment

I was planning to do Terraform certification a long time ago. I have worked on multiple projects using Terraform after my plan but still it’s in the planning stage. To make it happen I want to make it public, so that may give me some commitment.

I hope documenting this journey may also help others. By reading multiple posts and watching multiple videos I have a plan for how to prepare for this exam.

Terraform Associate Exam Preparation Strategy:

  • Read the syllabus thorougly
  • Watch Udemy/YouTube videos and get basic Ideas
  • Read Terraform Documentation (Optional)
  • Give Practice Tests
  • Revise weak areas in Terraform Documentation
  • Take notes to revise before the Exam

Terraform Associate Exam Preparation Steps:

Six Steps to Clear Terraform Associate Exam. You can also skip some steps by reading Terraform documentation instead of watching Video courses or skipping Terraform documentation and reading our Terraform notes instead.

Step 1:

Click here to read the Terraform Syllabus

Step 2:

I’m listing some of the Udemy Courses which I have watched and which helped me a lot

Step 3:

Official Terraform Documentation. You can also skip this step and directly

Step 4:

I’m listing some Good Sites to give Terraform Practice Tests

Step 5:

After giving practice tests you will understand the weak areas where more concentration is needed. Reread those documents

Step 6:

I have taken notes for all these topics. You can use them and save time by DRY(Do not Repeat Yourself) method. You can also take some notes on you own if you need to waste more time by repeating.

Filed Under: Terraform

Runcloud vs SiteGround Comparision

November 20, 2022 by Gokul Deepak S Leave a Comment

As a user of both of these services has got multiple benefits with both of them. I plan to share my experiences and opinion directly on Runcloud vs SiteGround unlike other blogs which make more SEO words and give fewer data.

I started my blog at Bluehost but got a lot of issues with my website’s loading speed and also downtime was high. So finally decided to shift to Siteground after tons of analysis. I got a Geek plan and tried to utilize all the provided features for cache and CDN. My website’s speed got increased a lot and so did the traffic.

There were some moments when I underwent issues with Siteground which is renewal. After our first purchase(Where if you purchase it by Black Friday deal you would get it for so cheap till $6). The renewal charge was $39 which is very high for me for the services we got. As I’m also technically involved to learn more, so purchased Digital Ocean, Linode and Vultr servers at the same time and installed WordPress on all the servers. As my major subscribers are from India I have taken servers in Asia and also for A/B testing I have taken servers in the US. After doing multiple speed tests using multiple tools like Google Pagespeed, Pingdom, and GTMetrix finally found that Vultr is a very good option. Now Installed Nginx in the Vultr Ubuntu server and migrate the WordPress application directly which was a mistake. It became very hard for me to maintain the website. As I want to manage my blog with less amount of time I didn’t want to continue with this operation. So finally have tried Cloudways, server pilot and Runcloud.

Runcloud vs SiteGround

I wanted the mix of both managed instance and also the customization part as some of my Android apps was using the HTML pages directly. So needed multiple domains, more customizing options, SSL, and different PHP versions for different applications as I also had the Xenforo Forum application hosted and pure Nginx as a webserver. So finally choose Runcloud as my service.

I have done multiple speed tests after migration. The performance was consistent and also it was easy to manage using Runcloud. There were no issues of the limit of traffic as happened in Siteground.

Filed Under: Hosting

Important Docker Commands to remember

November 12, 2022 by Gokul Deepak S Leave a Comment

You need not memorize these important docker commands. Repeated usage will make it easy for you to remember.

Important Docker Commands

  1. docker ps
  2. docker pull
  3. docker run
  4. docker stop
  5. docker restart
  6. docker exec
  7. docker search
  8. docker rename
  9. docker pause
  10. docker unpause
  11. docker kill
  12. docker login
  13. docker commit
  14. docker rmi
  15. docker cp
  16. docker logs
  17. docker info
  18. docker logout
  19. docker inspect
  20. docker history
  21. docker push

Filed Under: Docker

Primary Sidebar

Popular Pages

  • Home
  • How to find the date of the Facebook group it was created
  • Yureka Yu Plus vs Lenovo K3 Note
  • How to Install Windows without GRUB rescue
  • How to Remove LinkWithin logo under 'You Might Also Like' widget in blogger

Archives

Categories

  • Android
  • Apache
  • AWS
  • Blogger
  • Computer Tips
  • DevOps
  • Docker
  • Earn
  • Facebook Tips
  • Git
  • Google Tips
  • Hosting
  • How to
  • Laptop Tips
  • Laptops
  • Linux
  • Mobile
  • MongoDB
  • Nginx
  • Node JS
  • Notepad++
  • PostgresQL
  • Terraform
  • Ubuntu
  • Wordpress
  • Xenforo

Tags

Android Android One AWS Bluehost Comparisions Custom ROM Elementor Facebook Genesis Genesis Sample Theme Google Drive How to Lineage OS Notes OnePlus One OwnCloud Rooting Smartphones Stock ROM Studiopress Tomcat Wordpress plugin

Copyright © 2025 · Maintained by GokulDeepak

 

Loading Comments...