devHọc Dev

Week 3 - Day 2: WAF & Shield, GuardDuty/Inspector/Macie and Cognito

Week 3 – Day 2

This lesson combines 3 topics: AWS WAF and Shield, GuardDuty, Inspector, Macie, Amazon Cognito.

Learning Objectives

  • Understand WAF: filtering HTTP requests at Layer 7
  • Distinguish Shield Standard vs Shield Advanced
  • Master Managed Rule Groups and Custom Rules
  • Apply rate limiting and geo blocking
  • Distinguish the 3 security detection services
  • Understand GuardDuty threat detection
  • Master Inspector vulnerability assessment
  • Apply Macie for PII detection
  • Distinguish User Pool and Identity Pool
  • Understand the authentication flow (JWT tokens)
  • Master federation with social providers
  • Apply Cognito to mobile/web apps

Part 1: AWS WAF and Shield

1. AWS WAF (Web Application Firewall)

Definition

WAF = Layer 7 firewall that protects web apps from common exploits (SQL injection, XSS, etc.).

Deploy targets

  • CloudFront distribution (global)
  • ALB (regional)
  • API Gateway (regional)
  • AppSync (regional)
  • App Runner
  • Cognito User Pool
  • Verified Access

Key concepts

  • Web ACL (Access Control List): container of rules
  • Rules: define conditions to evaluate
  • Rule Groups: collection of rules
  • Actions: ALLOW, BLOCK, COUNT (monitor), CAPTCHA, Challenge

2. WAF Rules

2 types

IP-based / regex-based simple rules
  • Block by IP, country, header, query string, body
Rate-based rules
  • Block when single IP exceeds rate threshold (e.g., 1000 req/5 min)
  • Use case: rate limiting, brute-force protection

Match conditions

  • IP set: list of IPs/CIDRs
  • Geographic match: country code
  • String match: header, body, URI contains
  • Regex match: pattern matching
  • Size constraint: body length
  • SQL injection match: detect SQLi patterns
  • XSS match: detect XSS patterns

Example rule

Rule: BlockLargePayloads
Condition: Body size > 8 KB
Action: BLOCK
Rule: RateLimitByIP
Condition: Requests from single IP > 1000 in 5 min
Action: BLOCK (TTL 1 hour)

3. AWS Managed Rule Groups

Free tier (AWS Managed Rules)

  • AWSManagedRulesCommonRuleSet: OWASP Top 10
  • AWSManagedRulesKnownBadInputsRuleSet: known bad patterns
  • AWSManagedRulesSQLiRuleSet: SQL injection
  • AWSManagedRulesLinuxRuleSet: Linux-specific (LFI, etc.)
  • AWSManagedRulesUnixRuleSet
  • AWSManagedRulesWindowsRuleSet
  • AWSManagedRulesAdminProtectionRuleSet: protect admin paths
  • AWSManagedRulesAmazonIpReputationList: bad IPs list
  • Third-party rules (Fortinet, F5, Imperva, Trend Micro)
  • $/month subscription

4. WAF Workflow

Internet→CloudFront/ALB→WAF(evaluaterules)├──ALLOW→Passtoapp├──BLOCK→Return403├──COUNT→Log,passtoapp├──CAPTCHA→ShowCAPTCHAtouser└──Challenge→Browserchallenge(silent)

Rule evaluation

  • Rules evaluated in order of priority
  • First matching action wins
  • Default action (no rules match): ALLOW or BLOCK (configurable)

5. Common WAF Use Cases

Block SQL injection

Rule: SQLiProtection
Type: Managed Rule Group AWSManagedRulesSQLiRuleSet
Action: BLOCK

Geo blocking

Rule: BlockChinaRussia
Condition: Country IN [CN, RU]
Action: BLOCK

Rate limit per IP

Rule: RateLimit
Condition: 1000 req / 5 min from single IP
Action: BLOCK

Allow only specific IPs (admin endpoint)

