Introduction
AWS Security is a collection of services, tools, and best practices designed to protect your data, workloads, and infrastructure in the AWS Cloud. Security in AWS follows the shared responsibility model, where AWS secures the infrastructure that runs all services, and you are responsible for securing your data and resources built on top of AWS.
Core Security Services
Identity and Access Management (IAM)
| Service | Primary Use | Key Features |
|---|
| IAM | User and access management | Users, groups, roles, policies |
| AWS SSO/IAM Identity Center | Centralized access management | Single sign-on, directory integration |
| AWS Organizations | Multi-account management | Consolidated billing, service control policies |
| AWS Directory Service | Directory management | Active Directory integration |
| AWS Control Tower | Account governance | Landing zone setup, guardrails |
Data Protection
| Service | Primary Use | Key Features |
|---|
| AWS KMS | Key management | Encryption key creation and control |
| AWS CloudHSM | Hardware security modules | FIPS 140-2 Level 3 validation |
| AWS Certificate Manager | SSL/TLS certificates | Free certificate provisioning and renewal |
| AWS Secrets Manager | Secret storage | Secret rotation, encryption |
| AWS Systems Manager Parameter Store | Parameter storage | Hierarchical storage, versioning |
Network Security
| Service | Primary Use | Key Features |
|---|
| Amazon VPC | Network isolation | Subnets, route tables, NACLs |
| Security Groups | Instance-level firewall | Stateful packet filtering |
| Network ACLs | Subnet-level firewall | Stateless packet filtering |
| AWS WAF | Web application firewall | Request filtering, bot control |
| AWS Shield | DDoS protection | Standard (free), Advanced (paid) |
| AWS Network Firewall | Network traffic filtering | Stateful, managed firewall |
| AWS Firewall Manager | Centralized security management | Policy administration across accounts |
Detection & Monitoring
| Service | Primary Use | Key Features |
|---|
| Amazon GuardDuty | Threat detection | ML-powered anomaly detection |
| AWS Security Hub | Security posture management | Compliance checks, findings aggregation |
| Amazon Inspector | Vulnerability management | Automated assessments |
| AWS Config | Resource configuration | Configuration history, rules |
| AWS CloudTrail | API activity logging | User activity, API history |
| Amazon CloudWatch | Monitoring and observability | Metrics, logs, alarms |
| Amazon Detective | Security investigation | Root cause analysis |
| AWS Trusted Advisor | Best practice checks | Performance, security, cost optimization |
IAM Best Practices
User Management
- Use IAM Identity Center (AWS SSO) instead of IAM users when possible
- Implement MFA for all users, especially the root account
- Create individual IAM users instead of sharing credentials
- Rotate credentials regularly
- Remove unused credentials
Permission Management
- Follow principle of least privilege
- Use groups to assign permissions to IAM users
- Use IAM roles for applications and services
- Do not share access keys
- Use permission boundaries for delegation
IAM Policy Types
| Policy Type | Description | Use Case |
|---|
| Identity-based | Attached to IAM identities | Grant permissions to users/roles |
| Resource-based | Attached to resources | Control access to specific resources |
| Service control policies (SCPs) | Applied to AWS Organizations | Set permission guardrails |
| Session policies | Passed when assuming roles | Restrict session permissions |
| Permission boundaries | Set maximum permissions | Delegate admin to others safely |
Example IAM Policy (Least Privilege for S3)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::example-bucket",
"arn:aws:s3:::example-bucket/*"
],
"Condition": {
"IpAddress": {
"aws:SourceIp": "192.0.2.0/24"
}
}
}
]
}
VPC Security
VPC Security Components
- Security Groups: Stateful, allow-only, instance-level firewall
- Network ACLs: Stateless, allow/deny rules, subnet-level firewall
- Flow Logs: Capture network traffic information
- VPC Endpoints: Private connections to AWS services
- Transit Gateway: Network transit hub for connecting VPCs and on-premises networks
Security Group vs NACL
| Feature | Security Group | Network ACL |
|---|
| Scope | Instance level | Subnet level |
| State | Stateful | Stateless |
| Rule types | Allow only | Allow and deny |
| Processing | All rules evaluated | Rules processed in order |
| Return traffic | Automatically allowed | Requires explicit rules |
VPC Security Best Practices
- Use private subnets for resources that don’t need internet access
- Use a bastion host or AWS Systems Manager Session Manager for secure access
- Implement VPC flow logs for network monitoring
- Use VPC endpoints to access AWS services privately
- Implement network segmentation with multiple subnets
Data Protection
Encryption Options
| Type | Description | When to Use |
|---|
| Server-side encryption | Data encrypted at rest by AWS | Default protection for most services |
| Client-side encryption | Data encrypted before sending to AWS | Highly sensitive data, compliance |
| In-transit encryption | Data encrypted while moving | All internet-facing communications |
AWS KMS Key Types
| Key Type | Description | Control Level |
|---|
| Customer managed keys (CMK) | Created and managed by you | Full control |
| AWS managed keys | Created and managed by AWS | Limited control |
| AWS owned keys | Owned and managed solely by AWS | No control |
Data Protection Best Practices
- Encrypt data at rest and in transit
- Use AWS KMS for key management
- Implement S3 bucket policies and ACLs
- Enable versioning and MFA delete for S3
- Use AWS Backup for consistent backups
- Implement DLP (Data Loss Prevention) mechanisms
- Regularly audit access patterns
Monitoring & Detection
Essential Monitoring Stack
- CloudTrail: Enable in all regions, log to a dedicated S3 bucket
- Config: Enable configuration recording in all regions
- GuardDuty: Enable threat detection in all regions
- Security Hub: Centralize security findings
- CloudWatch: Set up alarms for suspicious activities
CloudTrail Log Example (S3 Bucket Policy)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my-cloudtrail-bucket/AWSLogs/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
},
{
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::my-cloudtrail-bucket"
}
]
}
Detection Best Practices
- Enable GuardDuty in all regions and accounts
- Configure Security Hub and enable AWS Foundational Security Best Practices standard
- Set up CloudWatch alarms for unusual API calls
- Monitor and alert on root account usage
- Use AWS Config to detect non-compliant resources
- Implement automated remediation with AWS Config Rules and Lambda
Incident Response
IR Framework in AWS
- Preparation: Establish response plans, implement detective controls
- Detection & Analysis: Use GuardDuty, Security Hub, CloudWatch
- Containment: Isolate affected resources (security groups, IAM policies)
- Eradication: Remove unauthorized access, malware
- Recovery: Restore from backups, redeploy clean resources
- Post-incident: Lessons learned, improve controls
IR Automation with AWS
- Use EventBridge to trigger automated responses
- Implement AWS Lambda functions for automated remediation
- Create incident response runbooks in Systems Manager
- Use tagging to track incident-related resources
Sample EventBridge Rule for GuardDuty Findings
{
"source": ["aws.guardduty"],
"detail-type": ["GuardDuty Finding"],
"detail": {
"severity": [7, 8, 9]
}
}
Compliance and Governance
AWS Compliance Programs
- SOC 1/2/3
- PCI DSS
- HIPAA
- FedRAMP
- GDPR
- ISO 27001/27017/27018/9001
- NIST
Compliance Tools
- AWS Artifact: Access compliance reports
- AWS Config: Assess resource compliance
- AWS Security Hub: Automate compliance checks
- AWS Audit Manager: Continuous audit evidence collection
- Service Control Policies: Enforce compliance guardrails
Example AWS Config Rule
{
"ConfigRuleName": "s3-bucket-public-read-prohibited",
"Description": "Checks that your S3 buckets do not allow public read access",
"Scope": {
"ComplianceResourceTypes": ["AWS::S3::Bucket"]
},
"Source": {
"Owner": "AWS",
"SourceIdentifier": "S3_BUCKET_PUBLIC_READ_PROHIBITED"
}
}
Multi-Account Security
AWS Organizations Best Practices
- Implement a multi-account strategy based on business functions
- Use AWS Control Tower for account setup and governance
- Apply SCPs to restrict capabilities within member accounts
- Centralize logging to a dedicated Security account
- Use AWS Config Aggregator for multi-account visibility
Sample SCP (Prevent Public S3 buckets)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Action": [
"s3:PutBucketPublicAccessBlock",
"s3:PutAccountPublicAccessBlock"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"s3:PublicAccessBlockConfiguration": "false"
}
}
}
]
}
Container & Serverless Security
Container Security
- Use ECR image scanning to detect vulnerabilities
- Implement least privilege task execution roles
- Use AWS Fargate for enhanced isolation
- Enable VPC mode for ECS/EKS
- Implement runtime monitoring with GuardDuty
Serverless Security
- Use IAM roles with minimal permissions for Lambda functions
- Configure Lambda in a VPC when accessing private resources
- Enable Lambda code signing
- Set appropriate Lambda timeout values
- Implement Lambda environment variable encryption
Common Security Challenges and Solutions
| Challenge | Solution |
|---|
| Excessive permissions | Implement IAM Access Analyzer |
| Unencrypted data | Enable default encryption, use AWS KMS |
| Public resources | Use S3 Block Public Access, Security Hub checks |
| Credential exposure | Use Secrets Manager, rotate credentials |
| Insecure configurations | Implement AWS Config rules, Security Hub standards |
| Account compromise | Enable CloudTrail, GuardDuty, MFA |
| DDoS attacks | Use Shield, WAF, and secure architecture patterns |
Security Assessment Tools
| Tool | Purpose | When to Use |
|---|
| IAM Access Analyzer | Find unintended resource access | Regularly for permission review |
| Trusted Advisor | Check AWS best practices | Baseline assessments |
| Amazon Inspector | Vulnerability assessment | For EC2, ECR images, Lambda |
| AWS Config | Configuration compliance | Continuous compliance monitoring |
| Security Hub | Security posture | Central security management |
| Prowler (3rd party) | AWS security assessment | Comprehensive account review |
Security Automation
Infrastructure as Code (IaC) Security
- Use AWS CloudFormation Guard or cdk-nag for policy validation
- Implement CI/CD pipeline security scanning
- Use service catalog for approved templates
- Implement drift detection
Example CloudFormation Guard Rule
rule secure_s3_bucket_policy {
when %s3_bucket !empty {
%s3_bucket.Properties.PublicAccessBlockConfiguration exists
%s3_bucket.Properties.PublicAccessBlockConfiguration.BlockPublicAcls == true
%s3_bucket.Properties.PublicAccessBlockConfiguration.BlockPublicPolicy == true
%s3_bucket.Properties.PublicAccessBlockConfiguration.IgnorePublicAcls == true
%s3_bucket.Properties.PublicAccessBlockConfiguration.RestrictPublicBuckets == true
}
}
Security Response Automation
Common Use Cases for Automation
- Remediate public resources
- Rotate compromised keys
- Isolate compromised instances
- Snapshot forensic data
- Block suspicious IP addresses
Sample Remediation Lambda Function (Python)
import boto3
def lambda_handler(event, context):
# Parse GuardDuty finding
finding = event['detail']
resource_type = finding['resource']['resourceType']
resource_id = finding['resource']['instanceDetails']['instanceId']
# Isolate compromised EC2 instance
if resource_type == 'Instance':
ec2 = boto3.client('ec2')
# Create isolation security group
isolation_sg = ec2.create_security_group(
GroupName=f'isolation-{resource_id}',
Description='Isolation security group for compromised instance',
VpcId=finding['resource']['instanceDetails']['networkInterfaces'][0]['vpcId']
)
# Apply isolation security group
ec2.modify_instance_attribute(
InstanceId=resource_id,
Groups=[isolation_sg['GroupId']]
)
return {
'statusCode': 200,
'body': f'Instance {resource_id} isolated successfully'
}
AWS Security Checklist
Day 1 Security Controls
- [ ] Enable MFA for root and all IAM users
- [ ] Create dedicated IAM users with least privilege
- [ ] Set up AWS Organizations with SCPs
- [ ] Enable CloudTrail in all regions
- [ ] Configure S3 Block Public Access at account level
- [ ] Enable GuardDuty in all regions
- [ ] Set up Security Hub
- [ ] Configure AWS Config
Weekly Security Tasks
- [ ] Review GuardDuty findings
- [ ] Check Security Hub compliance status
- [ ] Review CloudTrail for unusual activity
- [ ] Rotate keys and credentials
- [ ] Update AMIs and containers
Monthly Security Tasks
- [ ] Run penetration tests (with AWS approval)
- [ ] Review IAM Access Analyzer findings
- [ ] Conduct security architecture review
- [ ] Update incident response runbooks
- [ ] Review AWS Trusted Advisor recommendations
Resources for Further Learning