Skip to main content

Application Layer: WAF, Shield, and API Security

The application layer protects your workloads from external threats that target your application logic. While network and identity controls prevent unauthorized access, application-layer security filters malicious traffic that arrives through legitimate channels, such as a SQL injection payload in a web form or a DDoS attack against your API.

AWS WAF​

AWS WAF (Web Application Firewall) inspects HTTP/HTTPS requests and blocks those that match rules you define. WAF attaches to CloudFront distributions, Application Load Balancers, API Gateway REST APIs, and AppSync GraphQL APIs.

Web ACLs and Rules​

A Web ACL is a collection of rules that WAF evaluates against each incoming request. Rules are evaluated in priority order, and the first matching rule determines the action (allow, block, or count).

Rule types:

Rule TypeExampleUse Case
Rate-basedBlock IPs exceeding 2,000 requests in 5 minutesDDoS mitigation, brute force protection
IP setBlock or allow specific IP rangesGeoblocking, allowlisting known partners
Regex pattern setMatch specific patterns in headers or bodyCustom signature detection
Managed rule groupsAWS Managed Rules, marketplace rulesBroad protection with minimal configuration

AWS Managed Rule Groups​

AWS provides free managed rule groups that cover common attack vectors:

Rule GroupWhat It Blocks
AWSManagedRulesCommonRuleSetOWASP Top 10 including XSS, SQLi, command injection
AWSManagedRulesKnownBadInputsRuleSetKnown bad request patterns (Log4j, etc.)
AWSManagedRulesSQLiRuleSetSQL injection patterns
AWSManagedRulesLinuxRuleSetLinux-specific exploits (path traversal, etc.)
AWSManagedRulesAmazonIpReputationListIPs identified as bots or threats
AWSManagedRulesBotControlRuleSetBot detection and management (paid)

Best practice: Start with the Common Rule Set and Known Bad Inputs in count mode. Review the logs for false positives before switching to block mode.

AWS Shield​

AWS Shield provides DDoS protection at two tiers:

Shield Standard vs Advanced​

FeatureShield StandardShield Advanced
CostFree (automatic)$3,000/month + data transfer
ProtectionLayer 3/4 (network/transport)Layer 3/4/7 (including application)
ResourcesAll AWS resourcesCloudFront, ALB, ELB, Route 53, Global Accelerator, EC2 EIPs
Response teamNone24/7 AWS Shield Response Team (SRT)
Cost protectionNoneDDoS cost protection (credits for scaling charges)
VisibilityBasicAdvanced metrics, attack forensics

When to use Shield Advanced: When your application is public-facing and a DDoS-related outage or cost spike would cause significant business impact. The $3,000/month subscription covers all resources in the account.

API Gateway Authorization Patterns​

API Gateway provides multiple mechanisms to authenticate and authorize API requests:

1. IAM Authorization​

Requests are signed with AWS Signature Version 4. The caller must have IAM permissions to invoke the API.

Best for: Service-to-service communication, internal APIs, and programmatic access where callers already have IAM credentials.

2. Cognito User Pool Authorizer​

API Gateway validates a JWT token issued by a Cognito User Pool. The token contains the user's identity and claims.

Best for: User-facing APIs where you manage user registration and authentication with Cognito.

3. Lambda Authorizer (Custom Authorizer)​

A Lambda function receives the request token or headers and returns an IAM policy that API Gateway uses to allow or deny the request.

Best for: Custom authentication logic, third-party identity providers, or when you need to validate tokens from a non-Cognito IdP.

Choosing an Authorization Pattern​

PatternAuthentication SourceCachingComplexity
IAMAWS SigV4 credentialsN/ALow
CognitoJWT from Cognito User PoolBuilt-inMedium
Lambda AuthorizerCustom (any token/header)Configurable (up to 1 hour)High

Secrets Manager vs Parameter Store​

Applications need credentials, API keys, and connection strings. Storing these in code or environment variables is a security risk. AWS provides two services for secret management:

FeatureSecrets ManagerParameter Store (Standard)
Automatic rotationBuilt-in rotation with LambdaNo built-in rotation
Cost$0.40/secret/month + API callsFree (standard tier)
Max size64 KB4 KB (standard) / 8 KB (advanced)
Cross-account accessSupported via resource policyNot supported (standard)
RDS integrationNative rotation for RDS, Redshift, DocumentDBManual
EncryptionAlways encrypted with KMSOptional encryption with KMS

When to use Secrets Manager: Database credentials, API keys, and any secret that benefits from automatic rotation. The cost is justified by the built-in rotation capability.

When to use Parameter Store: Configuration values, feature flags, and non-sensitive parameters. Use the SecureString type with KMS for sensitive values that do not need rotation.

Flashcards​

1 / 6
Question

What AWS resources can WAF be attached to?

Click to reveal
Answer

CloudFront distributions, Application Load Balancers, API Gateway REST APIs, and AppSync GraphQL APIs.