Rule: AdminAccess
Condition: URI = /admin AND IP NOT IN allowlist
Action: BLOCK

Block bots

  • AWS Managed Rule: Bot Control (paid)
  • Distinguish good bots (Googlebot) from bad bots (scrapers)

6. WAF Pricing

  • $5/month per Web ACL
  • $1/month per rule
  • $0.60/million requests
  • Bot Control: +$10/M requests (advanced)

Cost optimization

  • Combine rules into rule groups
  • Use AWS Managed Rule Groups (free included rules)

7. AWS Shield

Shield Standard

  • Free, automatic for all AWS customers
  • Protects against most common DDoS attacks (L3, L4):
    • SYN/UDP floods
    • Reflection attacks (NTP, DNS amplification)
  • Always-on for CloudFront, Route 53
  • Suitable for basic protection

Shield Advanced

  • Paid: $3,000/month + data transfer fees
  • Protects:
    • CloudFront, Route 53, Global Accelerator, ALB, NLB, EIP (EC2)
  • Features:
    • Enhanced DDoS protection (Layer 3, 4, 7)
    • 24/7 DDoS Response Team (DRT) access
    • Cost protection: refund for scaling charges during attack
    • Real-time attack visibility (CloudWatch metrics)
    • WAF included (no separate cost)
    • Application Layer (L7) protection with WAF auto-rule
    • Health check-based detection

When to use Shield Advanced

  • Mission-critical apps
  • History of DDoS attacks
  • Regulatory requires DDoS protection
  • Want financial protection from scaling costs

8. AWS Firewall Manager

Definition

Firewall Manager = centrally manage WAF, Shield, Security Groups, Network Firewall across multiple accounts (Organizations).

Characteristics

  • Apply policies to all accounts / OUs in organization
  • Auto-protect new resources created
  • Compliance reporting
  • Cost: $/policy/region/month

Use case

  • Multi-account AWS Organization
  • Enforce baseline security across all accounts
  • Compliance (PCI, HIPAA across org)

9. AWS Network Firewall

Definition

Network Firewall = managed network firewall at the VPC level (L3-7), stateful inspection.

Characteristics

  • Filter ingress/egress traffic at subnet/VPC level
  • Supports Suricata-compatible rules (open source IDS/IPS)
  • Stateful inspection
  • Deep packet inspection
  • Integration with Firewall Manager

Pricing

  • ~$0.395/hour per firewall endpoint
  • $0.065/GB data processed

Use case

  • Centralized traffic inspection for VPCs
  • Block egress to malicious domains
  • Compliance requires network-level firewall

10. Security Service Layers

┌─────────────────────────────────────────┐│Internet│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│AWSShieldStandard(always-on,free)││├──DDoSL3/L4protection││└──Edgelocations│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│CloudFront+WAF││├──L7filtering(SQLi,XSS,rate)││└──Geoblocking│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│ShieldAdvanced(paid)││└──EnhancedDDoS+DRTsupport│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│ALB+SecurityGroups+NACLs│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│Application(EC2/Lambda/ECS)│└─────────────────────────────────────────┘

11. WAF Best Practices

  1. Start with COUNT mode to evaluate rules without blocking
  2. Use AWS Managed Rule Groups for baseline
  3. Add rate-based rules for brute-force protection
  4. Geo-block unnecessary countries
  5. Monitor with CloudWatch metrics (BlockedRequests, AllowedRequests)
  6. Centrally manage via Firewall Manager if multi-account
  7. Enable logging to Kinesis Firehose → S3 for analysis

12. Common Patterns

Pattern 1: E-commerce site

  • CloudFront + WAF (managed rules + rate limit)
  • Shield Standard (free)
  • ALB → EC2

Pattern 2: API protection

  • CloudFront + API Gateway + WAF
  • Rate limit per API key
  • IP allowlist for partners

Pattern 3: High-value target (gov, financial)

  • CloudFront + WAF + Shield Advanced
  • DRT on-call
  • 24/7 monitoring

