Security and Compliance · Topic 4 of 6

Automated Security Controls

Automate preventive, detective and corrective security controls with SCPs, CloudFormation Guard and Hooks, Config packs, Firewall Manager and patching.

  • 5 min
In a nutshell
  • Preventive, detective and corrective controls work together.
  • SCPs block actions; they do not grant, and they do not apply to the management account.
  • Guard checks templates in the pipeline; Hooks check at deploy time in the account.

What it is

A security control is a rule that keeps resources in a safe state. At scale, controls must be automated and applied by default, because manual review cannot keep up with hundreds of accounts and thousands of deployments.

Controls fall into three groups. Preventive controls stop a bad action, detective controls notice a bad state, and corrective controls fix it. A strong design uses all three at different points.

PreventSCP, Hooks, GuardDetectConfig rules, findingsCorrectauto remediationEvidencereports and audit

How it works

Preventive controls

ControlWhere it acts
Service control policyBlocks API actions in member accounts regardless of IAM
Permission boundaryCaps roles that teams create
S3 Block Public AccessAccount or bucket setting that blocks public access
Control Tower preventive controlsManaged SCPs for common rules
CloudFormation HooksCheck resource properties before creation and fail the deployment
CloudFormation GuardPolicy as code checks on templates in the pipeline
Service CatalogOffers only approved, pre hardened products

An SCP can force a secure setting. This one denies launching instances that do not require IMDSv2, the token based version of the instance metadata service.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "RequireImdsV2",
    "Effect": "Deny",
    "Action": "ec2:RunInstances",
    "Resource": "arn:aws:ec2:*:*:instance/*",
    "Condition": {"StringNotEquals": {"ec2:MetadataHttpTokens": "required"}}
  }]
}

Other typical SCPs deny leaving the organization, deny disabling CloudTrail, GuardDuty or Config, deny use of unapproved Regions, and deny actions by the root user.

Policy as code in the pipeline

CloudFormation Guard is a rule language that checks structured data, such as templates, before deployment. Put it in a CodeBuild step so a noncompliant template fails the pipeline.

let buckets = Resources.*[ Type == 'AWS::S3::Bucket' ]
rule s3_encrypted when %buckets !empty {
    %buckets.Properties.BucketEncryption exists
}
cfn-guard validate -d template.yaml -r rules.guard

The earlier check catches a problem in a pull request. A CloudFormation Hook acts at deploy time inside the account, so it also catches templates that skipped the pipeline.

Detective controls with AWS Config

Config rules evaluate the state of resources. Deploy them as conformance packs, which are collections of rules and remediations in one template, and as organization conformance packs, so every account in an OU receives them.

aws configservice put-organization-conformance-pack \
  --organization-conformance-pack-name baseline \
  --template-s3-uri s3://my-config-templates/baseline.yaml \
  --delivery-s3-bucket awsconfigconforms-central

Pack rules evaluate encryption, public access, logging, tagging, and open ports. Findings flow to AWS Security Hub and to EventBridge for action.

Corrective controls

Attach automatic remediation to a Config rule, or run an EventBridge rule that calls Systems Manager Automation. Fix the cause too: update the template or module that created the bad resource.

Network and edge controls at scale

AWS Firewall Manager applies security policies to every account in an organization from one administrator account. It requires Organizations and AWS Config.

Policy typeProtects
AWS WAF rulesWeb applications behind load balancers, CloudFront and API Gateway
AWS Shield AdvancedDDoS protection for chosen resources
Security groupsCommon baselines, audit and cleanup of unused or redundant groups
AWS Network FirewallInspection at VPC level
Route 53 Resolver DNS FirewallBlocking known bad domains

New accounts and new resources that match a policy receive it automatically, which is the main reason to choose Firewall Manager over manual WAF setup.

Vulnerability and patch automation

  • Patch Manager applies patch baselines to tagged instances in maintenance windows, and reports compliance.
  • Amazon Inspector scans EC2 instances, container images in ECR and Lambda functions for known vulnerabilities continuously.
  • EC2 Image Builder rebuilds hardened AMIs on a schedule, so replacing instances beats patching them in place.
  • Immutable infrastructure means you replace instances through the pipeline and avoid manual changes, which reduces drift.

Securing the pipeline itself

Give pipeline roles least privilege, require approval for production, scan code, dependencies and images, keep secrets out of source control, and log all pipeline activity. A pipeline with broad admin rights is an attack path into every account it deploys to.

What to remember for the exam

  • Preventive, detective and corrective controls work together.
  • SCPs block actions; they do not grant, and they do not apply to the management account.
  • Guard checks templates in the pipeline; Hooks check at deploy time in the account.
  • Conformance packs deploy rule sets; organization packs reach every account.
  • Config rules plus SSM Automation provide detect and fix.
  • Firewall Manager applies WAF, Shield Advanced, security group and firewall policies across an organization automatically.
  • Patch Manager patches by baseline and window; Inspector finds vulnerabilities.
  • Replace instances from hardened AMIs rather than patching them by hand.
  • IMDSv2 can be enforced with the ec2:MetadataHttpTokens condition.
Exam tip

When a question asks for a guardrail that no administrator in a member account can bypass, think SCP, not an IAM policy.

Common mistakes

Relying on detection alone. A Config rule finds an open bucket after it exists, while a preventive control stops it.

Deploying SCPs to the root of the organization without testing. A mistake can break every account at once.

Using Firewall Manager without Config. It depends on Config to see resources.

Fixing resources but not templates. The next deployment recreates the problem.

Watch out

Test any SCP in a sandbox OU first, because a broad deny can block your own pipelines and recovery roles.

Check yourself

  • Which control stops a noncompliant resource at creation time inside the account?

    A CloudFormation Hook, which can fail the operation before the resource is created.

  • How do you apply the same WAF rules to every account automatically?

    Use an AWS Firewall Manager policy from a Firewall Manager administrator account.

  • Why rebuild AMIs with Image Builder instead of patching by hand?

    Rebuilt, tested images are consistent and replaceable, which avoids drift and manual changes.

Topic 4 of 6 in Security and Compliance

Test yourself on Security and Compliance

The full AWS DOP-C02 question bank has 844 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.