1. CloudWatch #
Metrics, logs and alarms.
Principles #
- Metrics: published automatically by services (EC2 CPU, ALB latency…); the CloudWatch agent adds memory and disk.
- Logs: log groups, queries with Logs Insights, retention to define (unlimited by default).
- Alarms: threshold or anomaly detection, SNS, Auto Scaling or EC2 actions.
Examples #
aws cloudwatch put-metric-alarm --alarm-name api-5xx --namespace AWS/ApplicationELB \
--metric-name HTTPCode_Target_5XX_Count --dimensions Name=LoadBalancer,Value=app/api/abc123 \
--statistic Sum --period 300 --evaluation-periods 2 --threshold 20 --comparison-operator GreaterThanThreshold \
--alarm-actions arn:aws:sns:eu-west-3:123456789012:astreinte
aws logs put-retention-policy --log-group-name /aws/lambda/api --retention-in-days 30
# Logs Insights : erreurs par minute
# fields @timestamp, @message | filter @message like /ERROR/ | stats count() by bin(1m)2. Audit and compliance #
CloudTrail and AWS Config.
CloudTrail #
CloudTrail records API calls (console, CLI, SDK): who, when, from where, with what result. Create an organization-wide, multi-region trail to an S3 bucket in an account dedicated to logs, with integrity validation.
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteBucket --max-results 5AWS Config #
AWS Config records the configuration history of each resource and evaluates rules (public bucket, unencrypted volume, security group open to 0.0.0.0/0 on port 22), with optional automatic remediation.
3. Protecting #
Encryption, secrets, threats.
Services #
| Service | Role |
|---|---|
| KMS | Managed encryption keys, used by S3, EBS, RDS…; logged in CloudTrail |
| Secrets Manager | Storage and automatic rotation of secrets (database passwords, API keys) |
| GuardDuty | Detection of suspicious activity (compromised credentials, mining, abnormal calls) |
| Security Hub | Consolidated findings and best-practice checks (AWS framework, CIS) |
| AWS WAF, Shield | Web application firewall in front of CloudFront and ALB, DDoS protection |
Good practice: Enable GuardDuty, Security Hub and Config in all accounts and all regions in use, with a delegated administrator account for security.