Part 2: GuardDuty, Inspector, Macie

1. AWS GuardDuty

Definition

GuardDuty = intelligent threat detection that uses ML to detect malicious activity and unauthorized behavior.

Data sources analyzed

  • VPC Flow Logs (network traffic)
  • CloudTrail event logs (API calls)
  • CloudTrail S3 data events (object access)
  • DNS logs (Route 53 Resolver queries)
  • EKS audit logs
  • EKS runtime monitoring
  • RDS login events
  • Lambda network activity
  • S3 protection
  • EBS volume scanning (Malware Protection)

Findings categories

  • Reconnaissance: port scanning, IAM enumeration
  • Instance compromise: bitcoin mining, malware C&C
  • Account compromise: stolen credentials usage
  • Bucket compromise: S3 unusual access patterns
  • Cryptocurrency mining

Severity levels

  • Critical (9.0-10.0): added in 2024 — confirmed compromise, act immediately
  • High (7.0-8.9): immediate action needed
  • Medium (4.0-6.9): investigate
  • Low (1.0-3.9): informational

Integration

  • EventBridge: trigger Lambda for auto-remediation
  • Security Hub: aggregate findings
  • Detective: investigate root cause

Pricing

  • Per million CloudTrail events analyzed
  • Per GB VPC Flow Logs / DNS logs
  • Per GB scanned (Malware Protection)
  • 30-day free trial

Use case

  • Continuous threat monitoring
  • Detect compromised credentials
  • Detect crypto mining on EC2
  • Alert on unusual API calls

Multi-account

  • Delegate administrator account (recommended)
  • Auto-enable for new member accounts
  • Aggregate findings centrally

2. AWS Inspector

Definition

Inspector = automated vulnerability assessment for AWS workloads.

Targets scanned

  • EC2 instances (OS + app vulnerabilities)
  • ECR container images
  • Lambda functions (code + dependencies)

Vulnerability sources

  • CVE database (Common Vulnerabilities and Exposures)
  • AWS-curated rules
  • Network reachability (EC2 internet exposure)

Findings

  • Severity: Critical, High, Medium, Low
  • CVSS score (Common Vulnerability Scoring System)
  • Suggested remediation
  • Affected packages

Inspector v2 (current)

  • Replaced Inspector Classic in 2022
  • Continuous, automated scanning
  • Integration with the Systems Manager Agent

Pricing

  • Per instance scanned/month (~$1-2)
  • Per ECR image scan
  • Per Lambda function

Use case

  • Compliance scanning (PCI DSS, HIPAA)
  • Detect outdated OS, libraries
  • Container image vulnerabilities before deploy

Multi-account

  • Delegated administrator
  • Auto-enroll new accounts

3. AWS Macie

Definition

Macie = ML-based data security service to discover, classify, and protect sensitive data in S3.

Detects

  • PII (Personally Identifiable Information):
    • Names, addresses, phone numbers
    • Email addresses
    • SSN, passport numbers, driver's license
  • Credit card numbers
  • Healthcare data (HIPAA-related)
  • AWS access keys (exposed in S3!)
  • Custom data identifiers (regex)

Workflow

  1. Enable Macie on account/organization
  2. Macie scans S3 buckets (sampling or full)
  3. Findings: which buckets contain sensitive data
  4. Alert + recommendation

Findings types

  • Policy findings:
    • Bucket publicly accessible
    • Bucket not encrypted
    • Bucket replicates externally
  • Sensitive Data findings:
    • PII found in object X
    • Credit card in object Y

Pricing

  • Bucket evaluation: $0.10 per S3 bucket/month
  • Sensitive data discovery: $1 per GB analyzed

Use case

  • GDPR compliance (find personal data)
  • PCI compliance (find credit cards)
  • Audit data storage
  • Prevent data leaks

4. Comparing the 3 services

