noobie.cloud

Back

Top AWS & Linux Tricks Every DevOps Engineer Should KnowBlur image

Top AWS & Linux Tricks Every DevOps Engineer Should Know#

As a DevOps engineer, mastering AWS and Linux is key to streamlining workflows and optimizing costs. Here are some powerful tricks to improve efficiency, security, and automation.

AWS SSM Session Manager: SSH Without Bastion Hosts#

Stop using bastion hosts for SSH! AWS SSM Session Manager allows direct access to EC2 instances securely via AWS Console or CLI.

How to Enable It#

  1. Attach the AmazonSSMManagedInstanceCore policy to your instance’s IAM role.

  2. Install the SSM Agent:

    bash

    CopyEdit

    sudo yum install -y amazon-ssm-agent

  3. Start a session:

    bash

    CopyEdit

    aws ssm start-session --target i-0abcd1234efgh5678

Benefits: No need to open SSH ports, use key pairs, or manage bastion hosts.


AWS Auto-Recovery for EC2: Self-Healing Instances#

Avoid downtime by enabling EC2 Auto-Recovery, which automatically restarts unhealthy instances.

How to Set It Up#

  1. Go to EC2 > Create CloudWatch Alarm.
  2. Select Status Check Failed (Any) metric.
  3. Set ActionRecover the instance. Benefits: Ensures uptime without manual intervention.

Save Money with Spot Instances & Savings Plans#

Cut EC2 costs by up to 90% with Spot Instances and Savings Plans:

  • Spot Instances: Use for batch jobs, CI/CD, or fault-tolerant apps.
  • Compute Savings Plans: Lock in discounts for 1-3 years on EC2, Lambda, and Fargate.

Check Spot Prices#

bash

CopyEdit

aws ec2 describe-spot-price-history --instance-types t3.large --start-time $(date -u +"%Y-%m-%dT%H:%M:%SZ") --region us-east-1

** Benefits:** Major cost savings compared to On-Demand pricing.


tmux: Never Lose Your Terminal Sessions#

Linux admins swear by tmux! It keeps your sessions alive even if your SSH connection drops.

Install & Use#

bash

CopyEdit

sudo yum install -y tmux # For Amazon Linux tmux new -s mysession

  • Detach: Ctrl + B, D
  • Reattach: tmux attach -t mysession ** Benefits:** Persistent terminal sessions for long-running commands.

Automate Linux Admin Tasks with Bash Scripts#

Speed up repetitive Linux tasks with Bash scripting. Example: Auto-clean disk space:

bash

CopyEdit

#!/bin/bash echo "Cleaning logs..." find /var/log -type f -name "*.log" -mtime +7 -exec rm -f {} \; echo "Cleanup complete!"

Run it automatically with a cron job:

bash

CopyEdit

crontab -e 0 3 * * * /home/ec2-user/cleanup.sh

** Benefits:** Saves time and keeps systems optimized.


Final Thoughts#

These AWS & Linux tricks will boost your productivity, cut costs, and improve security. Try them out and make your DevOps life easier!

For more DevOps guides & AWS tips, keep following Noobie.Cloud! 🚀

Top AWS & Linux Tricks Every DevOps Engineer Should Know
https://noobie.cloud/blog/linux-tricks
Author noobiecloud@protonmail.com
Published at February 16, 2024
Comment seems to stuck. Try to refresh?✨