By the end you'll know
- What GuardDuty, Security Hub and Config each watch, and how they differ
- How Config records resources, and what a configuration item is
- How a Config rule decides compliant or non-compliant, and how quickly
- How to read a resource's whole history of changes
- What GuardDuty's findings and Security Hub's checks look like, and what they cost
- What a free-plan account can't use, and how that shows up
Before you start
- You need: the
juniper-ryeprofile, signed in, and Lesson 20's virtual environment. Lesson 9 covers security groups, and Lesson 33 the CloudTrail events GuardDuty reads. - The script:
lab.pyfrom the practice folder'slesson-35. Everything it creates is namedjr-lesson35-*and taggedlesson=35, and itsdeletestep removes it. - Where you run things: your own machine, labeled (Your machine).
- Every output below is from a real run on November 16, 2026, at about 11am in New York, which is 4pm UTC.
Two of these three weren't run
This lab ran on a free-plan account, and the free plan doesn't allow GuardDuty or Security Hub: every call to them, even a read, was refused. Config worked, so its part is real output. The GuardDuty and Security Hub sections explain what they do from AWS's documentation, and say so. On a paid-plan account, both have a 30-day free trial; on the free plan, trials don't apply and usage comes out of your credits.
The short version
- Config records how resources are set up, and every change, then checks them against rules.
- A configuration item is one snapshot of one resource; Config charges for each one it records.
- Config rules mark resources compliant or non-compliant, here within two minutes of a change.
- GuardDuty reads CloudTrail, VPC flow logs and DNS logs to spot threats, with nothing to install.
- Security Hub runs best-practice checks and gathers findings from GuardDuty, Config and others in one format.
- Record only what you need: Config's bill is set by how many changes it records.
What this lesson costs
| Part | Price | This lab |
|---|---|---|
| Config: each change recorded (a configuration item) | About $0.003 | About 5: two security groups, a few changes |
| Config: each rule evaluation | About $0.001 | About 6 |
| Config's files in S3 | S3 storage | 1 small file, deleted the same hour |
| GuardDuty and Security Hub | Per event or check analyzed | Nothing: refused |
| The network and security group | Free | Nothing |
| This lesson | About two cents |
Three watchers, three questions
Every lesson so far built something and checked it once. Real accounts change all day, by people, scripts and attackers, and nobody re-checks by hand. These three services check continuously, and each answers a different question:
| GuardDuty | Config | Security Hub | |
|---|---|---|---|
| Question | Is someone attacking us, or already in? | How is everything set up, and did it break a rule? | How do we stand overall, in one place? |
| Looks at | Activity: CloudTrail, VPC flow logs, DNS queries | Settings of each resource, and every change | Findings from the other two, and its own checks |
| Produces | Threat findings, like "SSH brute force" | Configuration items, and compliant or non-compliant | One list of findings, in one format |
| On this account | Refused | Ran | Refused |
What's on, and what's allowed
(Your machine)
cd ~/Apps/aws-practice/lesson-35
source ../lesson-20/.venv/bin/activate
python lab.py fence
== What's already on in us-east-2
AWS said: An error occurred (AccessDeniedException) when calling the ListDetectors operation: User: (an ARN) is not authorized to perform: guardduty:ListDetectors on resource: (an ARN) with an explicit deny in a service control policy: (an ARN)
Even listing GuardDuty was refused, "with an explicit deny in a service control policy". This account isn't in an organization, so nobody here wrote that policy: it's the free plan's own. Lesson 33 found the same wording on a refused IAM call. The script asked three times, in fence, on and samples, and got the same answer each time; one is shown. Security Hub's DescribeHub got the same refusal later. The script that ran this didn't expect a refusal and stopped; it now reports both services as blocked and carries on, which is the version in the practice folder.
This is worth recognizing on any account: an AccessDenied that mentions an explicit deny in a service control policy can't be fixed with IAM. Something above the account said no. In a company, that's the organization's administrators; on a free-plan account, it's the plan.
Config: the inspector
Config needs three things to start:
- A recorder, which says which resource types to record. Recording everything is the default, and the expensive choice: Config charges for every change it records. This one records security groups only.
- A delivery channel, an S3 bucket where Config writes snapshots and history files.
- A service-linked role, a role AWS defines that lets Config read your resources. It's free, and the script creates it if it's missing.
Then rules check what's recorded. AWS has hundreds of managed rules, ready-made checks you turn on by name; this lab uses INCOMING_SSH_DISABLED, known in the console as restricted-ssh, which fails any security group that allows SSH from anywhere.
python lab.py config
== Created Config's service-linked role
== Config recorder: security groups only, recorded continuously
recording: True; files go to s3://jr-lesson35-config-9969f3ef/AWSLogs/...
== The rule: AWS's managed rule INCOMING_SSH_DISABLED (restricted-ssh), for security groups
jr-lesson35-restricted-ssh: ACTIVE, triggered by configuration changes
== The ovens network vpc-05172d9d662630150 and its security group jr-lesson35-ovens, sg-097491a4873dc04cd: no inbound rules
waiting for Config to evaluate the new security group (every 20 seconds, up to 15 minutes)
COMPLIANT at 16:09:14 UTC, 320 seconds after the change
"Triggered by configuration changes" means the rule runs whenever Config records a change to a security group. Other rules run on a schedule instead, every few hours or once a day; those are for settings that don't show up as a resource change.
"320 seconds after the change" is the script measuring from the wrong moment, five minutes before it started waiting. The history below shows Config recorded the new group at 16:09:04, so it was judged compliant 10 seconds later.
Break it, and watch
The same mistake as Lesson 33's story: SSH opened to the whole internet "for debugging", then closed. This time something is watching.
python lab.py break
== 16:09:35 UTC: opened port 22 (SSH) to 0.0.0.0/0
waiting for Config to evaluate the open port (every 20 seconds, up to 15 minutes)
NON_COMPLIANT at 16:11:03 UTC, 88 seconds after the change
== 16:11:16 UTC: closed it again
waiting for Config to evaluate the closed port (every 20 seconds, up to 15 minutes)
COMPLIANT at 16:13:20 UTC, 124 seconds after the change
Flagged 88 seconds after it happened, and cleared two minutes after it was fixed. Nobody had to look. In a real account, a non-compliant result can send an alert through EventBridge, or start an automatic fix: Config remediation runs a Systems Manager Automation document, such as one that removes the offending rule.
The history
Config doesn't just know how things are now; it keeps every version. get_resource_config_history returns them in order:
python lab.py history
== Asking Config for the history of jr-lesson35-ovens (every 30 seconds, for up to 10 minutes, until it has all 3 changes)
found after 47 seconds
== Config's record of jr-lesson35-ovens: 3 configuration items
captured status inbound rules
16:09:04 ResourceDiscovered none
16:10:51 OK tcp 22-22 from 0.0.0.0/0
16:13:11 OK none
== One configuration item (some fields left out)
{
"configurationItemCaptureTime": "2026-11-16 11:10:51.386000-05:00",
"configurationItemStatus": "OK",
"resourceType": "AWS::EC2::SecurityGroup",
"resourceId": "sg-097491a4873dc04cd",
"resourceName": "jr-lesson35-ovens",
"awsRegion": "us-east-2",
"relatedEvents": [],
"relationships": [
{
"resourceType": "AWS::EC2::VPC",
"resourceId": "vpc-05172d9d662630150",
"relationshipName": "Is contained in Vpc"
}
]
}
Each row is a configuration item: a full snapshot of the resource at that moment, with its settings, tags and relationships. ResourceDiscovered is the first one; OK means recorded normally. The capture time in the JSON is in New York time (-05:00) because the script didn't convert it; 11:10:51 there is 16:10:51 UTC. It converts it now.
Put the times side by side and Config's speed comes into focus:
| Change | Made | Recorded | Judged |
|---|---|---|---|
| Security group created | About 16:09 | 16:09:04 | 16:09:14 compliant |
| SSH opened to the internet | 16:09:35 | 16:10:51, 76 seconds later | 16:11:03 non-compliant |
| SSH closed | 16:11:16 | 16:13:11, 115 seconds later | 16:13:20 compliant |
Almost all the delay is Config noticing the change; the rule itself takes about 10 seconds. Plan on a minute or two between a mistake and a flag, not seconds.
The relationship says which network the group belongs to. Config builds those links for every resource it records, which is how it can answer "what's in this VPC?" or "what uses this security group?" for any point in the past.
GuardDuty: the night watchman (not run here)
GuardDuty reads three sources it collects for itself, with nothing to install or turn on: CloudTrail management events, VPC flow logs, and DNS query logs. It compares them with threat intelligence, like lists of known attacker addresses, and with what's normal for your account, and raises findings when something looks wrong. Optional protection plans add more sources, such as S3 data events, EKS audit logs, and malware scans of EBS volumes.
Finding types are named in a pattern that says what's happening: ThreatPurpose:ResourceType/ThreatFamily. Some of the ones this lab would have asked for as samples:
| Finding type | What it means |
|---|---|
UnauthorizedAccess:EC2/SSHBruteForce | Something is trying passwords on an instance's SSH port |
Recon:EC2/PortProbeUnprotectedPort | A known scanner is probing a port a security group leaves open |
CryptoCurrency:EC2/BitcoinTool.B!DNS | An instance is looking up cryptocurrency mining servers |
UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration.OutsideAWS | An instance's role credentials are being used from outside AWS: stolen |
Policy:S3/BucketBlockPublicAccessDisabled | Someone turned off a bucket's public access block |
Sample findings are how you'd try it safely: create_sample_findings makes fake findings of any type, marked as samples, so you can test alerts and dashboards without an attack. Each finding has a severity, from low to high, and a count of how many times it's been seen. GuardDuty is priced by how much it reads: per million CloudTrail events, and per gigabyte of flow and DNS logs. A quiet account costs very little; a busy one, enough to check the estimate it shows during the trial.
Turning it on is one call, create_detector, per Region. That's the whole setup, which is why it's on in almost every real account, in every Region, including the ones nobody uses.
Security Hub: the manager's desk (not run here)
Security Hub does two jobs. It gathers findings from GuardDuty, Config, Inspector, Macie, IAM Access Analyzer and partner products, and converts them to one format, the AWS Security Finding Format (ASFF), so one filter or one alert works across all of them. And it runs security checks against standards: the AWS Foundational Security Best Practices, the CIS AWS Foundations Benchmark, NIST SP 800-53 and PCI DSS. Those checks are Config rules underneath, which is why Security Hub needs Config recording.
The name changed recently. That service is now called Security Hub CSPM (Cloud Security Posture Management), and AWS launched a new Security Hub on top of it that combines Security Hub CSPM, GuardDuty and Inspector, with one bill. Most documentation, exams and existing accounts still mean the CSPM one when they say Security Hub.
This lab would have turned it on without any standards, so it ran no paid checks, and used it only to collect GuardDuty's samples and Config's result. Security Hub CSPM is priced per check run and per finding taken in, with a 30-day trial on paid-plan accounts.
Take it down
python lab.py delete
python lab.py check
== Deleted security group jr-lesson35-ovens
== Deleted network vpc-05172d9d662630150
== Deleted bucket jr-lesson35-config-9969f3ef and its 1 files
== Anything left on from Lesson 35
nothing: all clear
(Config's service-linked role stays: it's free, and Config reuses it)
This is the second delete. The first one deleted the Config rule, then stopped and deleted the recorder and its delivery channel, and then stopped at Security Hub's refusal before it reached the network and the bucket. That's why a lab's cleanup should carry on past an error it can explain. Stopping the recorder is what stops the charges; the configuration items already recorded aren't billed again.
By hand: the same with the AWS CLI
(Your machine) With a bucket $BUCKET whose policy allows Config to write, and the service-linked role created:
export AWS_PROFILE=juniper-rye AWS_REGION=us-east-2
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
aws configservice put-configuration-recorder --configuration-recorder name=default,roleARN=arn:aws:iam::$ACCOUNT:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig --recording-group '{"allSupported":false,"includeGlobalResourceTypes":false,"resourceTypes":["AWS::EC2::SecurityGroup"],"recordingStrategy":{"useOnly":"INCLUSION_BY_RESOURCE_TYPES"}}'
aws configservice put-delivery-channel --delivery-channel name=default,s3BucketName=$BUCKET
aws configservice start-configuration-recorder --configuration-recorder-name default
aws configservice put-config-rule --config-rule '{"ConfigRuleName":"restricted-ssh","Scope":{"ComplianceResourceTypes":["AWS::EC2::SecurityGroup"]},"Source":{"Owner":"AWS","SourceIdentifier":"INCOMING_SSH_DISABLED"}}'
What's non-compliant, and a group's history:
aws configservice describe-compliance-by-config-rule --config-rule-names restricted-ssh
aws configservice get-compliance-details-by-config-rule --config-rule-name restricted-ssh --compliance-types NON_COMPLIANT
aws configservice get-resource-config-history --resource-type AWS::EC2::SecurityGroup --resource-id sg-... --query "configurationItems[].[configurationItemCaptureTime,configurationItemStatus]" --output table
Turn it off:
aws configservice delete-config-rule --config-rule-name restricted-ssh
aws configservice stop-configuration-recorder --configuration-recorder-name default
aws configservice delete-delivery-channel --delivery-channel-name default
aws configservice delete-configuration-recorder --configuration-recorder-name default
On a paid-plan account, GuardDuty is aws guardduty create-detector --enable, then aws guardduty create-sample-findings --detector-id ... --finding-types ..., and off is aws guardduty delete-detector.
In real systems
- GuardDuty is on in every account and every Region, turned on for the whole organization from one delegated administrator account.
- Security Hub collects findings from every account into one, with cross-Region aggregation, and its standards give a score teams track over time.
- Config records in every account, with an aggregator that shows all of them together. That's not available on the free plan.
- Conformance packs deploy a whole set of Config rules at once, like the ones for a compliance standard.
- High-severity findings go to people: EventBridge rules send them to a chat channel or a paging tool, and some trigger automatic fixes.
- Config's recording is scoped to the resource types that matter, sometimes recorded daily instead of continuously, because recording everything in a busy account is one of the more common surprise bills.
Spot the problem
Work out what's wrong before you read the explanation.
"Config cost more than the servers." A team turns on Config with the console's defaults to pass an audit. Their account runs an EKS cluster whose nodes scale up and down all day, each new node bringing its own network interface and volume. The next bill shows Config costing more than the EC2 instances. What's wrong? Recording all resource types continuously charges for every configuration item, and constantly changing resources like autoscaled instances, network interfaces and volumes produce thousands a day. The fix: record only the resource types the rules and the audit need, and record the noisy ones daily instead of continuously, or exclude them. Then check: Config's own dashboard and the bill both show configuration items by resource type; the top few are usually the answer.
Keep this
| Remember | Why |
|---|---|
| GuardDuty: threats, from activity | CloudTrail, flow logs, DNS; nothing to install |
| Config: settings, and every change | Configuration items, kept as history |
| Security Hub: one list, one format | ASFF, plus best-practice checks |
| Config rules flag in a minute or two | Most of that is recording, not the rule |
| Record only the types you need | Each configuration item is charged |
| Stop the recorder to stop the charges | Deleting rules alone doesn't |
| Explicit deny in an SCP can't be fixed by IAM | Something above the account said no |
Where you are now
Juniper & Rye's ovens security group was watched for a quarter of an hour: Config recorded each of its three versions, flagged SSH open to the internet within 88 seconds and cleared it once it was closed, and kept the whole history, for about two cents. GuardDuty and Security Hub refused to start on this account, and that refusal is worth recognizing in its own right. Next, Lesson 36 is about the level above a single account, organizations and service control policies, the kind of policy that just said no.
Check yourself
Which service would notice an instance's credentials being used from outside AWS?
What is a configuration item?
SSH was opened at 16:09:35 and flagged at 16:11:03. Where did most of that time go?
Why did the lab record only security groups?
What stops Config's charges?
An AccessDenied says 'explicit deny in a service control policy'. What fixes it?
What does Security Hub's ASFF give you?
Key terms
- GuardDuty: a threat detection service that reads CloudTrail, VPC flow logs and DNS logs.
- Finding: a report of a possible problem, from GuardDuty, Config, Security Hub or others.
- Sample finding: a fake finding GuardDuty makes on request, for testing.
- Config: a service that records resources' settings and changes, and checks them against rules.
- Configuration recorder: Config's setting for which resource types to record, and how often.
- Configuration item: one snapshot of one resource at one moment.
- Delivery channel: where Config writes its snapshot and history files.
- Config rule: a check that marks resources compliant or non-compliant; managed rules are AWS's ready-made ones.
- Remediation: an automatic fix Config can run for a non-compliant resource.
- Security Hub CSPM: the service that gathers findings and runs best-practice checks; the new Security Hub builds on it.
- ASFF (AWS Security Finding Format): Security Hub's common format for findings.
- Service control policy (SCP): a policy above an account that limits what anyone in it can do.
Go deeper
- Earlier lessons: security groups for the rule being checked, Systems Manager for the Automation documents remediation uses, and CloudTrail, which GuardDuty reads.
- AWS: How AWS Config works (opens in a new tab), and the restricted-ssh rule (opens in a new tab).
- AWS: GuardDuty finding types (opens in a new tab), and Security Hub CSPM standards (opens in a new tab).
- AWS: Config pricing (opens in a new tab), GuardDuty pricing (opens in a new tab), and Security Hub CSPM pricing (opens in a new tab).
- Try: run
configandbreakagain, but open port 3389 instead of 22 in the script. Doesrestricted-sshcare? Then rundelete.