GuardDutyInspectorMacie
WhatThreat detectionVulnerability assessmentSensitive data detection
WhereAccount activity (logs)EC2, ECR, LambdaS3 buckets
HowML on log streamsCVE scanningML on S3 objects
FindingsActive attacks, anomaliesVulnerabilities (CVEs)PII, credit cards
Use caseReal-time threat alertCompliance vulnerability scanData privacy compliance

When to use what

  • GuardDuty: Real-time threat detection (always-on monitoring)
  • Inspector: Periodic vulnerability scan (compliance, DevSecOps)
  • Macie: Data discovery (compliance, audit)

Best practice: enable all 3 + Security Hub to aggregate.

5. AWS Security Hub

Definition

Security Hub = central dashboard for security findings from AWS services + 3rd party.

Aggregates findings from

  • GuardDuty
  • Inspector
  • Macie
  • IAM Access Analyzer
  • AWS Config
  • AWS Firewall Manager
  • 3rd party (Tenable, Qualys, Splunk)

Features

  • Compliance standards:
    • AWS Foundational Security Best Practices
    • CIS AWS Benchmark
    • PCI DSS
    • NIST CSF
  • Security score (0-100%)
  • Multi-account aggregation (via Organizations)
  • Automated response via EventBridge

Pricing

  • Per finding ingested + per check
  • Free tier: 30 days

Use case

  • Single pane of glass for security
  • Continuous compliance monitoring
  • Centralized response workflow

6. AWS Detective

Definition

Detective = investigate the root cause of security findings (GuardDuty, etc.).

Characteristics

  • Auto-collects logs (VPC Flow Logs, CloudTrail, GuardDuty findings)
  • Builds interactive graph of resources, IPs, actions
  • "What happened?" investigation tool
  • Goes beyond just alerting → understanding

Use case

  • Investigate GuardDuty finding
  • Forensic analysis after incident
  • Understand attacker movement

Pricing

  • Per GB ingested (~$2-3/GB)

7. AWS Audit Manager

Definition

Audit Manager = automate audit evidence collection for compliance.

Frameworks

  • PCI DSS, HIPAA, SOC 2, GDPR, NIST
  • Custom frameworks

Workflow

  1. Select framework (e.g., PCI DSS)
  2. Audit Manager identifies controls
  3. Continuous evidence collection from CloudTrail, Config, etc.
  4. Generate audit-ready reports

Use case

  • Annual SOC 2 audit (save manual effort)
  • Continuous compliance posture

8. AWS Config

Definition

Config = track resource configuration changes over time.

Characteristics

  • Configuration snapshots of resources
  • History (timeline of changes)
  • Compliance rules: check if resource configured correctly
  • Integration with Security Hub, Audit Manager

Use case

  • "What changed and when?"
  • Compliance check (e.g., "all S3 buckets must be encrypted")
  • Drift detection

Pricing

  • $0.003 per configuration item recorded
  • $0.001 per evaluation

9. AWS Security Suite (Big picture)

┌───────────────Prevention──────────────┐│IAM,KMS,VPC,SG,NACL,WAF,Shield│└─────────────────────────────────────────┘│┌───────────────────Detection─────────────┐│GuardDuty(threats),Inspector(vulns),││Macie(data),AccessAnalyzer,Config│└───────────────────────────────────────────┘│┌───────────────────Response──────────────┐│SecurityHub(centralize),EventBridge││(automate),Detective(investigate),││AuditManager(compliancereports)│└───────────────────────────────────────────┘

10. Multi-account Security Strategy

Best practice setup

  1. Dedicated Security Account (AWS Organizations)
  2. Enable across organization:
    • GuardDuty (delegated admin)
    • Inspector (delegated admin)
    • Macie (delegated admin)
    • Security Hub (delegated admin)
    • Config (organization-wide)
  3. Aggregate findings in Security Account
  4. Automated remediation via EventBridge + Lambda
  5. Quarterly reviews + Audit Manager reports

11. Common Patterns

Pattern 1: New AWS account baseline

  1. Enable GuardDuty (free trial 30 days)
  2. Enable Security Hub
  3. Enable Access Analyzer
  4. Enable IAM Identity Center (replace IAM users)

