0Pricing
AWS Solutions Architect · Lesson

Secure Architecture Scenarios

Work through scenario questions on IAM least privilege, encryption, VPC isolation, and WAF/Shield to lock in your security domain knowledge.

Secure Architecture Scenarios is a free AWS Solutions Architect lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Scenario 1: Least-Privilege EC2 S3 Access

Scenario: An EC2 instance runs a web application that needs to read objects from a specific S3 bucket. The security team requires that no long-term credentials are stored on the instance and that access follows the principle of least privilege. Solution: Create an IAM role with a policy allowing only s3:GetObject on the specific bucket ARN. Attach the role to the EC2 instance as an instance profile. The application uses the instance metadata service (IMDS) to retrieve temporary credentials automatically — no stored keys needed.

# IAM policy for least-privilege EC2 -> S3 read
{
  'Version': '2012-10-17',
  'Statement': [{
    'Effect': 'Allow',
    'Action': ['s3:GetObject'],
    'Resource': 'arn:aws:s3:::my-app-bucket/*'
  }]
}

# Attach role to EC2 instance
aws ec2 associate-iam-instance-profile \
  --instance-id i-1234567890abcdef0 \
  --iam-instance-profile Name=EC2S3ReadRole

Scenario 2: Encrypting Data in an RDS Database

Scenario: A company stores customer PII in an RDS PostgreSQL database. The compliance team requires encryption at rest with the ability to audit key usage. Solution: Enable RDS encryption using AWS KMS with a Customer Managed Key (CMK). The CMK allows the security team to control key rotation, view key usage in CloudTrail, and revoke access if needed. Note: encryption must be enabled at RDS instance creation — you cannot encrypt an existing unencrypted RDS instance in place. To encrypt an existing DB, take a snapshot, copy it with encryption enabled, and restore from the encrypted snapshot.

# Create an encrypted RDS instance
aws rds create-db-instance \
  --db-instance-identifier prod-postgres \
  --db-instance-class db.t3.medium \
  --engine postgres \
  --master-username admin \
  --master-user-password SecurePass123! \
  --storage-encrypted \
  --kms-key-id arn:aws:kms:us-east-1:123456789012:key/mrk-abc123 \
  --allocated-storage 100

Scenario 3: S3 Bucket — Block Public Access

Scenario: A developer accidentally made an S3 bucket public, exposing customer data. The security team wants to ensure no S3 bucket in the account can ever be made public, even if a developer tries. Solution: Enable S3 Block Public Access at the account level. This overrides any bucket-level policy or ACL that grants public access, regardless of what individual teams configure. Combine with an AWS Config rule (s3-bucket-public-read-prohibited) to continuously detect and alert on any non-compliant buckets.

# Block all public access at account level
aws s3control put-public-access-block \
  --account-id 123456789012 \
  --public-access-block-configuration \
    'BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true'

# Deploy Config rule to detect violations
aws configservice put-config-rule \
  --config-rule '{"ConfigRuleName": "s3-bucket-public-read-prohibited", "Source": {"Owner": "AWS", "SourceIdentifier": "S3_BUCKET_PUBLIC_READ_PROHIBITED"}}'

Scenario 4: VPC Isolation for Database Tier

Scenario: A company wants to ensure their RDS database is only accessible from their application servers and not from the internet. Solution: Place RDS in a private subnet with no internet gateway route. Create a security group for RDS that only allows inbound traffic on port 5432 (PostgreSQL) from the application server security group — not from any IP address range. This ensures that even if an app server is compromised, the attacker cannot reach the database from outside the VPC, and lateral movement is limited by security group rules.

# Create RDS security group allowing only the app tier SG as source
aws ec2 create-security-group \
  --group-name rds-sg \
  --description 'RDS security group' \
  --vpc-id vpc-abc123

aws ec2 authorize-security-group-ingress \
  --group-id sg-rds \
  --protocol tcp \
  --port 5432 \
  --source-group sg-app  # app tier security group ID only

Scenario 5: Rotating Database Credentials

