TL;DR
This guide shows how to secure your AWS Dev, Test, Staging and Production environments using IAM roles, security groups, network ACLs, WAF, and monitoring. It focuses on least privilege access and layered defence.
1. Identity and Access Management (IAM)
- Create Separate IAM Roles: Don’t use the same role for all environments. Each environment needs a specific role with limited permissions.
- Dev Role: Basic access – code deployment, testing.
- Test Role: More access than Dev – data creation/modification (limited).
- Staging Role: Near-Production access – full application functionality but isolated data.
- Production Role: Least privilege for essential operations only – monitoring, scaling, emergency fixes.
- Define Policies: Use AWS managed policies as a starting point and then refine them to restrict access further.
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:GetObject", "s3:PutObject"], "Resource": "arn:aws:s3:::your-dev-bucket/*" } ] } - Multi-Factor Authentication (MFA): Enforce MFA for all IAM users, especially those with administrative access.
2. Network Security
- VPC Design: Isolate each environment within its own Virtual Private Cloud (VPC) or subnet.
- This prevents accidental cross-environment data access.
- Security Groups: Act as virtual firewalls for your instances.
- Dev/Test: Allow wider ranges of inbound traffic (e.g., from your development IP addresses).
- Staging: Restrict inbound traffic to specific IPs or CIDR blocks used for testing and internal access.
- Production: Allow only necessary inbound traffic – typically limited to load balancers, bastion hosts, and monitoring services.
- Network ACLs: Provide an additional layer of security at the subnet level.
- Use them to block known malicious IPs or protocols.
3. Web Application Firewall (WAF)
- Deploy WAF: Protect your web applications from common web exploits.
- Use AWS WAF or a third-party solution.
- Create Rules: Implement rules to block SQL injection, cross-site scripting (XSS), and other attacks.
aws wafv2 createwebacl --name MyWebACL --scope REGIONAL --defaultaction Block --rules "[{"Name":"SQLInjectionRule","Priority":10,"Statement":{"ManagedRuleSetId":"AWS:CoreRuleSet:SQLInjection:1.0"},"Action":{"Block"}}"] - Rate Limiting: Protect against DDoS attacks by limiting the number of requests from a single IP address.
4. Data Protection
- Encryption at Rest: Encrypt data stored in S3, EBS volumes, and databases using KMS keys.
- Use different KMS keys for each environment.
- Encryption in Transit: Use HTTPS (TLS) to encrypt data transmitted between clients and your applications.
- Database Access Control: Limit database access to authorized IAM roles and security groups.
5. Monitoring and Logging
- CloudTrail: Enable CloudTrail to log all API calls made in your AWS account.
- Monitor for suspicious activity, such as unauthorized access attempts or changes to security configurations.
- CloudWatch: Monitor key metrics and set up alarms to alert you of potential issues.
- Track CPU usage, memory utilization, network traffic, and error rates.
- VPC Flow Logs: Capture information about the IP traffic going to and from your VPCs.
- Use this data to identify potential security threats or performance bottlenecks.
6. Automation
- Infrastructure as Code (IaC): Use tools like Terraform or CloudFormation to automate the deployment and configuration of your AWS infrastructure.
- This ensures consistency and repeatability, reducing the risk of manual errors.