Pattern 2: Detect compromised credentials

  • GuardDuty finding: UnauthorizedAccess:IAMUser/...
  • EventBridge rule → Lambda → auto-revoke credentials

Pattern 3: S3 data privacy

  • Macie scans S3 buckets weekly
  • Alert if PII found in non-classified bucket
  • Auto-tag bucket as "sensitive"

Pattern 4: Container vulnerability scanning

  • Inspector v2 scans ECR images on push
  • Block deploy if Critical findings (CI/CD gate)

Part 3: Amazon Cognito

1. Cognito Overview

Amazon Cognito = managed user identity service for web + mobile apps.

2 components

ComponentPurpose
User PoolUser directory: signup, signin, password management
Identity Pool (Federated Identities)Exchange identity → AWS temp credentials

Use cases

  • Mobile app authentication
  • Web app SSO
  • API authentication
  • Backend user management without building auth

Pricing

  • User Pool: since 12/2024 priced by Lite / Essentials / Plus tier — Essentials ~$0.015/MAU, free tier 10K MAU (the Lite tier with 50K free MAU only remains for user pools created before 12/2024; older materials often say "$0.0055/MAU, free 50K")
  • Identity Pool: free

2. User Pool

Characteristics

  • User directory (database of users)
  • Authentication: username/password, email, phone
  • MFA: SMS, TOTP, authenticator app
  • Password policy: complexity, expiration
  • Self-service: signup, password reset, email/phone verification
  • Federation: SAML, OIDC (Google, Facebook, Apple, Amazon, SAML IdPs)
  • Returns JWT tokens (ID token, Access token, Refresh token)

Token types

TokenContainsUse case
ID TokenUser attributes (email, name, sub)Identity verification
Access TokenScopes, user infoAPI authorization
Refresh Token(Opaque)Get new ID/Access tokens

Token lifetime

  • ID Token: 1 hour (default)
  • Access Token: 1 hour
  • Refresh Token: 30 days (default, configurable 60 min - 10 years)

Customization

  • Lambda triggers at key events:
    • Pre Sign-up (validation)
    • Post Confirmation
    • Pre Authentication
    • Post Authentication
    • Custom Message (email/SMS content)
    • Pre Token Generation (add custom claims)

App Client

  • An app accessing the User Pool has an app client ID
  • Configure: which OAuth flows, which IdPs allowed, callback URLs

3. User Pool Authentication Flow

Standard flow

1. User → App: enters username + password
2. App → User Pool: InitiateAuth API
3. User Pool: verify creds
4. User Pool → App: ID Token + Access Token + Refresh Token (JWT)
5. App → API Gateway: API call with Access Token in Authorization header
6. API Gateway → User Pool: verify token signature
7. API Gateway → Lambda backend

Federated flow (Google sign-in)

1. User → App: "Sign in with Google"
2. App → Google: OAuth
3. Google → User Pool: SAML/OIDC token
4. User Pool: provision user (if first time)
5. User Pool → App: JWT tokens

4. Identity Pool (Federated Identities)

Characteristics

  • Provide temporary AWS credentials to users
  • For users authenticated via:
    • Cognito User Pools
    • Social IdPs (Google, Facebook, Apple, Amazon)
    • SAML / OIDC
    • Developer-authenticated
  • 2 roles:
    • Authenticated role
    • Unauthenticated (guest) role

Workflow

1. User authenticates with IdP (User Pool, Google, ...)
2. IdP returns token
3. App calls Identity Pool: GetCredentialsForIdentity
4. Identity Pool returns AWS STS temp credentials
5. App uses credentials to access AWS services (S3, DynamoDB, API Gateway)

Use case: Mobile photo app

  • User uploads photo directly to S3 (instead of through backend)
  • Identity Pool gives temp credentials scoped to user's S3 prefix
  • App uses creds for S3 upload