Scenario: Application code currently has database credentials hardcoded in configuration files. The security audit flags this as a critical risk. Solution: Store credentials in AWS Secrets Manager and configure automatic rotation (Secrets Manager has built-in Lambda rotation functions for RDS). Update the application to fetch credentials from Secrets Manager at runtime using the SDK. The application automatically gets fresh credentials without any deployment on each rotation. Enable the RDS secret rotation template for fully managed, zero-downtime credential rotation.

# Store RDS credentials in Secrets Manager
aws secretsmanager create-secret \
  --name prod/myapp/rds \
  --secret-string '{"username":"admin","password":"OldPass123!","host":"rds-endpoint.amazonaws.com","port":5432}'

# Enable automatic rotation every 30 days
aws secretsmanager rotate-secret \
  --secret-id prod/myapp/rds \
  --rotation-lambda-arn arn:aws:lambda:us-east-1:123:function:SecretsManagerRDSPostgreSQLRotationSingleUser \
  --rotation-rules AutomaticallyAfterDays=30

Scenario 6: Detecting Unusual API Activity

Scenario: A company wants to detect if AWS account credentials are compromised and used from unexpected locations. Solution: Enable Amazon GuardDuty in all Regions. GuardDuty analyses CloudTrail events, VPC Flow Logs, and DNS logs using machine learning to detect anomalies: API calls from unusual geographies, Bitcoin mining patterns on EC2, Tor exit node communication, or credential exfiltration patterns. GuardDuty generates findings that can trigger EventBridge rules to automatically notify the security team via SNS or create a support ticket.

# Enable GuardDuty in a Region
aws guardduty create-detector \
  --enable \
  --finding-publishing-frequency FIFTEEN_MINUTES

# EventBridge rule to react to GuardDuty HIGH severity findings
aws events put-rule \
  --name guardduty-high-severity \
  --event-pattern '{
    "source": ["aws.guardduty"],
    "detail-type": ["GuardDuty Finding"],
    "detail": {"severity": [{"numeric": [">=", 7]}]}
  }'

Scenario 7: WAF to Block Malicious Requests

Scenario: A web application running behind an ALB is receiving SQL injection attacks. The application cannot be modified immediately. Solution: Associate AWS WAF with the ALB. Deploy the AWS Managed Rules for Common Threats rule group (Core Rule Set + SQL Database rule group) which includes pre-built SQL injection detection. WAF inspects HTTP requests before they reach the ALB and blocks requests matching attack patterns — no application code change required. Also enable WAF logging to Kinesis Firehose for security analysis.

# Create WAF Web ACL with SQL injection protection
aws wafv2 create-web-acl \
  --name AppProtection \
  --scope REGIONAL \
  --default-action Allow={} \
  --rules '[{
    "Name": "AWSManagedRulesSQLiRuleSet",
    "Priority": 1,
    "Statement": {
      "ManagedRuleGroupStatement": {
        "VendorName": "AWS",
        "Name": "AWSManagedRulesSQLiRuleSet"
      }
    },
    "OverrideAction": {"None": {}},
    "VisibilityConfig": {"SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "SQLi"}
  }]' \
  --region us-east-1

Scenario 8: Cross-Account Assume Role

Scenario: A central security account needs read-only access to all workload accounts in an AWS Organisation to run security audits. Solution: In each workload account, create an IAM role with a trust policy allowing the security account (by account ID) to assume it. Attach a read-only policy (e.g., SecurityAudit AWS managed policy). The security team in the central account uses STS AssumeRole to temporarily assume the role in each workload account. This follows the principle of least privilege — no permanent IAM users are created in workload accounts.

# Trust policy in workload account (allows security account to assume role)
{
  'Version': '2012-10-17',
  'Statement': [{
    'Effect': 'Allow',
    'Principal': {
      'AWS': 'arn:aws:iam::SECURITY_ACCOUNT_ID:root'
    },
    'Action': 'sts:AssumeRole'
  }]
}

# From security account: assume role in workload account
aws sts assume-role \
  --role-arn arn:aws:iam::WORKLOAD_ACCOUNT_ID:role/SecurityAuditRole \
  --role-session-name audit-2024-01

