DEV Community

Yash Sonawane
Yash Sonawane

Posted on

How to Secure Your EC2, S3 & RDS Like a DevOps Engineer ๐Ÿ”๐Ÿš€

"Your AWS setup is only as strong as your weakest misconfiguration."

If you're just launching your first EC2 instance, uploading files to S3, or spinning up an RDS database โ€” congratulations! Youโ€™re building on the cloud. But hereโ€™s a hard truth: 90% of security issues in AWS come from avoidable mistakes.

Today, Iโ€™ll show you how to secure your EC2, S3, and RDS like a DevOps engineer โ€” even if you're brand new to cloud. No jargon. No overkill. Just real tips, relatable analogies, and actionable code snippets.

Letโ€™s lock it down. ๐Ÿ›ก๏ธ


๐Ÿšช Step 1: Secure Your EC2 Like It's Your Front Door

Imagine EC2 as your house in the cloud. You wouldnโ€™t leave your front door wide open, right?

โœ… What to Do:

  • Use key pairs for SSH access (never passwords!)
  • Restrict inbound traffic with Security Groups
  • Change the default SSH port (22) to something custom (e.g., 2222)
  • Use a bastion host or VPN for private instances

๐Ÿ›‘ What to Avoid:

  • Opening ports to 0.0.0.0/0 unless absolutely needed (this means open to the world!)
  • Using root user for everyday tasks

๐Ÿ” Example Security Group:

aws ec2 authorize-security-group-ingress \
  --group-id sg-01234abcde \
  --protocol tcp \
  --port 22 \
  --cidr 203.0.113.0/24
Enter fullscreen mode Exit fullscreen mode

This allows only your office/home IP to access the instance via SSH.


๐Ÿ“ฆ Step 2: Secure Your S3 Like a Vault (Not a Public Folder)

S3 is powerful โ€” but dangerously easy to misconfigure.

Real-world fail: A dev uploads app logs with customer data to a public bucket. It gets scraped by bots in minutes.

โœ… What to Do:

  • Enable Block Public Access on all buckets
  • Use bucket policies to control access tightly
  • Enable S3 server-side encryption (SSE)
  • Use pre-signed URLs for temporary file access

๐Ÿ”’ Example Bucket Policy (Read Only for Authenticated Users):

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-secure-bucket/*",
      "Condition": {
        "Bool": {"aws:SecureTransport": "true"}
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Pro tip: Use S3 access logs to track who accessed what, and when.


๐Ÿ›ข๏ธ Step 3: Secure Your RDS Like a Fortified Database

Databases are prime targets for attackers. If youโ€™re using RDS for MySQL, PostgreSQL, or Aurora, lock it down.

โœ… What to Do:

  • Keep your RDS inside a private subnet
  • Restrict access using Security Groups
  • Enable encryption at rest and in transit
  • Turn on automated backups and multi-AZ failover

๐Ÿ”‘ IAM Authentication (Optional)

Use IAM users instead of native DB usernames/passwords โ€” especially for short-lived apps or internal tooling.

aws rds generate-db-auth-token \
  --hostname mydb.cluster-xyz.us-east-1.rds.amazonaws.com \
  --port 3306 \
  --region us-east-1 \
  --username devuser
Enter fullscreen mode Exit fullscreen mode

Reminder: Donโ€™t expose RDS to the internet unless absolutely necessary. Use a bastion host or AWS Systems Manager Session Manager.


๐Ÿง  Bonus Tips Across All Services

โœ… Tag your resources for better visibility & automation
โœ… Enable CloudTrail & GuardDuty for monitoring and anomaly detection
โœ… Rotate credentials and access keys regularly
โœ… Use IAM Roles, not long-term static credentials
โœ… Apply least privilege principles โ€” donโ€™t give broad access to anyone


๐Ÿง  TL;DR โ€“ The DevOps Security Checklist

Service What to Secure
EC2 SSH access, ports, IAM roles, key pairs
S3 Public access, bucket policies, encryption
RDS Network access, backups, encryption, IAM auth

๐Ÿ’ฌ Letโ€™s Keep the Cloud Safe โ€” Together

Every dev is responsible for cloud security. These aren't just best practices โ€” they're habits that help you build trust with your users and clients.

๐Ÿ‘‡ Whatโ€™s one security tip YOU swear by? Ever had a close call?

Share your stories in the comments. Hit โค๏ธ if this helped you, and tag a friend who just launched their first AWS project!

Together, letโ€™s build secure โ€” and build smart. ๐Ÿงก

Top comments (0)