Policy scoping

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["s3:PutObject", "s3:GetObject"],
    "Resource": "arn:aws:s3:::my-bucket/users/${cognito-identity.amazonaws.com:sub}/*"
  }]
}

→ Each user can only access their own S3 prefix.

5. User Pool vs Identity Pool

User PoolIdentity Pool
PurposeUser management + authAWS credentials
ReturnsJWT tokensAWS temp credentials
ForApp authenticationDirect AWS access
IdPOptional (can federate)Required (User Pool, social, SAML)
Combined useOften combined: User Pool → Identity Pool → AWS

Common pattern

User → User Pool (sign in) → JWT
     → Identity Pool (exchange JWT) → AWS temp creds
     → S3 / DynamoDB / API Gateway

6. Cognito with API Gateway

Cognito Authorizer

  • API Gateway has a Cognito Authorizer type
  • Validates JWT token from User Pool
  • No backend code needed for auth

Setup

APIGatewayendpoint:GET/users/me└──Authorizer:CognitoUserPoolauthorizer├──Tokensource:Authorizationheader└──ValidatesagainstUserPoolID

Lambda Authorizer (alternative)

  • Custom Lambda function validates token
  • More flexible (custom logic)
  • Use when need extra validation beyond Cognito

7. Cognito Federation Examples

Sign in with Google

  1. Setup Google OAuth credentials
  2. Add Google as IdP in User Pool
  3. Configure App Client allowed IdPs: Google
  4. User clicks "Sign in with Google" → redirects to Google → returns to app

SAML federation (corporate AD)

  1. Setup SAML IdP in User Pool (Okta, Azure AD, ADFS)
  2. Configure attribute mapping (email, name)
  3. Users sign in with corporate creds

Apple Sign-In

  1. Apple Developer account required
  2. Add Apple as IdP
  3. Handle Apple-specific tokens

8. Cognito Sync (Deprecated → use AppSync)

  • Sync user data across devices
  • Deprecated — use AWS AppSync + DataStore for new apps

9. Hosted UI

Definition

Hosted UI = AWS-provided customizable login/signup UI.

Characteristics

  • Pre-built sign-in, sign-up, forgot password forms
  • Customizable: logo, colors, CSS
  • OAuth 2.0 flows: Authorization Code, Implicit, PKCE
  • Custom domain support

Use case

  • Don't want to build auth UI from scratch
  • Quick prototype
  • Standard auth flows

10. Advanced Security Features (Plus tier)

Risk-based adaptive authentication

  • Detect risky sign-ins (new device, unusual location)
  • Require MFA or block

Compromised credentials check

  • Check against known compromised passwords
  • Force user to change password

Pricing

  • Plus tier: more expensive per MAU

11. Cognito vs IAM Identity Center vs IAM Users

CognitoIAM Identity CenterIAM Users
ForApp end-usersAWS workforce usersLegacy AWS access
ScaleMillions of users100s-1000s of employees< 5000/account
SSOPer appMulti-account AWSNo
Use caseMobile/web app usersInternal team accessing AWSLegacy or service accounts

Decision

  • App users: Cognito
  • Employees accessing AWS Console: IAM Identity Center
  • Service accounts: IAM Roles (not users)

12. Common Patterns

Pattern 1: Mobile photo sharing app

User → Cognito User Pool (email/password)
     → Cognito Identity Pool (AWS creds scoped to user)
     → S3 upload + DynamoDB metadata

Pattern 2: SaaS multi-tenant app

Users → User Pool per tenant
      → API Gateway with Cognito Authorizer
      → Lambda → DynamoDB (filter by user ID from JWT)

Pattern 3: Enterprise app with SAML

Employee → User Pool with SAML federation (Okta)
        → JWT
        → App

Pattern 4: Public app + admin portal

Public users → User Pool A
Admins → User Pool B with MFA required
Different API Gateway authorizers