Scenario 9: Restricting Actions with SCPs

Scenario: A company uses AWS Organizations and wants to prevent any account in a non-production OU from launching expensive GPU instances. Solution: Create a Service Control Policy (SCP) that denies ec2:RunInstances for GPU instance families (p3, p4, g4, g5) and attach it to the non-production OU. SCPs apply even to root users and Administrator-level IAM users in the member accounts — they act as guardrails that no identity in the account can override. This prevents accidental or malicious large spend in dev/test accounts.

# SCP to deny GPU instance types in non-prod OU
{
  'Version': '2012-10-17',
  'Statement': [{
    'Sid': 'DenyGPUInstances',
    'Effect': 'Deny',
    'Action': 'ec2:RunInstances',
    'Resource': 'arn:aws:ec2:*:*:instance/*',
    'Condition': {
      'StringLike': {
        'ec2:InstanceType': ['p3.*', 'p4d.*', 'g4.*', 'g5.*']
      }
    }
  }]
}

Scenario 10: Audit Trail for Compliance

Scenario: A financial services company must demonstrate to auditors that all AWS API calls are logged, tamper-proof, and retained for 7 years. Solution: Create a multi-region AWS CloudTrail trail that delivers logs to a dedicated S3 bucket in a logging account. Enable Log File Integrity Validation (cryptographic digest files that detect log tampering). Set an S3 Object Lock policy in Compliance mode with a 7-year retention period on the logging bucket. This ensures logs cannot be deleted or modified — even by the root user — for the required retention period.

# Create multi-region trail with integrity validation
aws cloudtrail create-trail \
  --name compliance-trail \
  --s3-bucket-name central-audit-logs-123 \
  --is-multi-region-trail \
  --enable-log-file-validation \
  --include-global-service-events

aws cloudtrail start-logging --name compliance-trail

Scenario 11: VPC Endpoint for Private S3 Access

Scenario: EC2 instances in a private VPC need to access S3 without traffic traversing the public internet. A NAT Gateway is currently used and costs are high due to NAT Gateway data processing fees. Solution: Create an S3 Gateway VPC Endpoint. Add a route entry to the private subnet's route table pointing the S3 prefix list to the endpoint. Traffic to S3 now stays within the AWS network backbone entirely — no NAT Gateway, no internet gateway needed. S3 Gateway Endpoints are free of charge (unlike Interface Endpoints which cost per-hour per-AZ). This also improves security by removing S3 access from the public internet path.

# Create S3 Gateway VPC Endpoint
aws ec2 create-vpc-endpoint \
  --vpc-id vpc-abc123 \
  --service-name com.amazonaws.us-east-1.s3 \
  --route-table-ids rtb-private-1a rtb-private-1b

# Result: route table automatically gets a route:
# Destination: pl-63a5400a (S3 prefix list)
# Target: vpce-xyz456 (the Gateway Endpoint)
# EC2 instances now reach S3 privately at no endpoint cost

Quick Check

Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.

Lesson Recap

In this lesson you worked through scenarios covering: IAM roles and instance profiles for credential-free EC2 access, Secrets Manager for automatic database credential rotation, AWS WAF for blocking injection attacks without code changes, and CloudTrail with S3 Object Lock for tamper-proof compliance logs. Next up we tackle resilient and highly available architecture scenarios.

Frequently asked questions

Is the “Secure Architecture Scenarios” lesson free?

Yes — the full text of “Secure Architecture Scenarios” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.

What will I learn in “Secure Architecture Scenarios”?

Work through scenario questions on IAM least privilege, encryption, VPC isolation, and WAF/Shield to lock in your security domain knowledge. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Solutions Architect?

No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Secure Architecture Scenarios” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Solutions Architect lesson?

Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Secure Architecture Scenarios
  2. Resilient and Highly Available Architecture Scenarios
  3. High-Performance and Cost-Optimised Scenarios
  4. Mixed Domain Full-Length Mini Exam
← Back to AWS Solutions Architect