Application Security on AWS: ACM, CloudFront Signed URLs, WAF, Cognito Protection and Securing AI Applications
Defense in Depth for Apps
text
Users ─► Route 53 ─► CloudFront (TLS, caching, signed URLs) ─► AWS WAF (OWASP rules, rate limits, bot control)
─► ALB / API Gateway (auth, throttling) ─► app code (validation, least privilege role)
─► data stores (KMS encryption, private subnets, security groups)
TLS with AWS Certificate Manager (ACM)
- ACM issues free public certificates for use with CloudFront, ALB, NLB, API Gateway, AppSync and renews them automatically when validated by DNS (a CNAME record, easy in Route 53)
- Certificates for **CloudFront and Cognito custom domains must be in
us-east-1. For ALB and API Gateway regional endpoints request them in the same Region** - You cannot export public certificates to install on your own servers (use ACM Private CA or an external CA for that)
- Enforce HTTPS: ALB redirect 80 to 443, CloudFront viewer protocol policy: redirect HTTP to HTTPS,
aws:SecureTransportin bucket policies, TLS 1.2 or higher
Protecting Private Content with CloudFront
| Goal | Tool |
|---|---|
| Only CloudFront can read the S3 bucket | Origin Access Control (OAC) (replaces older OAI) plus a bucket policy allowing the distribution |
| Only CloudFront can reach your ALB | Secret custom header check, or the CloudFront managed prefix list in the ALB security group, or VPC origins |
| Paid or private downloads for specific users | Signed URLs (one file) or signed cookies (many files) |
| Block countries | Geo restriction |
| Control cache and headers safely | Cache policies, origin request policies, response headers policies (HSTS, CSP) |
| Signed URL | Signed cookie |
|---|---|
| One file or an RTMP-style single URL | Many files (a whole site area, HLS video segments) |
| URL changes | URLs stay the same |
- Signing uses a CloudFront key group (public key in CloudFront, private key in your backend). Keep the private key in Secrets Manager
- Do not confuse with S3 presigned URLs, which sign for S3 directly with IAM credentials. Use CloudFront signed URLs when content is delivered through CloudFront
python
from botocore.signers import CloudFrontSigner
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding
import datetime
def rsa_signer(message):
key = serialization.load_pem_private_key(PRIVATE_KEY_PEM, password=None)
return key.sign(message, padding.PKCS1v15(), hashes.SHA1()) # CloudFront canned policy uses RSA-SHA1
signer = CloudFrontSigner("K2JCJMDEHXQW5F", rsa_signer) # public key id
url = signer.generate_presigned_url("https://dxxxx.cloudfront.net/videos/lesson1.mp4",
date_less_than=datetime.datetime.utcnow() + datetime.timedelta(minutes=10))
AWS WAF
- WAF inspects HTTP(S) requests on CloudFront, ALB, API Gateway REST, AppSync, Cognito, App Runner, Verified Access
- A web ACL has rules evaluated in priority order. Actions: Allow, Block, Count, CAPTCHA, Challenge
- AWS managed rule groups: Core rule set (OWASP-style), SQL injection, known bad inputs, IP reputation, anonymous IP list, bot control, account takeover protection
- Rate-based rules block an IP that sends more than N requests in 5 minutes (stops brute force and scraping)
- Start rules in Count mode, watch logs, then switch to Block. Send WAF logs to S3, CloudWatch Logs or Firehose
- Shield Standard protects against common network and transport DDoS automatically and free. Shield Advanced adds more protection, response team and cost protection
json
{
"Name": "rate-limit-login",
"Priority": 10,
"Statement": {"RateBasedStatement": {"Limit": 100, "AggregateKeyType": "IP",
"ScopeDownStatement": {"ByteMatchStatement": {"SearchString": "/login", "FieldToMatch": {"UriPath": {}},
"TextTransformations": [{"Priority": 0, "Type": "NONE"}], "PositionalConstraint": "STARTS_WITH"}}}},
"Action": {"Block": {}},
"VisibilityConfig": {"SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "rate-limit-login"}
}
Secure Coding Checklist for AWS Apps
- Validate and encode all input and output. Use parameterized queries. Avoid
evaland shell injection - Protect against SSRF: do not fetch user-supplied URLs from servers with IAM roles unless filtered. Use IMDSv2
- Least-privilege roles per function and per service. No wildcards on sensitive actions
- Encrypt at rest and in transit. Keep secrets out of logs
- Keep dependencies patched (Amazon Inspector scans EC2, ECR and Lambda). Use CodeGuru Security or other scanners in CI
- Use short-lived credentials, MFA and OIDC federation for CI/CD instead of stored keys
- Log with CloudTrail, CloudWatch, GuardDuty to detect misuse
Securing AI Applications (Amazon Bedrock and Agents)
Applications that use foundation models bring new risks. The same principles apply (access control, privacy, logging) plus AI-specific controls.
| Risk | Defense |
|---|---|
| Unauthorized model or data access | IAM least privilege for bedrock:InvokeModel on specific model ARNs, VPC endpoints (PrivateLink) for private traffic, resource-based and Region/model allow lists in SCPs |
| Sensitive data exposure | Do not send secrets or unnecessary personal data in prompts. Mask or redact PII. Bedrock Guardrails can detect and block or mask PII. Encrypt with KMS and control retention |
| Unsafe or harmful content | Guardrails: content filters, denied topics, word filters, grounding checks, applied to inputs and outputs |
| Prompt injection (user or retrieved documents try to override instructions) | Treat model input as untrusted. Keep system instructions separate, filter and validate outputs, use Guardrails prompt-attack filter, never let model text directly run commands or SQL, limit what the model can do |
| Excessive agent permissions | Give each agent tool its own least-privilege role. Require human approval for risky actions (payments, deletes). Validate tool arguments with a schema. Log every tool call |
| Secrets and personal data in logs | Turn model invocation logging on only with care, do not log full prompts containing sensitive data, restrict log access, set retention, redact before logging |
| Poisoned or leaky knowledge bases | Control who can add documents, use metadata filtering and per-user access checks at retrieval time |
| Cost abuse and denial of wallet | Authenticate users, rate limit with WAF and API throttling, set token limits and budgets, alarms on usage |
python
import boto3
br = boto3.client("bedrock-runtime", region_name="us-east-1")
resp = br.converse(
modelId="anthropic.claude-sonnet-4-5-20250929-v1:0", # use a model id available to you
messages=[{"role": "user", "content": [{"text": user_text}]}],
guardrailConfig={"guardrailIdentifier": "gr-abc123", "guardrailVersion": "1", "trace": "enabled"},
inferenceConfig={"maxTokens": 500, "temperature": 0.2},
)
print(resp["output"]["message"]["content"][0]["text"])
print(resp["stopReason"]) # 'guardrail_intervened' when blocked
Model IDs change Model identifiers and availability by Region change often. Look up the current model ID in the Bedrock console or API (
list-foundation-models) instead of copying an old one.
Practice Tasks
- Request an ACM certificate with DNS validation and attach it to an ALB HTTPS listener
- Put a private S3 bucket behind CloudFront with OAC and confirm the direct S3 URL is blocked
- Generate a CloudFront signed URL that expires in 10 minutes
- Add a WAF web ACL with the Core rule set and a rate-based rule in Count mode, then Block
- Create a Bedrock guardrail that masks email addresses and blocks a denied topic, and test it
Conclusion
Layer your defenses: ACM for TLS, CloudFront with OAC and signed URLs for private content, WAF managed and rate rules, least-privilege roles, input validation and secret hygiene. For AI features add IAM scoping of models, Guardrails, prompt-injection awareness, limited and approved agent tools, and careful logging of sensitive data.
Quick Summary: layers; ACM; CloudFront protection; WAF; secure coding; AI security risks and defenses; Bedrock guardrails example.