Review Questions

  1. Which targets can WAF be deployed on?

    Show answer

    WAF (Web Application Firewall) can be deployed on: CloudFront, ALB (Application Load Balancer), API Gateway, AppSync GraphQL API, Cognito User Pool. It cannot be deployed on NLB (Layer 4) or CLB. WAF operates at Layer 7 — it inspects HTTP/HTTPS requests. WAF for CloudFront is global; WAF for ALB/API GW is regional.

  2. Is Shield Standard free? Which layers does it protect?

    Show answer

    Free and automatic for all AWS customers. It protects at Layer 3 and Layer 4 (network + transport) — volumetric attacks (UDP floods, SYN floods, reflection attacks). It protects all Edge Locations (CloudFront, Route 53, Global Accelerator). It does not protect Layer 7 (HTTP floods, application-level DDoS) — you need WAF and Shield Advanced for that.

  3. How much does Shield Advanced cost per month?

    Show answer

    $3,000/month per organization (not per account). It includes: 24/7 DDoS Response Team (DRT) support, financial reimbursement for DDoS-caused AWS cost spikes, automatic application layer attack detection + response (WAF rules auto-created), and protection for EC2, ELB, CloudFront, Route 53, Global Accelerator. Reasonable for enterprises with business-critical applications.

  4. What is a rate-based rule in WAF used for?

    Show answer

    A rate-based rule blocks or challenges requests from an IP when it exceeds a request-rate threshold within 5 minutes. Example: block an IP that sends > 1000 requests/5 minutes. Used to prevent brute-force attacks, credential stuffing, scraping, Layer 7 DDoS. You can group by IP, forwarded IP, or any aggregation key. The rule automatically unblocks the IP when the rate drops below the threshold.

  5. How does AWS Firewall Manager differ from the WAF console?

    Show answer

    Firewall Manager is centralized management for multiple accounts in AWS Organizations — it deploys and enforces WAF rules, Shield Advanced protections, Security Groups, Network Firewall policies across all accounts from one place. The WAF console only manages WAF in a single account. Firewall Manager suits enterprises with many accounts that need consistent security policies — it automatically applies rules to new accounts/resources.

  6. Which data sources does GuardDuty analyze?

    Show answer

    GuardDuty analyzes: VPC Flow Logs, DNS Logs, CloudTrail Events, CloudTrail S3 Data Events (optional), EKS audit logs, Lambda network activity, RDS login activity. It uses ML to detect anomalies: unusual API calls, compromised credentials, cryptocurrency mining, port scanning, known malicious IPs. You don't need to enable every data source in the account — GuardDuty pulls them from AWS itself.

  7. Which resource types can Inspector scan?

    Show answer

    Amazon Inspector scans: EC2 instances (OS vulnerabilities, network exposure), ECR container images (layer vulnerabilities), Lambda functions (package vulnerabilities, code analysis). Automated continuous scanning — no manual schedule needed. It generates findings with severity, CVE details, and remediation recommendations. Unlike the 2016 classic Inspector, the new generation (Inspector v2) integrates with AWS Organizations.

  8. What does Macie specialize in detecting in S3?

    Show answer

    Amazon Macie specializes in detecting sensitive data in S3 buckets using ML: PII (Personally Identifiable Information), financial data (credit cards, bank accounts), credentials, medical records. It also detects misconfigured buckets (public access, unencrypted). Macie creates findings when it detects sensitive data exposure. A good fit for GDPR, HIPAA, PCI DSS compliance — audit S3 bucket contents automatically.

  9. How does Security Hub differ from Detective?

    Show answer

    Security Hub: aggregates findings from many services (GuardDuty, Inspector, Macie, IAM Access Analyzer, Config...) and third-party tools into one dashboard. Normalized to the ASFF format, automation via EventBridge. Amazon Detective: an investigation tool — when there is a finding/incident, use Detective to visualize, analyze the root cause, and view the activity timeline. Detective helps you "investigate" after detection; Security Hub helps you "aggregate and prioritize".

  10. When do you need Shield Advanced instead of Shield Standard?

