Expert · Cloud security and compliance · topic 45 of 50 · 30 min
Logging, threat detection and incident response
Explanation
Why logging comes first
When something goes wrong, the first questions are: who did it, what did they touch, and when? Without logs you cannot answer, cannot prove anything to an auditor, and cannot tell a regulator what happened. Detection tools also read those logs, so logging is the foundation of everything in this topic.
AWS CloudTrail
CloudTrail records API calls: who (the identity), what (the event name, such as RunInstances), when, from which IP address, and whether it succeeded. The console's Event history keeps 90 days of management events for free. For anything longer, create a trail that delivers logs to an S3 bucket.
- Make it a multi-region trail, so activity in a region you never use (a favourite trick of attackers mining cryptocurrency) is still recorded.
- In AWS Organizations, create an organisation trail so every account, including new ones, is covered automatically.
- Send the logs to a bucket in a separate log-archive account, turn on log file integrity validation, and consider S3 Object Lock so nobody can delete or alter them.
- Data events (for example every S3 GetObject) are not logged by default and cost extra; enable them for sensitive buckets.
aws cloudtrail create-trail --name org-trail --s3-bucket-name acme-log-archive \
--is-multi-region-trail --is-organization-trail --enable-log-file-validation
aws cloudtrail start-logging --name org-trail
# Who signed in to the console recently?
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=ConsoleLogin --max-results 5The AWS detection services
| Service | What it does |
|---|---|
| Amazon GuardDuty | Threat detection: reads CloudTrail, VPC Flow Logs and DNS logs to spot things like crypto-mining, calls from known bad IP addresses, or stolen credentials used from outside AWS |
| AWS Security Hub | Collects findings from GuardDuty, Inspector, Macie and others in one place, and checks your settings against standards such as the AWS Foundational Security Best Practices and CIS benchmarks |
| Amazon Inspector | Vulnerability scanning of EC2 instances, container images in ECR and Lambda functions for known software flaws (CVEs) |
| Amazon Macie | Finds sensitive data such as PAN card numbers, credit card numbers or credentials in S3 buckets |
| AWS Config | Records how each resource is configured over time and checks it against rules such as s3-bucket-public-read-prohibited or encrypted-volumes |
On Azure, Microsoft Defender for Cloud does posture checks and workload protection, and Microsoft Sentinel is a SIEM (security information and event management: a system that collects logs from many sources, correlates them and raises incidents). On Google Cloud, Security Command Center plays the role of Security Hub and GuardDuty together. AWS reorganised parts of Security Hub in 2025, so console names may differ; the ideas stay the same.
Network protection: security groups, WAF and Shield
Security groups are stateful firewalls on each instance or load balancer: allow only the ports you need (443 from the internet to the load balancer, the app port only from the load balancer). AWS WAF (web application firewall) inspects HTTP requests at CloudFront, an Application Load Balancer or API Gateway. Start with AWS Managed Rules (such as the core rule set and known bad inputs) and add a rate-based rule that blocks an IP sending too many requests, which stops simple login floods. AWS Shield Standard protects every customer against common network DDoS (distributed denial of service) attacks at no extra cost. Shield Advanced is a paid subscription with a one-year commitment that adds stronger protection, cost protection and access to the AWS response team.
Incident response basics in the cloud
- Prepare: decide in advance who is on call, how they are paged, and keep a written runbook.
- Contain: move a compromised instance into an isolation security group with no inbound or outbound rules. Do not terminate it; you would destroy evidence.
- Preserve evidence: take EBS snapshots and tag them with the incident number; keep the CloudTrail logs.
- Rotate credentials: disable leaked access keys, revoke active role sessions, change passwords and secrets the attacker could have seen.
- Investigate: search CloudTrail for everything the identity did, in every region, from the first suspicious event.
- Recover and learn: rebuild from clean images, fix the root cause, and write a blameless post-incident report. In India, check whether the incident must be reported to CERT-In within 6 hours (covered in the next topic).
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Logging, threat detection and incident response · 1/7
You cannot protect what you cannot see. Logging is the foundation of cloud security.
Prefer a video by a teacher? Find free videos on “AWS CloudTrail GuardDuty Security Hub incident response tutorial” on YouTube ↗
In real life: A late-night alert at an e-commerce company in Gurugram
At 2 a.m., GuardDuty raises a high-severity finding: an EC2 instance in the company's Mumbai account is talking to a known crypto-mining pool. EventBridge pages the on-call engineer. Following the runbook, she moves the instance into an isolation security group, takes EBS snapshots for forensics and disables the IAM role session. CloudTrail shows that an access key from an old CI server launched the instance, plus five more in eu-west-1 and us-west-2, regions the company never uses. The team terminates those after snapshotting them, deletes the key, adds an SCP to block unused regions, and sends a report to CERT-In within the 6-hour window.
Practice (0/3 done)
Which AWS service records who made each API call in your account?
Write cloudtrail_alerts(events) that scans simplified CloudTrail events and returns alert strings, in event order. Each event is a dict with "eventName", "user", "userType" ("Root" or "IAMUser") and, for console logins, "mfaUsed" ("Yes" or "No"). Rules: ConsoleLogin with mfaUsed "No" gives "ConsoleLogin without MFA: <user>"; StopLogging or DeleteTrail gives "<eventName> by <user>: logging tampered"; PutBucketPolicy gives "PutBucketPolicy by <user>: check the bucket is not public"; CreateAccessKey by a Root userType gives "CreateAccessKey by root". Other events give nothing.
Write a one-page incident runbook for "an IAM access key was found in a public GitHub repository". List the steps in order, the AWS commands or consoles you would use, and who you would inform.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Compliance in the cloud, with Indian rulesCloud security and compliance · same module
- Identity is the new perimeterCloud security and compliance · same module
- Logging and monitoring in the cloudCyber Security: from zero to SOC analyst · Cloud security basics
- Common cloud misconfigurationsCyber Security: from zero to SOC analyst · Cloud security basics
- Logs and log sourcesCyber Security: from zero to SOC analyst · Logs, SIEM and incident response
- AWS vs Azure vs Google Cloud: the service mapGoogle Cloud and comparing the clouds
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which service finds credit card numbers stored in S3 buckets?
Answer: Amazon Macie
Macie discovers and reports sensitive data in S3.
Why should a CloudTrail trail be multi-region?
Answer: Attackers often use regions you never use, and a single-region trail would miss them
A multi-region trail records activity everywhere, including regions you do not normally use.
Which AWS service blocks an IP address that sends 2,000 login requests in five minutes?
Answer: AWS WAF with a rate-based rule
A WAF rate-based rule counts requests per IP and blocks those over the limit.
An EC2 instance is compromised. What should you do first?
Answer: Isolate it with a restrictive security group and snapshot its volumes
Isolate to stop the damage, and keep the evidence for investigation.
Which is the Microsoft Azure SIEM service?
Answer: Microsoft Sentinel
Microsoft Sentinel is Azure's cloud SIEM; Defender for Cloud handles posture and workload protection.
Which Amazon service gives managed threat detection on CloudTrail, VPC flow and DNS data?Related
Answer: GuardDuty
GuardDuty analyses these sources and raises findings.
An auditor asks how a security group was configured last Tuesday. Which service answers best?Related
Answer: AWS Config
AWS Config records the configuration history of resources and can check them against rules.
Which service gives global layer 7 routing at Microsoft's edge, with caching and WAF?Related
Answer: Azure Front Door
Front Door is global and HTTP-aware. Application Gateway is regional; Load Balancer is layer 4.
Why require IMDSv2 on AWS servers?Related
Answer: It makes it much harder for an SSRF bug to steal the server's credentials
IMDSv2 needs a session token, which typical SSRF requests cannot get.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 1 more topic in “Cloud security and compliance” before its exam: Compliance in the cloud, with Indian rules.
- Module 11 exam: Cloud security and compliance · 14 questions · 20 min, without help. 4 topics of this module still to finish first.
- Then the next module, Certifications and cloud careers. 50 topics left in the course before the final exam.