Show answer

You need Shield Advanced when: (1) Applications are business-critical with high revenue risk from downtime (e-commerce, financial), (2) You need 24/7 DRT support to respond to and mitigate complex DDoS, (3) You need cost protection — reimbursement of AWS scaling costs during a DDoS (EC2, NAT GW, data transfer), (4) You need Layer 7 auto-mitigation for sophisticated HTTP-based attacks. $3,000/month per org — justified for enterprises.

  1. How do User Pool and Identity Pool differ?
Show answer

User Pool: an authentication service — manages the user directory (sign-up, sign-in, password reset, MFA, social federation). Returns JWT tokens (ID, Access, Refresh). Does not issue AWS credentials. Identity Pool: an authorization service — exchanges an identity (JWT from User Pool, Google, Facebook, SAML) for temporary AWS credentials (via STS) to call AWS APIs directly. Often both are used: User Pool authenticates → Identity Pool issues AWS credentials.

  1. What types of JWT tokens does a User Pool return?
Show answer

3 types: (1) ID Token — contains user attributes (email, phone, custom claims) — used to verify identity and pass user info to the backend, (2) Access Token — authorizes API calls to the User Pool (not AWS APIs) — contains scopes and groups, (3) Refresh Token — long lifetime (default 30 days) — used to get new ID/Access tokens when they expire. The refresh token is never sent to an API — it is only used with Cognito.

  1. When do you use an Identity Pool?
Show answer

When you need a mobile/web app to call AWS APIs directly (S3 upload, DynamoDB query, Kinesis...) with temporary credentials. Example: a photo app needs to upload straight to the user's S3 bucket — not through a backend server. The Identity Pool issues IAM role credentials with limited-scope permissions. It is also used for unauthenticated (guest) access — allowing anonymous users to access AWS resources with limited permissions.

  1. What does a Cognito Authorizer in API Gateway validate?
Show answer

The Cognito Authorizer validates the JWT Access Token from the User Pool. API Gateway checks: (1) The token is still valid (not expired), (2) The signature is valid (signed by the User Pool), (3) The token scope matches the required scopes (if configured). No custom validation code is needed — API Gateway handles it entirely. If the token is invalid → 401 Unauthorized. You don't need a Lambda Authorizer for a simple authentication flow.

  1. Does Cognito User Pool support MFA?
Show answer

Yes — Cognito User Pool supports MFA: TOTP (Time-based One-Time Password — Google Authenticator, Authy) and SMS (via Amazon SNS). MFA can be configured as: Off, Optional (user chooses), or Required (mandatory). Since 2023, Cognito also supports email OTP and passkeys (WebAuthn). MFA is configured at the User Pool level, not per user.

Hands-on Exercises

Part 1: AWS WAF and Shield

  • Create a Web ACL with the managed rule AWSManagedRulesCommonRuleSet, attach it to an ALB
  • Add custom rule: rate limit 100 req/5min per IP
  • Add geo block: deny country code XX
  • Test with a simulated SQL injection request (should be blocked)
  • Set up a CloudWatch alarm when BlockedRequests spikes
  • (Optional) Test with Firewall Manager (requires an Organization)

Part 2: GuardDuty, Inspector, Macie

  • Enable GuardDuty (30 day free trial), wait 24h and review findings
  • Enable Inspector v2 for EC2 instances
  • Enable Macie, scan 1 S3 bucket containing sample PII
  • Enable Security Hub, observe aggregated findings
  • Set up an EventBridge rule: GuardDuty High severity → SNS email

Part 3: Amazon Cognito

  • Create a Cognito User Pool, configure password policy + MFA
  • Create an App Client, test sign-up + sign-in via Hosted UI
  • Set up an Identity Pool, get temp creds for a test user
  • Configure API Gateway with a Cognito Authorizer
  • Add Google as a federated IdP, test sign-in
  • Create a Post-Confirmation Lambda trigger: add user to DynamoDB

References


Next lesson →