Home / Topics / AWS for DevOps / Troubleshooting
AWS for DevOps

Troubleshooting

Real AWS error messages, symptoms and how to diagnose them with the aws CLI


IAM and Access Errors

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q1

An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied for a user who has S3 read access. What is wrong?

Beginner

Likely causes โ†’ The policy grants object actions but not s3:ListAllMyBuckets; or the user is on a different profile than expected.

Diagnose โ†’

bash
aws sts get-caller-identity
aws iam list-attached-user-policies --user-name alice
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::111111111111:user/alice --action-names s3:ListAllMyBuckets

Fix โ†’

  1. Confirm you are using the intended profile with AWS_PROFILE
  2. Add s3:ListAllMyBuckets on * if bucket listing is genuinely required
  3. Otherwise instruct the user to aws s3 ls s3://bucket directly

Prevent โ†’ Document the minimal policy template for S3 users; bucket-scoped listing needs s3:ListBucket on the bucket ARN.

Copy link
Q2

ExpiredToken: The security token included in the request is expired in a long CI job. How do you fix it?

Beginner

Likely causes โ†’ Assumed-role sessions last 1 hour by default and the job exceeded it, or cached credentials are stale.

Diagnose โ†’

bash
aws sts get-caller-identity
env | grep AWS_
aws iam get-role --role-name ci-deploy --query Role.MaxSessionDuration

Fix โ†’

  1. Raise role MaxSessionDuration and request --duration-seconds accordingly
  2. Re-authenticate mid-job or split the job
  3. Unset stale AWS_SESSION_TOKEN variables left over from a prior step

Prevent โ†’ Use OIDC with fresh credentials per job and keep jobs short.

Copy link
Q3

User: arn:aws:sts::111111111111:assumed-role/dev/bob is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::222222222222:role/deploy. Why?

Intermediate

Likely causes โ†’ Caller lacks an sts:AssumeRole allow, or the target trust policy excludes the caller, or an SCP denies it.

Diagnose โ†’

bash
aws iam get-role --role-name deploy --query Role.AssumeRolePolicyDocument
aws iam list-role-policies --role-name dev
aws organizations list-policies-for-target --target-id 111111111111 --filter SERVICE_CONTROL_POLICY

Fix โ†’

  1. Add allow on the target ARN to the caller's policy
  2. Fix the trust policy principal
  3. Remove blocking SCP conditions

Prevent โ†’ Keep a trust-policy template in IaC and test with a CI assume-role smoke test.

Copy link
Q4

An error occurred (AccessDenied) ... because no identity-based policy allows the s3:GetObject action yet a bucket policy allows the user. Cross-account?

Intermediate

Likely causes โ†’ For cross-account, both the caller's account identity policy and the bucket policy must allow.

Diagnose โ†’

bash
aws s3api get-bucket-policy --bucket shared
aws iam list-attached-role-policies --role-name reader
aws iam simulate-principal-policy --policy-source-arn <arn> --action-names s3:GetObject --resource-arns arn:aws:s3:::shared/*

Fix โ†’

  1. Add s3:GetObject to the caller role's identity policy
  2. Keep the bucket policy as is

Prevent โ†’ Treat cross-account access as two changes in your runbook.

Copy link
Q5

IAM policy validation: MalformedPolicyDocument: Policy document should not specify a principal. What happened?

Intermediate

Likely causes โ†’ A resource-based policy element was placed in an identity policy.

Diagnose โ†’

bash
aws accessanalyzer validate-policy --policy-document file://p.json --policy-type IDENTITY_POLICY

Fix โ†’

  1. Remove Principal from the identity policy
  2. Use a trust policy for roles instead
  3. Re-run validation

Prevent โ†’ Validate policies in CI by policy type.

Copy link
Q6

The security token included in the request is invalid when using aws CLI.

Beginner

Likely causes โ†’ Wrong region or partition, a mangled session token, or credentials of a deleted key.

Diagnose โ†’

bash
aws configure list
env | grep -i aws
aws sts get-caller-identity --debug 2>&1 | head -50

Fix โ†’

  1. Unset environment credentials and rerun aws configure or aws sso login
  2. Check for trailing whitespace in the token
  3. Re-create the access key if deleted

Prevent โ†’ Prefer SSO and avoid copy-pasting tokens.

Copy link
Q7

SSO login works in the browser but aws sso login hangs or gives Error loading SSO Token: Token for ... does not exist.

Intermediate

Likely causes โ†’ Missing or stale cache in ~/.aws/sso/cache, wrong sso_session, or a headless terminal.

Diagnose โ†’

bash
cat ~/.aws/config
ls ~/.aws/sso/cache
aws sso login --profile dev --use-device-code --debug

Fix โ†’

  1. Remove stale cache files and log in again
  2. Use --use-device-code on remote machines
  3. Verify sso_region and sso_start_url

Prevent โ†’ Use aws configure sso-session templates for the team.

Copy link
Q8

An SCP is suspected of denying actions but console errors are vague. How do you confirm?

Advanced

Likely causes โ†’ Explicit deny from SCP shows in the error text of recent API versions and in CloudTrail.

Diagnose โ†’

bash
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=RunInstances --max-results 5
aws organizations describe-effective-policy --policy-type SERVICE_CONTROL_POLICY --target-id 111111111111
aws organizations list-policies-for-target --target-id ou-xxxx --filter SERVICE_CONTROL_POLICY

Fix โ†’

  1. Adjust the SCP, test in a sandbox OU first
  2. Use an exception for the required principal via condition keys

Prevent โ†’ Keep SCPs in IaC with a test suite of allowed and denied calls.

Copy link
Q9

iam:PassRole error: User is not authorized to perform: iam:PassRole on resource: arn:aws:iam::...:role/task-role.

Intermediate

Likely causes โ†’ The deployer can launch a service but lacks permission to hand the role to it.

Diagnose โ†’

bash
aws iam get-role --role-name task-role
aws iam simulate-principal-policy --policy-source-arn <deployer-arn> --action-names iam:PassRole --resource-arns <role-arn>

Fix โ†’

  1. Add iam:PassRole on that specific role ARN with condition iam:PassedToService
  2. Do not use wildcard resources

Prevent โ†’ Scope PassRole narrowly; it is a privilege escalation path.

Copy link
Q10

A newly created IAM user cannot see anything in the console. Why?

Beginner

Likely causes โ†’ New users have no permissions.

Diagnose โ†’

bash
aws iam list-attached-user-policies --user-name new
aws iam list-groups-for-user --user-name new

Fix โ†’

  1. Attach a group with required policies
  2. Wait a few seconds for propagation

Prevent โ†’ Manage by groups or SSO, not by individual attachments.

Copy link
Q11

Policy changes do not seem to apply for several minutes. Is something broken?

Intermediate

Likely causes โ†’ IAM is eventually consistent, and existing sessions keep old permissions until refreshed.

Diagnose โ†’

bash
aws iam get-policy-version --policy-arn <arn> --version-id v2
aws sts get-caller-identity
aws iam get-role --role-name r

Fix โ†’

  1. Retry with backoff
  2. Re-assume the role to get a fresh session
  3. Avoid create-then-use in the same script without waiting

Prevent โ†’ Build retries into IaC and deployment pipelines.

Copy link
Q12

AccessDenied with message explicit deny in a resource-based policy for a KMS decrypt in a cross-account pipeline.

Advanced

Likely causes โ†’ The key policy lacks the caller or has a deny condition on kms:ViaService or encryption context.

Diagnose โ†’

bash
aws kms get-key-policy --key-id <key> --policy-name default
aws kms list-grants --key-id <key>
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=Decrypt

Fix โ†’

  1. Add the role ARN to the key policy or a grant
  2. Add the identity policy allow for kms:Decrypt
  3. Check encryption context

Prevent โ†’ Review key policies when granting cross-account S3 or EBS access.

Copy link
Q13

The error You are not authorized to perform this operation. Encoded authorization failure message: .... How do you read it?

Intermediate

Likely causes โ†’ EC2 encodes failure details that must be decoded.

Diagnose โ†’

bash
aws sts decode-authorization-message --encoded-message <msg> --query DecodedMessage --output text | jq .

Fix โ†’

  1. Read explicitDeny, matchedStatements, and context keys
  2. Fix the policy statement that matched

Prevent โ†’ Grant sts:DecodeAuthorizationMessage to engineers.

Copy link
Q14

An IAM role created by CloudFormation cannot be assumed by a Lambda: The role defined for the function cannot be assumed by Lambda.

Intermediate

Likely causes โ†’ Trust policy missing lambda.amazonaws.com, or the role was just created.

Diagnose โ†’

bash
aws iam get-role --role-name fn-role --query Role.AssumeRolePolicyDocument

Fix โ†’

  1. Add lambda.amazonaws.com to trust policy
  2. Add DependsOn or wait; retry creation

Prevent โ†’ Use SAM or CDK helpers that wire trust automatically.

Copy link
Q15

Your IAM role limit error: LimitExceeded: Cannot exceed quota for PoliciesPerRole: 10.

Beginner

Likely causes โ†’ Managed policy attachments per role are capped at 10 by default (up to 20 by quota).

Diagnose โ†’

bash
aws iam list-attached-role-policies --role-name big
aws service-quotas get-service-quota --service-code iam --quota-code L-0DA4ABF3

Fix โ†’

  1. Consolidate policies into fewer customer managed ones
  2. Request a quota increase
  3. Split the role by function

Prevent โ†’ Design roles per workload, not mega-roles.

Copy link
Q16

Policy size exceeds quota: Maximum policy size of 6144 characters when attaching an inline policy.

Intermediate

Likely causes โ†’ Role inline policies total limit is 10,240 chars; managed policies cap at 6,144.

Diagnose โ†’

bash
wc -c policy.json
aws iam list-role-policies --role-name r

Fix โ†’

  1. Use wildcards by prefix with care
  2. Split into several managed policies
  3. Use tag-based ABAC to shrink statements

Prevent โ†’ Prefer ABAC and resource tags over listing ARNs.

Copy link
Q17

Access Analyzer reports an external access finding for an S3 bucket you thought was private.

Intermediate

Likely causes โ†’ Bucket policy or ACL grants a principal outside the zone of trust, possibly via Principal: *.

Diagnose โ†’

bash
aws accessanalyzer list-findings --analyzer-arn <arn>
aws s3api get-bucket-policy-status --bucket b
aws s3api get-bucket-acl --bucket b

Fix โ†’

  1. Remove the offending statement
  2. Re-enable Block Public Access
  3. Archive the finding if intentional

Prevent โ†’ Alert on new findings through EventBridge.

Copy link
Q18

Cross-account role session shows AccessDenied only for sts:TagSession calls from an SSO flow.

Advanced

Likely causes โ†’ Trust policy lacks sts:TagSession which is needed when sessions carry tags.

Diagnose โ†’

bash
aws iam get-role --role-name target
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=AssumeRole

Fix โ†’

  1. Add sts:TagSession to the trust policy action list
  2. Retry

Prevent โ†’ Include sts:TagSession whenever you use session tags or ABAC.

Copy link
Q19

The config profile (prod) could not be found.

Beginner

Likely causes โ†’ Profile name not defined in ~/.aws/config.

Diagnose โ†’

bash
aws configure list-profiles
cat ~/.aws/config

Fix โ†’

  1. Add the profile or fix the name
  2. Check AWS_PROFILE env value

Prevent โ†’ Standardize profile names across the team.

Copy link
Q20

GitHub Actions OIDC fails: Not authorized to perform sts:AssumeRoleWithWebIdentity.

Intermediate

Likely causes โ†’ Trust policy sub or aud conditions mismatch the workflow's token.

Diagnose โ†’

bash
aws iam get-role --role-name gh-deploy --query Role.AssumeRolePolicyDocument
# in workflow print the token claims with a debug step (never in production logs)

Fix โ†’

  1. Align sub with repo:org/repo:ref:refs/heads/main or environment form
  2. Ensure aud equals sts.amazonaws.com
  3. Add id-token: write permission

Prevent โ†’ Test trust policy with a staging branch pattern.

Copy link
Q21

Instance role credentials stopped working inside a container on an EC2 host: Unable to locate credentials.

Intermediate

Likely causes โ†’ IMDSv2 hop limit of 1 blocks containers from reaching metadata.

Diagnose โ†’

bash
curl -s -X PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 60'
aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].MetadataOptions'

Fix โ†’

  1. Set hop limit to 2: aws ec2 modify-instance-metadata-options --instance-id i-0abc --http-put-response-hop-limit 2 --http-tokens required
  2. Or use task or pod roles

Prevent โ†’ Bake hop limit into launch templates.

Copy link
Q22

Organization CloudTrail stopped delivering logs. How do you recover?

Advanced

Likely causes โ†’ The bucket policy changed, KMS key permissions broke, or the trail was disabled.

Diagnose โ†’

bash
aws cloudtrail get-trail-status --name org-trail
aws s3api get-bucket-policy --bucket log-archive
aws kms describe-key --key-id <key>

Fix โ†’

  1. Restore bucket policy allowing cloudtrail.amazonaws.com
  2. Fix KMS key policy
  3. aws cloudtrail start-logging --name org-trail

Prevent โ†’ Alarm on LatestDeliveryError and protect via SCP.

Copy link
Q23

Console says You don't have permission to view this for CloudWatch Logs but CLI works.

Intermediate

Likely causes โ†’ Console needs extra read permissions such as logs:DescribeLogGroups.

Diagnose โ†’

bash
aws iam simulate-principal-policy --policy-source-arn <arn> --action-names logs:DescribeLogGroups logs:GetLogEvents

Fix โ†’

  1. Add console-required describe actions
  2. Use the AWS managed CloudWatchLogsReadOnlyAccess

Prevent โ†’ Test console flows for each new role.

Copy link
Q24

InvalidClientTokenId when calling an API in a new opt-in region.

Intermediate

Likely causes โ†’ The region is disabled for the account or credentials are for the wrong partition.

Diagnose โ†’

bash
aws account get-region-opt-status --region-name ap-south-2
aws sts get-caller-identity --region ap-south-2

Fix โ†’

  1. Enable the region: aws account enable-region --region-name ap-south-2
  2. Wait for enablement

Prevent โ†’ Document region opt-ins in the landing zone.

Copy link
Q25

Root user lost MFA device. How to recover?

Beginner

Likely causes โ†’ Use the account recovery flow.

Diagnose โ†’

bash
Sign in as root and choose the troubleshooting link
Verify email and phone
Contact AWS Support if required

Fix โ†’

  1. Re-register MFA after verification
  2. Review recent activity

Prevent โ†’ Register multiple MFA devices for root.

Copy link

VPC and Connectivity

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q26

ssh: connect to host 3.250.1.1 port 22: Connection timed out. Walk the checks.

Beginner

Likely causes โ†’ Timeout means packets are dropped: SG, NACL, route, public IP, or an on-instance firewall.

Diagnose โ†’

bash
aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].[PublicIpAddress,SecurityGroups,SubnetId]'
aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=subnet-0abc
aws ec2 describe-network-acls --filters Name=association.subnet-id,Values=subnet-0abc
aws ec2 describe-network-insights-analyses

Fix โ†’

  1. Add SG rule for your IP
  2. Ensure route 0.0.0.0/0 to the IGW
  3. Fix NACL rules
  4. Prefer SSM Session Manager

Prevent โ†’ Remove public SSH and use SSM.

Copy link
Q27

ssh: connect to host ... port 22: Connection refused. How is it different from a timeout?

Beginner

Likely causes โ†’ Refused means the packet arrived but nothing is listening, or the OS firewall rejected.

Diagnose โ†’

bash
aws ec2 get-console-output --instance-id i-0abc --latest --output text | tail -50
aws ssm start-session --target i-0abc
sudo ss -ltnp | grep 22
sudo systemctl status sshd

Fix โ†’

  1. Start sshd
  2. Fix sshd_config
  3. Check ufw or iptables

Prevent โ†’ Bake sshd settings into the AMI.

Copy link
Q28

Permission denied (publickey) on a new EC2 instance.

Intermediate

Likely causes โ†’ Wrong key pair, wrong username, or wrong permissions on the key file.

Diagnose โ†’

bash
ssh -vvv -i key.pem ec2-user@host
chmod 400 key.pem
aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].KeyName'

Fix โ†’

  1. Use correct user: ec2-user, ubuntu, admin
  2. Use the right key
  3. Use EC2 Instance Connect or SSM to inject a new key

Prevent โ†’ Document usernames per AMI.

Copy link
Q29

Private instances cannot reach the internet; curl: (28) Connection timed out after 10000 milliseconds.

Intermediate

Likely causes โ†’ NAT gateway missing, route absent, or NAT in a subnet without an IGW route.

Diagnose โ†’

bash
aws ec2 describe-nat-gateways --filter Name=vpc-id,Values=vpc-0abc
aws ec2 describe-route-tables --route-table-ids rtb-0abc
aws ec2 describe-subnets --subnet-ids <nat-subnet>
curl -v https://example.com

Fix โ†’

  1. Create the NAT in a public subnet
  2. Fix routes
  3. Check NACL and SG egress

Prevent โ†’ Test egress in IaC pipelines.

Copy link
Q30

NAT gateway shows ErrorPortAllocation in CloudWatch and connections drop.

Intermediate

Likely causes โ†’ Too many concurrent connections to the same destination from one NAT IP.

Diagnose โ†’

bash
aws cloudwatch get-metric-statistics --namespace AWS/NATGateway --metric-name ErrorPortAllocation --dimensions Name=NatGatewayId,Value=nat-0abc --start-time 2026-11-08T00:00:00Z --end-time 2026-11-09T00:00:00Z --period 300 --statistics Sum
aws ec2 describe-nat-gateways

Fix โ†’

  1. Add secondary EIPs or more NAT gateways
  2. Spread across AZs
  3. Reuse connections and reduce churn

Prevent โ†’ Alarm on port allocation errors.

Copy link
Q31

VPC peering is active but ping fails.

Intermediate

Likely causes โ†’ Missing routes, SG rule, or NACL.

Diagnose โ†’

bash
aws ec2 describe-vpc-peering-connections
aws ec2 describe-route-tables --filters Name=route.vpc-peering-connection-id,Values=pcx-0abc
aws ec2 describe-security-groups --group-ids sg-0abc

Fix โ†’

  1. Add routes both ways
  2. Allow ICMP or app port in SG
  3. Fix NACL

Prevent โ†’ Use Reachability Analyzer in CI.

Copy link
Q32

VPC Reachability Analyzer says BLACKHOLE. What does it mean?

Advanced

Likely causes โ†’ A route points to a deleted or inactive target.

Diagnose โ†’

bash
aws ec2 create-network-insights-path --source i-0abc --destination i-0def --protocol tcp --destination-port 443
aws ec2 start-network-insights-analysis --network-insights-path-id nip-0abc
aws ec2 describe-route-tables

Fix โ†’

  1. Remove or fix the blackhole route (deleted NAT, TGW or peering)
  2. Re-run the analysis

Prevent โ†’ Alert on blackhole routes via Config.

Copy link
Q33

Transit Gateway attached VPCs cannot talk to each other.

Intermediate

Likely causes โ†’ Missing association or propagation in TGW route tables, or VPC routes.

Diagnose โ†’

bash
aws ec2 get-transit-gateway-route-table-associations --transit-gateway-route-table-id tgw-rtb-0abc
aws ec2 search-transit-gateway-routes --transit-gateway-route-table-id tgw-rtb-0abc --filters Name=state,Values=active
aws ec2 describe-route-tables

Fix โ†’

  1. Associate attachments with the right route table
  2. Enable propagation
  3. Add VPC routes to the TGW

Prevent โ†’ Model TGW routing with diagrams.

Copy link
Q34

Site-to-Site VPN tunnel is DOWN on one side.

Intermediate

Likely causes โ†’ IKE mismatch, wrong pre-shared key, or on-prem device idle with no DPD.

Diagnose โ†’

bash
aws ec2 describe-vpn-connections --vpn-connection-ids vpn-0abc --query 'VpnConnections[].VgwTelemetry'
# check device logs for IKE phase 1 and 2

Fix โ†’

  1. Align IKE version and proposals
  2. Reapply the configuration download
  3. Enable DPD and keepalives

Prevent โ†’ Monitor TunnelState.

Copy link
Q35

Elastic IP association fails: Resource ... is already associated with a different resource.

Beginner

Likely causes โ†’ EIP attached elsewhere.

Diagnose โ†’

bash
aws ec2 describe-addresses --allocation-ids eipalloc-0abc

Fix โ†’

  1. Disassociate then associate, or use --allow-reassociation

Prevent โ†’ Track EIPs in IaC.

Copy link
Q36

Unable to resolve host inside a VPC though internet is available.

Intermediate

Likely causes โ†’ DNS support disabled, or custom DHCP option set points to unreachable DNS.

Diagnose โ†’

bash
aws ec2 describe-vpc-attribute --vpc-id vpc-0abc --attribute enableDnsSupport
aws ec2 describe-dhcp-options
cat /etc/resolv.conf
dig @169.254.169.253 example.com

Fix โ†’

  1. Enable DNS support and hostnames
  2. Fix DHCP options

Prevent โ†’ Keep default DHCP options unless needed.

Copy link
Q37

Private hosted zone names do not resolve from a peered VPC.

Intermediate

Likely causes โ†’ Zone not associated with that VPC.

Diagnose โ†’

bash
aws route53 get-hosted-zone --id Z123
dig db.internal.example.com

Fix โ†’

  1. Associate the VPC (cross-account needs authorization)
  2. Enable DNS resolution on peering

Prevent โ†’ Use Resolver rules shared via RAM.

Copy link
Q38

Interface endpoint created but SDK calls still go to the internet.

Intermediate

Likely causes โ†’ Private DNS disabled or no DNS support.

Diagnose โ†’

bash
aws ec2 describe-vpc-endpoints --vpc-endpoint-ids vpce-0abc
dig sqs.eu-west-1.amazonaws.com

Fix โ†’

  1. Enable PrivateDns on the endpoint
  2. Fix VPC DNS attributes

Prevent โ†’ Verify DNS answers in post-deploy test.

Copy link
Q39

S3 gateway endpoint blocks access: AccessDenied through VPC endpoint.

Intermediate

Likely causes โ†’ Endpoint policy or bucket policy restricts.

Diagnose โ†’

bash
aws ec2 describe-vpc-endpoints --filters Name=service-name,Values=com.amazonaws.eu-west-1.s3
aws s3api get-bucket-policy --bucket b

Fix โ†’

  1. Allow the bucket in endpoint policy
  2. Add needed AWS managed buckets such as package repos

Prevent โ†’ Test endpoint policies with real workloads.

Copy link
Q40

Security group references do not work across peered VPCs in different regions.

Intermediate

Likely causes โ†’ Cross-region peering cannot reference SGs.

Diagnose โ†’

bash
aws ec2 describe-security-groups --group-ids sg-0abc

Fix โ†’

  1. Use CIDR rules for cross-region peers

Prevent โ†’ Document limits.

Copy link
Q41

Security group rule limit: RulesPerSecurityGroupLimitExceeded.

Beginner

Likely causes โ†’ Too many rules in one SG.

Diagnose โ†’

bash
aws ec2 describe-security-groups --group-ids sg-0abc --query 'SecurityGroups[].IpPermissions | length(@)'

Fix โ†’

  1. Use prefix lists
  2. Split groups
  3. Request quota

Prevent โ†’ Use managed prefix lists.

Copy link
Q42

Return traffic is blocked even though SG allows; NACL is suspected.

Intermediate

Likely causes โ†’ NACL is stateless; ephemeral ports not allowed.

Diagnose โ†’

bash
aws ec2 describe-network-acls --network-acl-ids acl-0abc
# check flow logs for REJECT on high ports

Fix โ†’

  1. Allow ephemeral 1024-65535 outbound and inbound as needed

Prevent โ†’ Keep NACLs default unless required.

Copy link
Q43

Instances in a new subnet cannot get an IP: InsufficientFreeAddressesInSubnet.

Intermediate

Likely causes โ†’ Subnet exhausted.

Diagnose โ†’

bash
aws ec2 describe-subnets --subnet-ids subnet-0abc --query 'Subnets[].AvailableIpAddressCount'

Fix โ†’

  1. Launch in another subnet
  2. Add subnets
  3. Add secondary CIDR

Prevent โ†’ Monitor available IPs.

Copy link
Q44

Asymmetric routing breaks a stateful firewall behind GWLB.

Advanced

Likely causes โ†’ Flow returns via a different AZ.

Diagnose โ†’

bash
aws ec2 describe-transit-gateway-vpc-attachments --query 'TransitGatewayVpcAttachments[].Options'
# check flow logs per AZ

Fix โ†’

  1. Enable appliance mode on the TGW attachment
  2. Keep route per AZ consistent

Prevent โ†’ Test failover per AZ.

Copy link
Q45

Network Load Balancer targets show unhealthy but the app works when tested directly.

Intermediate

Likely causes โ†’ SG on targets blocks NLB source, or health check port mismatch.

Diagnose โ†’

bash
aws elbv2 describe-target-health --target-group-arn <arn>
aws elbv2 describe-target-groups --target-group-arns <arn>

Fix โ†’

  1. Allow health check source ranges
  2. Fix port and protocol

Prevent โ†’ Use client IP preservation rules carefully.

Copy link
Q46

Direct Connect virtual interface BGP session stays Down.

Intermediate

Likely causes โ†’ VLAN, ASN or MD5 mismatch.

Diagnose โ†’

bash
aws directconnect describe-virtual-interfaces
# check router BGP summary

Fix โ†’

  1. Align VLAN ID, ASN, auth key and IPs
  2. Contact the colo provider if layer 2 is down

Prevent โ†’ Keep a config checklist.

Copy link
Q47

RequestLimitExceeded from the EC2 API during mass operations.

Intermediate

Likely causes โ†’ API throttling.

Diagnose โ†’

bash
aws ec2 describe-instances --max-items 50

Fix โ†’

  1. Add exponential backoff and jitter
  2. Use pagination
  3. Reduce polling

Prevent โ†’ Use the SDK retry modes (adaptive).

Copy link
Q48

Cannot delete a VPC: The vpc has dependencies and cannot be deleted.

Beginner

Likely causes โ†’ ENIs, endpoints, NAT or gateways still exist.

Diagnose โ†’

bash
aws ec2 describe-network-interfaces --filters Name=vpc-id,Values=vpc-0abc
aws ec2 describe-vpc-endpoints --filters Name=vpc-id,Values=vpc-0abc
aws ec2 describe-nat-gateways --filter Name=vpc-id,Values=vpc-0abc

Fix โ†’

  1. Delete dependencies in order: instances, endpoints, NAT, IGW, subnets, SGs, route tables, VPC

Prevent โ†’ Manage VPCs with IaC for clean teardown.

Copy link
Q49

SSH and small HTTP requests work across a VPN / Transit Gateway, but large file transfers and TLS handshakes hang.

Advanced

Likely causes โ†’ An MTU mismatch. Instances use jumbo frames (9001 MTU) inside the VPC, but Site-to-Site VPN supports at most 1446 bytes and Transit Gateway 8500. Small packets fit; big ones need fragmentation. Path MTU Discovery fails because ICMP "fragmentation needed" (type 3 code 4) is blocked by a security group, NACL or on-prem firewall.

Diagnose โ†’

bash
ip link show eth0 | grep mtu                 # 9001 on most Nitro instances
ping -M do -s 1418 10.20.0.15                # 1418 + 28 = 1446, should pass
ping -M do -s 1472 10.20.0.15                # fails => MTU is the problem
tracepath 10.20.0.15                         # shows the pmtu hop by hop
aws ec2 describe-security-groups --group-ids sg-0abc --query 'SecurityGroups[].IpPermissions[?IpProtocol==`icmp`]'

Fix โ†’

  1. Allow inbound ICMP type 3 code 4 (Destination Unreachable / Fragmentation Needed) in the SGs and NACLs on both sides
  2. Enable TCP MSS clamping on the customer gateway (for example MSS 1379 for IPsec)
  3. As a short-term workaround, lower the instance MTU: sudo ip link set dev eth0 mtu 1400

Prevent โ†’ Treat ICMP unreachable as required traffic in baseline SGs, and document per-path MTU (VPN 1446, TGW 8500, internet 1500).

Copy link
Q50

InvalidSubnet.Conflict: The CIDR '10.0.1.0/24' conflicts with another subnet when creating a subnet.

Beginner

Likely causes โ†’ The CIDR overlaps an existing subnet in the same VPC. A related error, InvalidSubnet.Range: The CIDR '10.1.0.0/24' is invalid, means the block is outside the VPC CIDR(s) or smaller than /28.

Diagnose โ†’

bash
aws ec2 describe-vpcs --vpc-ids vpc-0abc --query 'Vpcs[].CidrBlockAssociationSet[].CidrBlock'
aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-0abc \
  --query 'Subnets[].[SubnetId,CidrBlock,AvailabilityZone]' --output table

Fix โ†’

  1. Pick a free, non-overlapping range inside the VPC CIDR
  2. If the VPC is full, add a secondary CIDR: aws ec2 associate-vpc-cidr-block --vpc-id vpc-0abc --cidr-block 10.1.0.0/16
  3. Then create the subnet inside the new range

Prevent โ†’ Plan subnets with IPAM or a documented CIDR map. Calculate subnets in Terraform with cidrsubnet() rather than typing them by hand.

Copy link

EC2, Auto Scaling and Load Balancing

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q51

InsufficientInstanceCapacity: We currently do not have sufficient m5.large capacity in the Availability Zone you requested (us-east-1a).

Beginner

Likely causes โ†’ AWS has no spare capacity for that instance type in that AZ right now. Your account is fine; this is not a quota problem.

Diagnose โ†’

bash
aws ec2 describe-instance-type-offerings --location-type availability-zone \
  --filters Name=instance-type,Values=m5.large --region us-east-1
aws autoscaling describe-scaling-activities --auto-scaling-group-name web-asg --max-items 5

Fix โ†’

  1. Retry in a few minutes or launch in another AZ
  2. Try a similar type (m6i.large, m5a.large, m7i.large)
  3. For an ASG, use a mixed instances policy with several types and subnets in every AZ

Prevent โ†’ Never pin critical workloads to one type in one AZ. For events where you know you will need capacity, buy an On-Demand Capacity Reservation.

Copy link
Q52

An instance shows 1/2 checks passed and you cannot reach it.

Beginner

Likely causes โ†’ If the system status check fails, the problem is AWS hardware or the host (power, network, physical host). If the instance status check fails, the problem is inside the OS: a kernel panic, a broken network config, a full disk or bad /etc/fstab.

Diagnose โ†’

bash
aws ec2 describe-instance-status --instance-ids i-0abc \
  --query 'InstanceStatuses[].[SystemStatus.Status,InstanceStatus.Status]'
aws ec2 get-console-output --instance-id i-0abc --latest --output text | tail -50
aws ec2 get-console-screenshot --instance-id i-0abc --query ImageData --output text | base64 -d > shot.jpg

Fix โ†’

  1. System check failed: stop and start the instance (not reboot), which moves it to new hardware
  2. Instance check failed: read the console output, then fix through the EC2 Serial Console or by attaching the root volume to a rescue instance

Prevent โ†’ Add a CloudWatch alarm on StatusCheckFailed_System with the recover action, and run stateless instances behind an ASG.

Copy link
Q53

VcpuLimitExceeded: You have requested more vCPU capacity than your current vCPU limit of 32 allows for the instance bucket that the specified instance type belongs to.

Beginner

Likely causes โ†’ You have hit the account's vCPU-based On-Demand quota for that instance family group in this Region (for example, "Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances").

Diagnose โ†’

bash
aws service-quotas get-service-quota --service-code ec2 --quota-code L-1216C47A
aws ec2 describe-instances --filters Name=instance-state-name,Values=running \
  --query 'Reservations[].Instances[].InstanceType' --output text | tr '\t' '\n' | sort | uniq -c

Fix โ†’

  1. Terminate unused instances
  2. Request an increase: aws service-quotas request-service-quota-increase --service-code ec2 --quota-code L-1216C47A --desired-value 128

Prevent โ†’ Watch quota usage with CloudWatch AWS/Usage metrics and Trusted Advisor. Raise quotas before launches and DR tests, not during them.

Copy link
Q54

A new instance goes pending โ†’ terminated within seconds with state reason Client.InternalError: Client error on launch.

Intermediate

Likely causes โ†’ Usually the EBS volumes are encrypted with a customer managed KMS key that the launching principal (or the ASG service-linked role) cannot use. It can also mean a snapshot is missing or the volume limit was exceeded.

Diagnose โ†’

bash
aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].StateReason'
aws ec2 describe-images --image-ids ami-0abc --query 'Images[].BlockDeviceMappings[].Ebs'
aws kms get-key-policy --key-id <key-id> --policy-name default

Fix โ†’

  1. Allow the launching principal and AWSServiceRoleForAutoScaling to use the key: kms:CreateGrant, kms:Decrypt, kms:GenerateDataKeyWithoutPlaintext, kms:ReEncrypt* and kms:DescribeKey
  2. For cross-account AMIs, update the key policy in the owning account and create a grant for the service-linked role

Prevent โ†’ Keep a tested key-policy template for EBS keys that names the ASG service-linked role.

Copy link
Q55

Session Manager: An error occurred (TargetNotConnected) when calling the StartSession operation: i-0abc is not connected.

Intermediate

Likely causes โ†’ The SSM Agent is not registered. Common reasons: the instance profile does not have AmazonSSMManagedInstanceCore, the private subnet has no NAT or ssm, ssmmessages and ec2messages endpoints, the agent is stopped, or IMDS is disabled.

Diagnose โ†’

bash
aws ssm describe-instance-information --filters Key=InstanceIds,Values=i-0abc
aws ec2 describe-iam-instance-profile-associations --filters Name=instance-id,Values=i-0abc
aws ec2 describe-vpc-endpoints --filters Name=vpc-id,Values=vpc-0abc --query 'VpcEndpoints[].ServiceName'
# on the box via serial console:
sudo systemctl status amazon-ssm-agent; sudo tail /var/log/amazon/ssm/amazon-ssm-agent.log

Fix โ†’

  1. Attach a role that has AmazonSSMManagedInstanceCore
  2. Add the three interface endpoints, with private DNS on and an SG that allows 443 from the instances
  3. Restart the agent, or turn on Default Host Management Configuration

Prevent โ†’ Bake the agent into AMIs and turn on Default Host Management Configuration across the organization.

Copy link
Q56

User data did not run: packages are missing and the app never started.

Intermediate

Likely causes โ†’ The script has no shebang, or it was saved with CRLF line endings. It may have failed part-way. Or it already ran once: by default, user data runs only on the first boot, so editing it on a stopped instance does nothing.

Diagnose โ†’

bash
aws ec2 describe-instance-attribute --instance-id i-0abc --attribute userData \
  --query UserData.Value --output text | base64 -d | head
sudo cat /var/log/cloud-init-output.log
sudo grep -i error /var/log/cloud-init.log
cloud-init status --long

Fix โ†’

  1. Start the script with #!/bin/bash and add set -euxo pipefail so failures show up
  2. Convert the file to LF line endings
  3. To re-run it for testing, run sudo cloud-init clean && sudo reboot

Prevent โ†’ Keep user data small: bootstrap a config tool or pull a versioned script. Better still, bake an AMI with Packer.

Copy link
Q57

curl http://169.254.169.254/latest/meta-data/ returns 401 - Unauthorized on a new instance.

Intermediate

Likely causes โ†’ The instance requires IMDSv2 (HttpTokens=required), and the request has no session token. Older SDKs and tools that only speak IMDSv1 break the same way.

Diagnose โ†’

bash
aws ec2 describe-instances --instance-ids i-0abc \
  --query 'Reservations[].Instances[].MetadataOptions'
TOKEN=$(curl -sX PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600')
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id

Fix โ†’

  1. Update scripts to use the token flow, and upgrade SDKs and agents
  2. For containers on the host, set HttpPutResponseHopLimit to 2: aws ec2 modify-instance-metadata-options --instance-id i-0abc --http-put-response-hop-limit 2

Prevent โ†’ Make IMDSv2 the default at account level (aws ec2 modify-instance-metadata-defaults), and track the MetadataNoToken metric before you enforce it.

Copy link
Q58

InvalidAMIID.NotFound: The image id '[ami-0abc123]' does not exist.

Beginner

Likely causes โ†’ AMI IDs are Regional, so the ID belongs to another Region. Other causes: the AMI was deregistered, or it is private and not shared with your account.

Diagnose โ†’

bash
aws configure get region
aws ec2 describe-images --image-ids ami-0abc123 --region eu-west-1
aws ec2 describe-image-attribute --image-id ami-0abc123 --attribute launchPermission

Fix โ†’

  1. Use the AMI ID for the right Region, or copy the AMI there: aws ec2 copy-image --source-region eu-west-1 --source-image-id ami-0abc123 --region us-east-1 --name app-v12
  2. Look up public AMIs through SSM parameters instead of hard-coding IDs: aws ssm get-parameter --name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64

Prevent โ†’ Resolve AMIs dynamically (SSM parameter or a data source filtered by tag) and copy golden AMIs to every Region you use.

Copy link
Q59

An ASG keeps launching and terminating instances in a loop; activity history says an instance was taken out of service in response to an ELB system health check failure.

Intermediate

Likely causes โ†’ The ASG uses ELB health checks, but the health check grace period is shorter than the app's boot time. It can also be a wrong health check path, or a target SG that does not allow traffic from the ALB.

Diagnose โ†’

bash
aws autoscaling describe-scaling-activities --auto-scaling-group-name web-asg --max-items 10
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names web-asg \
  --query 'AutoScalingGroups[].[HealthCheckType,HealthCheckGracePeriod]'
aws elbv2 describe-target-health --target-group-arn <tg-arn>

Fix โ†’

  1. Raise the grace period above the real boot time: aws autoscaling update-auto-scaling-group --auto-scaling-group-name web-asg --health-check-grace-period 300
  2. Fix the health check path and port, and the SG rule from the ALB SG
  3. To debug a live instance, suspend ReplaceUnhealthy for a while: aws autoscaling suspend-processes --auto-scaling-group-name web-asg --scaling-processes ReplaceUnhealthy

Prevent โ†’ Use a cheap /healthz endpoint, plus a lifecycle hook or warm pool for slow boots.

Copy link
Q60

ASG activity fails: Value (app-profile) for parameter iamInstanceProfile.name is invalid. Invalid IAM Instance Profile name.

Beginner

Likely causes โ†’ The instance profile does not exist, or it was just created and has not propagated yet. Another common cause: the role was created in the console with a different profile name, or created through the CLI without a profile.

Diagnose โ†’

bash
aws iam get-instance-profile --instance-profile-name app-profile
aws iam list-instance-profiles-for-role --role-name app-role

Fix โ†’

  1. Create the profile and add the role to it: aws iam create-instance-profile --instance-profile-name app-profile then aws iam add-role-to-instance-profile --instance-profile-name app-profile --role-name app-role
  2. Wait a few seconds after creating it, then retry the launch

Prevent โ†’ In IaC, create aws_iam_instance_profile explicitly and reference it, so the dependency order is correct.

Copy link
Q61

An ASG instance refresh fails with Instance refresh failed: ... could not maintain the minimum healthy percentage.

Advanced

Likely causes โ†’ New instances from the updated launch template never become healthy, so the refresh cannot replace more instances without dropping below MinHealthyPercentage. Typical reasons: a bad AMI, broken user data or a failing health check. A checkpoint or alarm-based rollback may also have stopped it.

Diagnose โ†’

bash
aws autoscaling describe-instance-refreshes --auto-scaling-group-name web-asg --max-records 1
aws autoscaling describe-scaling-activities --auto-scaling-group-name web-asg --max-items 10
aws elbv2 describe-target-health --target-group-arn <tg-arn> \
  --query 'TargetHealthDescriptions[].[Target.Id,TargetHealth.State,TargetHealth.Reason]'

Fix โ†’

  1. Roll back: aws autoscaling rollback-instance-refresh --auto-scaling-group-name web-asg, or cancel it and fix the template
  2. Debug one new instance (console output, cloud-init log), then start the refresh again with --preferences '{"MinHealthyPercentage":90,"InstanceWarmup":300,"AutoRollback":true}'

Prevent โ†’ Turn on AutoRollback with CloudWatch alarms, use checkpoints for canary-style refreshes, and test AMIs in staging first.

Copy link
Q62

ALB returns 502 Bad Gateway. Where do you look?

Intermediate

Likely causes โ†’ The target closed the connection, sent a malformed response, or reset during a request. Common reasons: the app crashed, or its keep-alive timeout is shorter than the ALB idle timeout (60s), so the target drops idle connections the ALB still reuses. A Lambda target that returns an invalid response also causes 502.

Diagnose โ†’

bash
aws cloudwatch get-metric-statistics --namespace AWS/ApplicationELB --metric-name HTTPCode_ELB_502_Count \
  --dimensions Name=LoadBalancer,Value=app/web/abc123 --statistics Sum --period 60 \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)
aws elbv2 describe-load-balancer-attributes --load-balancer-arn <alb-arn>
# access logs: elb_status_code=502 with target_status_code="-" means no response from target

Fix โ†’

  1. Set the app keep-alive timeout above the ALB idle timeout (for example, Node.js server.keepAliveTimeout = 65000, Nginx keepalive_timeout 75s)
  2. Fix the app crashes and response headers

Prevent โ†’ Turn on ALB access logs to S3 and alarm on the ratio of HTTPCode_ELB_5XX_Count to request count.

Copy link
Q63

ALB returns 504 Gateway Timeout on a report endpoint.

Intermediate

Likely causes โ†’ The target did not respond before the ALB idle timeout (60s by default). Either the request is too slow, or the target is unreachable (blocked by an SG or NACL), so the connection attempt times out.

Diagnose โ†’

bash
aws elbv2 describe-load-balancer-attributes --load-balancer-arn <alb-arn> \
  --query "Attributes[?Key=='idle_timeout.timeout_seconds']"
# access logs: high target_processing_time, or request_processing_time -1
aws cloudwatch get-metric-statistics --namespace AWS/ApplicationELB --metric-name TargetResponseTime \
  --dimensions Name=LoadBalancer,Value=app/web/abc123 --extended-statistics p99 --period 60 \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)

Fix โ†’

  1. As a short-term fix, raise the idle timeout: aws elbv2 modify-load-balancer-attributes --load-balancer-arn <arn> --attributes Key=idle_timeout.timeout_seconds,Value=180
  2. As the real fix, make long jobs asynchronous: return 202, process through a queue, and let the client poll or receive a webhook

Prevent โ†’ Track TargetResponseTime p99 per route, and keep synchronous requests well under the timeout.

Copy link
Q64

ALB returns 503 Service Temporarily Unavailable immediately.

Beginner

Likely causes โ†’ The target group behind the matched listener rule has no registered targets, or all of its targets are in AZs the ALB is not enabled in. If every target is unhealthy, the ALB "fails open" and still routes traffic, so 503 usually means no targets.

Diagnose โ†’

bash
aws elbv2 describe-rules --listener-arn <listener-arn> \
  --query 'Rules[].[Priority,Actions[0].TargetGroupArn]'
aws elbv2 describe-target-health --target-group-arn <tg-arn>
aws elbv2 describe-load-balancers --load-balancer-arns <alb-arn> --query 'LoadBalancers[].AvailabilityZones'

Fix โ†’

  1. Register targets, or attach the ASG or ECS service to the right target group
  2. Enable the ALB in the AZs where the targets run

Prevent โ†’ Alarm on HealthyHostCount < 1 per target group, and check that targets are attached in your IaC.

Copy link
Q65

Target health shows Target.ResponseCodeMismatch: Health checks failed with these codes: [404].

Intermediate

Likely causes โ†’ The health check path does not exist on the app, or it redirects (301/302) to HTTPS or a login page. By default, the matcher only accepts 200.

Diagnose โ†’

bash
aws elbv2 describe-target-groups --target-group-arns <tg-arn> \
  --query 'TargetGroups[].[HealthCheckPath,HealthCheckPort,Matcher.HttpCode]'
# from an instance in the same subnet:
curl -i http://10.0.1.25:8080/health

Fix โ†’

  1. Point the health check at a real endpoint: aws elbv2 modify-target-group --target-group-arn <tg-arn> --health-check-path /healthz
  2. Or widen the matcher if the endpoint legitimately returns another code: --matcher HttpCode=200-299

Prevent โ†’ Every service exposes an unauthenticated /healthz that does not redirect, and IaC defines it next to the target group.

Copy link
Q66

Target health shows Target.Timeout: Request timed out for every target.

Intermediate

Likely causes โ†’ The ALB cannot reach the targets. The usual reasons: the target SG does not allow the health check port from the ALB SG, a NACL blocks it, the app listens only on 127.0.0.1, or the health check uses the wrong port.

Diagnose โ†’

bash
aws elbv2 describe-target-health --target-group-arn <tg-arn>
aws ec2 describe-security-groups --group-ids <target-sg> --query 'SecurityGroups[].IpPermissions'
# on the target:
sudo ss -lntp | grep 8080      # 127.0.0.1:8080 means not reachable from the ALB

Fix โ†’

  1. Allow the app port from the ALB SG: aws ec2 authorize-security-group-ingress --group-id <target-sg> --protocol tcp --port 8080 --source-group <alb-sg>
  2. Bind the app to 0.0.0.0
  3. Check that the NACL allows the ephemeral return ports

Prevent โ†’ Use SG-to-SG references in IaC rather than CIDRs, and run Reachability Analyzer from the ALB ENI to the target.

Copy link
Q67

ALB access logs show many 460 responses and some 463. What do they mean?

Advanced

Likely causes โ†’ These are ALB-specific codes. 460 means the client closed the connection before the idle timeout ran out, usually because the client timeout is shorter than the backend latency. 463 means the X-Forwarded-For header has more than 30 IP addresses, usually from a proxy loop or a misbehaving client.

Diagnose โ†’

bash
aws s3 cp s3://alb-logs/AWSLogs/111111111111/elasticloadbalancing/us-east-1/2026/11/09/ . --recursive
zcat *.log.gz | awk '$9==460 {print $13,$14}' | sort | uniq -c | sort -rn | head   # method + URL
zcat *.log.gz | awk '$9==460 {print $7}' | sort -n | tail                         # target_processing_time

Fix โ†’

  1. For 460, find the slow endpoints and fix their latency, or align the client and SDK timeouts with the server
  2. For 463, find the proxy chain that keeps appending to XFF, and break the loop (for example, CloudFront โ†’ ALB โ†’ nginx โ†’ the same ALB)

Prevent โ†’ Load ALB logs into Athena with a saved table, and alarm on the p99 latency of the top routes.

Copy link
Q68

Creating an HTTPS listener fails with CertificateNotFound: Certificate 'arn:aws:acm:...' not found.

Intermediate

Likely causes โ†’ The ACM certificate is in a different Region from the ALB, it is still PENDING_VALIDATION, or the ARN belongs to another account.

Diagnose โ†’

bash
aws acm list-certificates --region us-east-1 \
  --query 'CertificateSummaryList[].[DomainName,Status,CertificateArn]'
aws acm describe-certificate --certificate-arn <arn> \
  --query 'Certificate.DomainValidationOptions[].[DomainName,ValidationStatus,ResourceRecord]'

Fix โ†’

  1. Request or import the certificate in the ALB's Region
  2. Finish DNS validation by creating the CNAME that ACM shows (Route 53 can do it in one click)
  3. Use the ISSUED ARN in the listener

Prevent โ†’ Manage certificates in IaC with aws_acm_certificate_validation, so the listener waits until the certificate is issued.

Copy link
Q69

Behind an NLB, one target gets most of the traffic while the others sit idle.

Advanced

Likely causes โ†’ An NLB balances per connection (flow hash), not per request. A few long-lived connections, such as gRPC, HTTP/2, WebSockets or pooled DB clients, stick to whichever target they first hit. Cross-zone load balancing is off by default on an NLB, so an AZ with fewer targets gets proportionally more load per target.

Diagnose โ†’

bash
aws elbv2 describe-load-balancer-attributes --load-balancer-arn <nlb-arn> \
  --query "Attributes[?Key=='load_balancing.cross_zone.enabled']"
aws elbv2 describe-target-health --target-group-arn <tg-arn>
# per-target ActiveFlowCount / NewFlowCount in CloudWatch (AWS/NetworkELB)

Fix โ†’

  1. Turn on cross-zone: aws elbv2 modify-load-balancer-attributes --load-balancer-arn <nlb-arn> --attributes Key=load_balancing.cross_zone.enabled,Value=true
  2. For HTTP/2 or gRPC, use an ALB, which balances per request. Or make clients recycle connections regularly (max connection age)
  3. Spread targets evenly across AZs

Prevent โ†’ Pick the LB for the protocol: an ALB for request-level balancing, an NLB for raw TCP, static IPs and very high throughput.

Copy link
Q70

Spot instances disappear and the state reason is Server.SpotInstanceTermination.

Intermediate

Likely causes โ†’ AWS reclaimed the Spot capacity. You get a 2-minute interruption notice, and possibly an earlier rebalance recommendation.

Diagnose โ†’

bash
aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].StateReason'
aws ec2 describe-spot-instance-requests --filters Name=instance-id,Values=i-0abc \
  --query 'SpotInstanceRequests[].Status'
# on the instance, the notice endpoint:
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/spot/instance-action

Fix โ†’

  1. Diversify across many instance types and all AZs, and use the price-capacity-optimized allocation strategy
  2. Handle the interruption notice: drain from the LB and checkpoint work. On EKS, use Karpenter or the Node Termination Handler
  3. Turn on Capacity Rebalancing on the ASG

Prevent โ†’ Run only stateless, interruptible workloads on Spot, and keep an On-Demand base capacity for the minimum.

Copy link
Q71

After a kernel update and reboot, the instance never comes back: status check fails and SSH times out.

Advanced

Likely causes โ†’ The new kernel or initramfs does not boot (missing NVMe or ENA modules), GRUB points at a bad entry, or /etc/fstab references a device that no longer exists.

Diagnose โ†’

bash
aws ec2 get-console-output --instance-id i-0abc --latest --output text | tail -80
# interactive: EC2 Serial Console (needs account-level enablement and a password user)
aws ec2 enable-serial-console-access
aws ec2-instance-connect send-serial-console-ssh-public-key --instance-id i-0abc --serial-port 0 --ssh-public-key file://key.pub

Fix โ†’

  1. Use the Serial Console to pick the previous kernel in GRUB, then fix it
  2. Or use a rescue instance: stop the instance, detach the root volume, attach it to a rescue instance in the same AZ, mount it, fix grub or fstab (nofail, UUIDs), then reattach as /dev/xvda and start
  3. AWSSupport-ExecuteEC2Rescue automation can do this for you

Prevent โ†’ Patch through AMI rebuilds and rolling replacement instead of in place, and take snapshots before kernel changes.

Copy link
Q72

Changing an old instance to c5.large fails: Enhanced networking with the Elastic Network Adapter (ENA) is required for the 'c5.large' instance type. Ensure that your instance 'i-0abc' is enabled for ENA.

Advanced

Likely causes โ†’ The instance came from an old AMI built for Xen (for example m4 or t2). Nitro types need the ENA driver for networking and NVMe drivers for EBS, and the instance attribute enaSupport must be true.

Diagnose โ†’

bash
aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].EnaSupport'
# on the instance:
modinfo ena; lsmod | grep -E 'ena|nvme'

Fix โ†’

  1. Install or confirm the ENA and NVMe drivers inside the OS, and add them to the initramfs
  2. Stop the instance and run aws ec2 modify-instance-attribute --instance-id i-0abc --ena-support
  3. Change the type, and change /etc/fstab to use UUIDs, because device names become /dev/nvme*

Prevent โ†’ Use current AMIs (AL2023, Ubuntu 22.04/24.04) and move off previous-generation types in planned windows.

Copy link
Q73

A t3.medium web server becomes slow every afternoon, but CPU never goes above ~20%.

Beginner

Likely causes โ†’ The instance is a burstable type in standard credit mode. Once CPUCreditBalance reaches 0, it is throttled to its baseline (20% for t3.medium). CloudWatch then shows CPU flat at the baseline.

Diagnose โ†’

bash
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUCreditBalance \
  --dimensions Name=InstanceId,Value=i-0abc --statistics Minimum --period 300 \
  --start-time $(date -u -d '-1 day' +%FT%TZ) --end-time $(date -u +%FT%TZ)
aws ec2 describe-instance-credit-specifications --instance-ids i-0abc

Fix โ†’

  1. Switch to unlimited mode: aws ec2 modify-instance-credit-specification --instance-credit-specification 'InstanceId=i-0abc,CpuCredits=unlimited' (you pay for surplus credits)
  2. Or move to a fixed-performance type (m7i, c7g) if the load is sustained

Prevent โ†’ Alarm on CPUCreditBalance and use T instances only for workloads that really are bursty.

Copy link
Q74

During scale-in, the ASG terminates instances in the middle of long batch jobs.

Advanced

Likely causes โ†’ Scale-in picks instances using the termination policy and knows nothing about the work on them. Without lifecycle hooks or protection, jobs are killed.

Diagnose โ†’

bash
aws autoscaling describe-scaling-activities --auto-scaling-group-name workers --max-items 10
aws autoscaling describe-lifecycle-hooks --auto-scaling-group-name workers
aws autoscaling describe-auto-scaling-instances --query 'AutoScalingInstances[].[InstanceId,ProtectedFromScaleIn]'

Fix โ†’

  1. The worker sets scale-in protection while it is busy: aws autoscaling set-instance-protection --instance-ids i-0abc --auto-scaling-group-name workers --protected-from-scale-in (and clears it when done)
  2. Add a autoscaling:EC2_INSTANCE_TERMINATING lifecycle hook. The instance finishes or checkpoints its job, then calls complete-lifecycle-action
  3. Scale on queue depth per instance instead of CPU

Prevent โ†’ Design jobs to be idempotent and checkpointed, and size the hook HeartbeatTimeout to the longest job.

Copy link
Q75

You updated the launch template with a new AMI, but new ASG instances still boot the old AMI.

Beginner

Likely causes โ†’ The ASG references a specific template version, or $Default, and you created a new version without making it the default. New versions are not used until the ASG points at them.

Diagnose โ†’

bash
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names web-asg \
  --query 'AutoScalingGroups[].[LaunchTemplate,MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification]'
aws ec2 describe-launch-template-versions --launch-template-id lt-0abc \
  --query 'LaunchTemplateVersions[].[VersionNumber,DefaultVersion,LaunchTemplateData.ImageId]'

Fix โ†’

  1. Point the ASG at $Latest, or set the new version as default: aws ec2 modify-launch-template --launch-template-id lt-0abc --default-version 7
  2. Start an instance refresh to replace the instances that are already running

Prevent โ†’ Have the pipeline create the version, update the ASG and start an instance refresh in one step.

Copy link

S3, EBS and EFS

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q76

BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system.

Beginner

Likely causes โ†’ S3 bucket names are global across all AWS accounts, and another account already owns this name. If you own it, you get BucketAlreadyOwnedByYou instead. That error is common when IaC re-runs a create in a different Region.

Diagnose โ†’

bash
aws s3api head-bucket --bucket my-app-logs   # 403 = exists in someone else's account, 404 = free
aws s3api list-buckets --query "Buckets[?Name=='my-app-logs']"

Fix โ†’

  1. Pick a unique name, for example with the account ID and Region: my-app-logs-111111111111-us-east-1
  2. For BucketAlreadyOwnedByYou, import the bucket into state instead of creating it

Prevent โ†’ Use a naming convention with the account and Region in it, or the S3 account-regional namespace option where it is available. Never rely on a deleted name being free again.

Copy link
Q77

PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint.

Beginner

Likely causes โ†’ The client is calling the wrong Regional endpoint for this bucket, usually because the profile Region is different from the bucket's Region, or an old SDK hard-codes s3.amazonaws.com.

Diagnose โ†’

bash
aws s3api get-bucket-location --bucket my-bucket     # null LocationConstraint = us-east-1
aws configure get region
aws s3 ls s3://my-bucket --debug 2>&1 | grep -i 'x-amz-bucket-region'

Fix โ†’

  1. Pass the right Region: aws s3 ls s3://my-bucket --region eu-central-1
  2. Configure the SDK client with the bucket's Region

Prevent โ†’ Keep Region per environment in config, and include the Region in bucket names to make mismatches obvious.

Copy link
Q78

A partner account uploads objects into your bucket, but your own admins get 403 Forbidden reading them.

Intermediate

Likely causes โ†’ Object Ownership is ObjectWriter (the legacy setting), so the uploading account owns the objects and the bucket policy cannot grant access to them. This happens when the uploader did not set bucket-owner-full-control.

Diagnose โ†’

bash
aws s3api get-bucket-ownership-controls --bucket shared-ingest
aws s3api get-object-acl --bucket shared-ingest --key incoming/file.csv

Fix โ†’

  1. Turn on Bucket owner enforced (ACLs disabled): aws s3api put-bucket-ownership-controls --bucket shared-ingest --ownership-controls 'Rules=[{ObjectOwnership=BucketOwnerEnforced}]'
  2. That takes ownership of all objects, including existing ones. Re-check the bucket policy grants

Prevent โ†’ Use BucketOwnerEnforced everywhere (the default for new buckets since 2023), and control access only through policies.

Copy link
Q79

aws s3 cp gets An error occurred (AccessDenied) when calling the GetObject operation but the IAM policy allows s3:GetObject and the bucket policy is fine.

Intermediate

Likely causes โ†’ The object is encrypted with SSE-KMS using a customer managed key, and the caller has no kms:Decrypt on that key (through the key policy or IAM). For uploads, the missing permission is kms:GenerateDataKey.

Diagnose โ†’

bash
aws s3api head-object --bucket data --key reports/q3.parquet \
  --query '[ServerSideEncryption,SSEKMSKeyId]'
aws kms get-key-policy --key-id <key-arn> --policy-name default --output text
# CloudTrail: look for kms Decrypt with errorCode AccessDenied

Fix โ†’

  1. Grant kms:Decrypt on the key ARN to the role in IAM, and make sure the key policy allows IAM policies (the root principal statement) or names the role
  2. For cross-account access, both the key policy and the caller's IAM policy must allow it

Prevent โ†’ Every S3 access policy template includes the matching KMS statement, and S3 Bucket Keys are on to reduce KMS calls.

Copy link
Q80

An S3 static website endpoint returns 403 Forbidden with Code: AccessDenied.

Intermediate

Likely causes โ†’ Block Public Access is on at the account or bucket level, or no bucket policy grants s3:GetObject to *. Also check that the index document exists exactly as named (keys are case-sensitive) and that objects are not KMS-encrypted (website endpoints cannot serve SSE-KMS objects).

Diagnose โ†’

bash
aws s3control get-public-access-block --account-id 111111111111
aws s3api get-public-access-block --bucket my-site
aws s3api get-bucket-policy --bucket my-site
aws s3api get-bucket-website --bucket my-site
aws s3 ls s3://my-site/index.html

Fix โ†’

  1. In production, keep the bucket private and put CloudFront with OAC in front of it
  2. If a public website endpoint is truly intended, turn off BPA for that bucket only and add a read-only public policy for arn:aws:s3:::my-site/*

Prevent โ†’ Keep account-level BPA on, and serve all public content through CloudFront.

Copy link
Q81

High-throughput writes get 503 SlowDown: Please reduce your request rate.

Intermediate

Likely causes โ†’ You are above the per-prefix request rate (about 3,500 PUT/COPY/POST/DELETE and 5,500 GET/HEAD per second per partitioned prefix), and S3 has not repartitioned yet. All writes going to one hot prefix such as logs/2026-11-09/ make it worse.

Diagnose โ†’

bash
aws s3api put-bucket-metrics-configuration --bucket data --id all --metrics-configuration Id=all
# then CloudWatch AWS/S3 metrics: AllRequests, 5xxErrors per FilterId
aws s3api list-objects-v2 --bucket data --prefix logs/2026-11-09/ --max-items 5

Fix โ†’

  1. Retry with exponential backoff. SDK retries do this, and adaptive mode helps
  2. Spread keys across more prefixes (for example, a hash or shard prefix)
  3. Batch small objects into larger ones

Prevent โ†’ Design key layouts for parallelism, and ramp traffic up gradually so S3 can scale partitions.

Copy link
Q82

BucketNotEmpty: The bucket you tried to delete is not empty. You must delete all versions in the bucket. even after aws s3 rm --recursive.

Beginner

Likely causes โ†’ Versioning is on. aws s3 rm only adds delete markers, and all older versions and delete markers remain.

Diagnose โ†’

bash
aws s3api get-bucket-versioning --bucket old-bucket
aws s3api list-object-versions --bucket old-bucket --max-items 5

Fix โ†’

  1. For small buckets, delete versions in batches:
bash
aws s3api list-object-versions --bucket old-bucket \
  --query '{Objects: [Versions[].{Key:Key,VersionId:VersionId}, DeleteMarkers[].{Key:Key,VersionId:VersionId}][]}' \
  --max-items 1000 --output json > del.json
aws s3api delete-objects --bucket old-bucket --delete file://del.json
  1. For big buckets, add a lifecycle rule that expires current and noncurrent versions and delete markers, wait a day, then delete the bucket

Prevent โ†’ In IaC, use force_destroy only for ephemeral buckets, and give every versioned bucket a noncurrent-version lifecycle rule.

Copy link
Q83

A browser upload to S3 fails: has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Intermediate

Likely causes โ†’ The bucket has no CORS configuration, or it does not list the origin, method (PUT/POST) or headers the browser sends in the preflight. Presigned PUTs with custom headers such as Content-Type need AllowedHeaders.

Diagnose โ†’

bash
aws s3api get-bucket-cors --bucket uploads
curl -i -X OPTIONS "https://uploads.s3.amazonaws.com/test.txt" \
  -H 'Origin: https://app.example.com' -H 'Access-Control-Request-Method: PUT'

Fix โ†’

bash
aws s3api put-bucket-cors --bucket uploads --cors-configuration '{
 "CORSRules":[{"AllowedOrigins":["https://app.example.com"],"AllowedMethods":["PUT","GET"],
 "AllowedHeaders":["*"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3000}]}'

If CloudFront is in front, forward the Origin header in the origin request policy.

Prevent โ†’ Keep the CORS config in IaC with explicit origins per environment. Never use * together with credentials.

Copy link
Q84

Presigned URLs return SignatureDoesNotMatch for some users and Request has expired for others.

Intermediate

Likely causes โ†’ SignatureDoesNotMatch means the request is different from what was signed: another HTTP method, a missing Content-Type, the wrong Region endpoint, or the URL was re-encoded. Request has expired means the expiry passed, or the URL was signed with temporary role credentials that expired earlier (a URL is valid only as long as the signing credentials).

Diagnose โ†’

bash
aws s3 presign s3://bucket/file.zip --expires-in 3600 --region us-east-1
# inspect X-Amz-Expires, X-Amz-Date, X-Amz-Credential in the URL
aws sts get-caller-identity   # signed with a role session? check its expiry

Fix โ†’

  1. Sign with the exact method and headers the client will send, using a Regional endpoint
  2. For long-lived links, sign with credentials that last at least as long. SigV4 allows a maximum of 7 days
  3. Fix client clock skew

Prevent โ†’ Generate URLs on demand with a short expiry, and serve large public downloads through CloudFront signed URLs.

Copy link
Q85

S3 Cross-Region Replication is configured, but new objects show ReplicationStatus: FAILED.

Advanced

Likely causes โ†’ The replication role does not have s3:ReplicateObject on the destination, or the destination bucket policy does not allow the role (cross-account). Objects are SSE-KMS but the rule has no SseKmsEncryptedObjects or KMS permissions in the destination Region. Versioning is off on one side. Or Object Lock is in use without the right configuration.

Diagnose โ†’

bash
aws s3api get-bucket-replication --bucket src
aws s3api head-object --bucket src --key path/obj --query ReplicationStatus
aws s3api get-bucket-versioning --bucket dst
# enable replication metrics + S3 event notifications for s3:Replication:OperationFailedReplication

Fix โ†’

  1. Fix the role permissions (source read, destination replicate, KMS decrypt on the source key and encrypt on the destination key)
  2. Fix the destination bucket policy for cross-account
  3. Re-replicate the failed and existing objects with S3 Batch Replication

Prevent โ†’ Turn on Replication Time Control metrics and alarm on OperationsFailedReplication.

Copy link
Q86

A lifecycle rule "expire after 30 days" has been on for months, yet storage is still growing.

Intermediate

Likely causes โ†’ The bucket is versioned. Expiring current objects only adds delete markers, so noncurrent versions build up. Other causes: the rule's prefix or tag filter does not match the keys, or the objects are below the minimum size for transitions.

Diagnose โ†’

bash
aws s3api get-bucket-lifecycle-configuration --bucket logs
aws s3api get-bucket-versioning --bucket logs
aws s3api list-object-versions --bucket logs --prefix app/ --max-items 10 \
  --query 'Versions[?IsLatest==`false`].[Key,LastModified]'

Fix โ†’ Add NoncurrentVersionExpiration (for example, after 7 days) and ExpiredObjectDeleteMarker: true. Correct the filter prefix.

Prevent โ†’ Use S3 Storage Lens to watch noncurrent bytes per bucket, and use one standard lifecycle template for versioned buckets.

Copy link
Q87

The bill shows far more S3 storage than aws s3 ls --summarize reports.

Advanced

Likely causes โ†’ Incomplete multipart uploads (the parts are stored and billed, but ls does not show them), noncurrent versions, or storage-class overhead (minimum object size and duration charges for IA and Glacier).

Diagnose โ†’

bash
aws s3api list-multipart-uploads --bucket data --query 'Uploads[].[Key,Initiated]' --output table
aws cloudwatch get-metric-statistics --namespace AWS/S3 --metric-name BucketSizeBytes \
  --dimensions Name=BucketName,Value=data Name=StorageType,Value=StandardStorage \
  --statistics Average --period 86400 --start-time $(date -u -d '-3 day' +%FT%TZ) --end-time $(date -u +%FT%TZ)

Fix โ†’

  1. Abort stale uploads: aws s3api abort-multipart-upload --bucket data --key <key> --upload-id <id>
  2. Add a lifecycle rule with AbortIncompleteMultipartUpload DaysAfterInitiation: 7

Prevent โ†’ Put that lifecycle rule on every bucket by default, and use Storage Lens for "incomplete MPU bytes".

Copy link
Q88

s3api put-object fails: EntityTooLarge: Your proposed upload exceeds the maximum allowed size.

Beginner

Likely causes โ†’ One PUT can be at most 5 GB. aws s3api put-object does a single PUT, while aws s3 cp switches to multipart automatically. Objects larger than that can only be uploaded with multipart upload.

Diagnose โ†’

bash
ls -lh backup.tar
aws configure get default.s3.multipart_threshold

Fix โ†’

  1. Use aws s3 cp backup.tar s3://bucket/ (multipart, parallel parts)
  2. Tune it for speed: aws configure set default.s3.multipart_chunksize 64MB and max_concurrent_requests 20

Prevent โ†’ Use the high-level transfer managers (CLI s3 cp, SDK TransferManager) for anything larger than about 100 MB.

Copy link
Q89

Someone added a bucket policy with "Effect":"Deny" unless aws:SourceVpce matches. Now even admins get AccessDenied, including on PutBucketPolicy.

Advanced

Likely causes โ†’ An explicit deny in the bucket policy beats every allow, including admin IAM policies. Calls from outside the VPC endpoint (console, laptop CLI) are denied, and that includes changing the policy.

Diagnose โ†’

bash
aws s3api get-bucket-policy --bucket locked --output text   # likely denied too
# CloudTrail: GetBucketPolicy / PutBucketPolicy errorCode AccessDenied

Fix โ†’

  1. Call from a principal that matches the condition, for example an instance in the VPC that uses that endpoint, and run aws s3api delete-bucket-policy --bucket locked
  2. If nothing can match, sign in as the account root user, which can always delete a bucket policy that locks it out (with Organizations, the management account can use centralized root access for member accounts)

Prevent โ†’ Always exempt a break-glass role in deny conditions (aws:PrincipalArn with StringNotLike), and test policies with Access Analyzer policy validation before applying them.

Copy link
Q90

You attached a new EBS volume, but df -h does not show it and /dev/sdf does not exist.

Beginner

Likely causes โ†’ Attaching a volume does not format or mount it. On Nitro instances, the device shows up as /dev/nvme1n1, not /dev/sdf.

Diagnose โ†’

bash
aws ec2 describe-volumes --volume-ids vol-0abc --query 'Volumes[].Attachments'
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,SERIAL     # SERIAL shows vol0abc...
sudo file -s /dev/nvme1n1                       # "data" = no filesystem

Fix โ†’

bash
sudo mkfs -t xfs /dev/nvme1n1
sudo mkdir -p /data && sudo mount /dev/nvme1n1 /data
echo "UUID=$(sudo blkid -s UUID -o value /dev/nvme1n1) /data xfs defaults,nofail 0 2" | sudo tee -a /etc/fstab

Prevent โ†’ Use UUIDs and nofail in fstab, and do the formatting in user data or configuration management.

Copy link
Q91

You grew an EBS volume from 20 to 50 GiB, but the server still says No space left on device.

Beginner

Likely causes โ†’ You resized the volume, but not the partition and filesystem inside it.

Diagnose โ†’

bash
aws ec2 describe-volumes-modifications --volume-ids vol-0abc --query 'VolumesModifications[].ModificationState'
lsblk                 # disk 50G, partition still 20G
df -hT /

Fix โ†’

bash
sudo growpart /dev/nvme0n1 1
sudo xfs_growfs -d /          # XFS (Amazon Linux)
# or
sudo resize2fs /dev/nvme0n1p1 # ext4 (Ubuntu)

If df shows the disk is not full, check inodes: df -i.

Prevent โ†’ Alarm on disk usage from the CloudWatch agent (disk_used_percent), and send logs off-box so they do not fill the disk.

Copy link
Q92

modify-volume fails: You've reached the maximum modification rate per volume limit. Wait at least 6 hours between modifications per EBS volume.

Intermediate

Likely causes โ†’ EBS allows one modification per volume every 6 hours, and the previous change must have reached completed or optimizing.

Diagnose โ†’

bash
aws ec2 describe-volumes-modifications --volume-ids vol-0abc \
  --query 'VolumesModifications[].[ModificationState,StartTime,EndTime,TargetSize,TargetIops]'

Fix โ†’

  1. If you need space now, attach a second volume and extend with LVM, or move data out
  2. Otherwise wait, and change size, IOPS and throughput in one call: aws ec2 modify-volume --volume-id vol-0abc --size 200 --iops 6000 --throughput 500

Prevent โ†’ Right-size with headroom, and batch all attribute changes into one modification.

Copy link
Q93

InvalidVolume.ZoneMismatch: The volume 'vol-0abc' is not in the same availability zone as instance 'i-0def'.

Beginner

Likely causes โ†’ An EBS volume exists in one AZ and can only attach to instances in that AZ.

Diagnose โ†’

bash
aws ec2 describe-volumes --volume-ids vol-0abc --query 'Volumes[].AvailabilityZone'
aws ec2 describe-instances --instance-ids i-0def --query 'Reservations[].Instances[].Placement.AvailabilityZone'

Fix โ†’

bash
aws ec2 create-snapshot --volume-id vol-0abc --description move-az
aws ec2 create-volume --snapshot-id snap-0123 --availability-zone us-east-1b --volume-type gp3

Then attach the new volume.

Prevent โ†’ Keep shared or portable data on EFS or S3, and pin stateful instances (and their ASG subnets) to the AZ of their volumes.

Copy link
Q94

A database on gp2 is fast in the morning, then latency jumps and VolumeQueueLength climbs.

Advanced

Likely causes โ†’ gp2 gets baseline IOPS at 3 per GiB (minimum 100) and bursts to 3,000 IOPS from a credit bucket. Once BurstBalance reaches 0, the volume falls back to baseline. Another possibility is the instance's EBS bandwidth limit (EBSIOBalance% / EBSByteBalance% on smaller instances).

Diagnose โ†’

bash
for m in BurstBalance VolumeQueueLength VolumeReadOps VolumeWriteOps; do
aws cloudwatch get-metric-statistics --namespace AWS/EBS --metric-name $m \
  --dimensions Name=VolumeId,Value=vol-0abc --statistics Average --period 300 \
  --start-time $(date -u -d '-6 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ) --output text | tail -3; done

Fix โ†’

  1. Migrate online to gp3, which gives 3,000 IOPS and 125 MiB/s baseline independent of size: aws ec2 modify-volume --volume-id vol-0abc --volume-type gp3 --iops 6000 --throughput 250
  2. If the instance is the bottleneck, move to an instance type with more EBS bandwidth

Prevent โ†’ Use gp3 as the default volume type and alarm on queue length and latency (VolumeAverageReadLatency).

Copy link
Q95

A volume restored from a snapshot is very slow for the first hour of a DR test.

Advanced

Likely causes โ†’ Snapshot restores are lazy-loaded: each block is fetched from S3 the first time it is read, so first reads have high latency.

Diagnose โ†’

bash
aws ec2 describe-fast-snapshot-restores --filters Name=snapshot-id,Values=snap-0abc
# on the instance: high await on first reads
iostat -x 5

Fix โ†’

  1. Pre-warm by reading every block: sudo fio --filename=/dev/nvme1n1 --rw=read --bs=1M --iodepth=32 --ioengine=libaio --direct=1 --name=init
  2. For critical paths, turn on Fast Snapshot Restore (paid per AZ-hour): aws ec2 enable-fast-snapshot-restores --availability-zones us-east-1a --source-snapshot-ids snap-0abc
  3. Or use a provisioned initialization rate where supported

Prevent โ†’ Count hydration time in your RTO, and test DR with real reads, not just "the instance is running".

Copy link
Q96

Sharing an EBS snapshot with the DR account fails because it is encrypted with the default aws/ebs key.

Intermediate

Likely causes โ†’ You cannot share snapshots encrypted with the AWS managed key, because its key policy cannot be changed to grant other accounts.

Diagnose โ†’

bash
aws ec2 describe-snapshots --snapshot-ids snap-0abc --query 'Snapshots[].[Encrypted,KmsKeyId]'
aws kms describe-key --key-id <key-id> --query 'KeyMetadata.KeyManager'   # AWS = managed key

Fix โ†’

  1. Copy the snapshot and re-encrypt it with a customer managed key: aws ec2 copy-snapshot --source-region us-east-1 --source-snapshot-id snap-0abc --encrypted --kms-key-id <cmk-arn>
  2. Allow the DR account in the CMK key policy, then share: aws ec2 modify-snapshot-attribute --snapshot-id snap-0new --attribute createVolumePermission --operation-type add --user-ids 222222222222
  3. In the DR account, copy it again with its own key

Prevent โ†’ Set EBS default encryption to a CMK (aws ec2 modify-ebs-default-kms-key-id), or use AWS Backup cross-account copy.

Copy link
Q97

mount -t efs hangs, then fails with mount.nfs4: Connection timed out.

Beginner

Likely causes โ†’ The mount target's SG does not allow NFS (TCP 2049) from the client, there is no mount target in the client's AZ, or DNS resolution of the file system name is off in the VPC.

Diagnose โ†’

bash
aws efs describe-mount-targets --file-system-id fs-0abc --query 'MountTargets[].[AvailabilityZoneName,IpAddress,LifeCycleState]'
aws efs describe-mount-target-security-groups --mount-target-id fsmt-0abc
nc -zv fs-0abc.efs.us-east-1.amazonaws.com 2049

Fix โ†’

  1. Allow TCP 2049 from the client SG on the mount target SG
  2. Create a mount target in every AZ where clients run
  3. Turn on enableDnsSupport and enableDnsHostnames on the VPC

Prevent โ†’ Create mount targets for every AZ in IaC, and use amazon-efs-utils with _netdev,tls in fstab.

Copy link
Q98

mount.nfs4: access denied by server while mounting fs-0abc.efs....

Intermediate

Likely causes โ†’ An EFS file system policy requires IAM authorization or TLS, and the mount did not use -o tls,iam. Or the client role has no elasticfilesystem:ClientMount/ClientWrite. Or an access point's root directory or POSIX user does not match what is expected.

Diagnose โ†’

bash
aws efs describe-file-system-policy --file-system-id fs-0abc
aws efs describe-access-points --file-system-id fs-0abc

Fix โ†’

  1. Mount with efs-utils: sudo mount -t efs -o tls,iam,accesspoint=fsap-0abc fs-0abc:/ /mnt/efs
  2. Grant the instance or task role elasticfilesystem:ClientMount and ClientWrite (plus ClientRootAccess if needed)

Prevent โ†’ Standardize on access points per app, with IAM auth and TLS required by policy.

Copy link
Q99

An app on EFS slows to a crawl under load; PercentIOLimit sits at 100% or throughput flat-lines.

Advanced

Likely causes โ†’ In Bursting mode, throughput depends on stored size, and BurstCreditBalance has run out. PercentIOLimit at 100% means the file system has hit the I/O operation limit for General Purpose performance mode. Lots of small-file metadata operations also have high per-operation latency on NFS.

Diagnose โ†’

bash
aws efs describe-file-systems --file-system-id fs-0abc --query 'FileSystems[].[ThroughputMode,PerformanceMode,SizeInBytes.Value]'
# CloudWatch AWS/EFS: BurstCreditBalance, PermittedThroughput, MeteredIOBytes, PercentIOLimit

Fix โ†’

  1. Switch to Elastic throughput: aws efs update-file-system --file-system-id fs-0abc --throughput-mode elastic
  2. Spread I/O across more clients and threads, and avoid hot ls loops over huge directories
  3. Cache read-heavy content locally

Prevent โ†’ Use Elastic throughput by default for spiky workloads, and keep databases off EFS.

Copy link
Q100

put-bucket-notification-configuration fails: Unable to validate the following destination configurations.

Intermediate

Likely causes โ†’ S3 checks that it may publish to the destination. The Lambda has no resource policy allowing s3.amazonaws.com, or the SNS topic or SQS queue policy does not allow S3, or the destination's KMS key does not let S3 use it.

Diagnose โ†’

bash
aws lambda get-policy --function-name thumbnailer
aws sqs get-queue-attributes --queue-url <url> --attribute-names Policy KmsMasterKeyId

Fix โ†’

bash
aws lambda add-permission --function-name thumbnailer --statement-id s3invoke \
  --action lambda:InvokeFunction --principal s3.amazonaws.com \
  --source-arn arn:aws:s3:::uploads --source-account 111111111111

For SQS or SNS, add a policy statement for s3.amazonaws.com with an aws:SourceArn condition. With SSE, the key policy must allow S3 kms:GenerateDataKey and kms:Decrypt.

Prevent โ†’ Create the permission and the notification together in IaC (with depends_on), or route events through EventBridge.

Copy link

RDS, Aurora and DynamoDB

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q101

The app cannot connect to RDS: psql: error: connection to server at "mydb.abc.us-east-1.rds.amazonaws.com" (10.0.3.12), port 5432 failed: Connection timed out.

Beginner

Likely causes โ†’ A timeout means the packets are dropped. The DB SG does not allow 5432 from the app SG, a NACL blocks it, or the client is outside the VPC (for example, a laptop) while the DB is not publicly accessible (which is how it should be).

Diagnose โ†’

bash
aws rds describe-db-instances --db-instance-identifier mydb \
  --query 'DBInstances[].[Endpoint.Address,Endpoint.Port,PubliclyAccessible,VpcSecurityGroups,DBSubnetGroup.Subnets[].SubnetIdentifier]'
nc -zv mydb.abc.us-east-1.rds.amazonaws.com 5432
aws ec2 describe-security-groups --group-ids <db-sg> --query 'SecurityGroups[].IpPermissions'

Fix โ†’

  1. Allow 5432 on the DB SG from the app SG
  2. From a laptop, use SSM port forwarding through a bastion: aws ssm start-session --target i-0abc --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters host=mydb...,portNumber=5432,localPortNumber=5432

Prevent โ†’ Keep databases in private subnets and grant access by SG reference only.

Copy link
Q102

FATAL: password authentication failed for user "postgres" and nobody knows the master password.

Beginner

Likely causes โ†’ The password is wrong or was rotated (Secrets Manager managed password), or the username is wrong. The master username is set at creation and is not always postgres.

Diagnose โ†’

bash
aws rds describe-db-instances --db-instance-identifier mydb \
  --query 'DBInstances[].[MasterUsername,MasterUserSecret.SecretArn]'
aws secretsmanager get-secret-value --secret-id <secret-arn> --query SecretString --output text

Fix โ†’

  1. If RDS manages the secret, read the current value from Secrets Manager
  2. Otherwise reset the password: aws rds modify-db-instance --db-instance-identifier mydb --master-user-password '<new>' --apply-immediately
  3. Update the apps, and restart connection pools

Prevent โ†’ Use --manage-master-user-password so RDS stores and rotates the password in Secrets Manager, and give apps their own least-privilege DB users.

Copy link
Q103

FATAL: no pg_hba.conf entry for host "10.0.1.25", user "app", database "orders", no encryption.

Intermediate

Likely causes โ†’ The parameter group sets rds.force_ssl=1 (the default for RDS PostgreSQL 15+), and the client connects without TLS. You cannot edit pg_hba.conf on RDS; it is controlled through parameters.

Diagnose โ†’

bash
aws rds describe-db-parameters --db-parameter-group-name pg16-app \
  --query "Parameters[?ParameterName=='rds.force_ssl']"

Fix โ†’

  1. Connect with TLS: psql "host=... dbname=orders user=app sslmode=verify-full sslrootcert=global-bundle.pem"
  2. Download the CA bundle: curl -O https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
  3. Set sslmode=require or verify-full in the app's JDBC or driver URL

Prevent โ†’ Require TLS everywhere, and ship the RDS CA bundle in your base images.

Copy link
Q104

App logs show FATAL: remaining connection slots are reserved for non-replication superuser connections (or MySQL ERROR 1040 (HY000): Too many connections).

Intermediate

Likely causes โ†’ You have hit max_connections. Usually too many app replicas each open a large pool, or Lambda functions open a new connection per invocation, or connections leak.

Diagnose โ†’

bash
aws cloudwatch get-metric-statistics --namespace AWS/RDS --metric-name DatabaseConnections \
  --dimensions Name=DBInstanceIdentifier,Value=mydb --statistics Maximum --period 60 \
  --start-time $(date -u -d '-2 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)
psql -c "select usename, application_name, state, count(*) from pg_stat_activity group by 1,2,3 order by 4 desc;"

Fix โ†’

  1. Shrink the pool per pod: total = replicas ร— pool size, which must stay under max_connections
  2. Put RDS Proxy (or PgBouncer) in front for Lambda and bursty clients
  3. Kill idle connections and set idle_in_transaction_session_timeout

Prevent โ†’ Budget connections per service, alarm at 80% of max, and use RDS Proxy for serverless callers.

Copy link
Q105

RDS status shows storage-full and writes fail.

Intermediate

Likely causes โ†’ FreeStorageSpace reached zero. Common reasons: growing tables, unvacuumed bloat, a large temp sort, binlogs or WAL kept by a stalled replication slot, or verbose logs.

Diagnose โ†’

bash
aws cloudwatch get-metric-statistics --namespace AWS/RDS --metric-name FreeStorageSpace \
  --dimensions Name=DBInstanceIdentifier,Value=mydb --statistics Minimum --period 300 \
  --start-time $(date -u -d '-1 day' +%FT%TZ) --end-time $(date -u +%FT%TZ)
psql -c "select slot_name, active, pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) from pg_replication_slots;"

Fix โ†’

  1. Add storage now: aws rds modify-db-instance --db-instance-identifier mydb --allocated-storage 500 --apply-immediately
  2. Drop stale replication slots, and vacuum or clean up data
  3. Turn on storage autoscaling: --max-allocated-storage 1000

Prevent โ†’ Alarm on FreeStorageSpace below 20%, turn on autoscaling, and alarm on OldestReplicationSlotLag / TransactionLogsDiskUsage.

Copy link
Q106

A read replica's ReplicaLag keeps growing and reports show stale data.

Intermediate

Likely causes โ†’ The replica is smaller than the primary, or IOPS-bound. Heavy write bursts or long-running queries on the replica cause conflicts (PostgreSQL max_standby_streaming_delay). MySQL replication may apply single-threaded.

Diagnose โ†’

bash
aws cloudwatch get-metric-statistics --namespace AWS/RDS --metric-name ReplicaLag \
  --dimensions Name=DBInstanceIdentifier,Value=mydb-replica --statistics Maximum --period 60 \
  --start-time $(date -u -d '-3 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)
aws rds describe-db-instances --db-instance-identifier mydb-replica --query 'DBInstances[].[DBInstanceClass,StorageType,Iops]'

Fix โ†’

  1. Size the replica the same as the primary, with the same storage performance
  2. For MySQL, turn on parallel apply (replica_parallel_workers)
  3. Move heavy analytics to a dedicated replica or to Aurora, where replicas share storage and lag is usually well under a second

Prevent โ†’ Alarm on lag, and route reads that must not be stale to the primary.

Copy link
Q107

After a Multi-AZ failover, some app servers keep failing with connection errors for 10+ minutes while others recover in a minute.

Advanced

Likely causes โ†’ A failover flips the endpoint's DNS CNAME to the standby. Clients that cache DNS for a long time (JVM networkaddress.cache.ttl set to forever, or a misconfigured local resolver) or keep stale pooled connections keep hitting the old IP.

Diagnose โ†’

bash
aws rds describe-events --source-identifier mydb --source-type db-instance --duration 120
dig +short mydb.abc.us-east-1.rds.amazonaws.com
# on the bad host
getent hosts mydb.abc.us-east-1.rds.amazonaws.com

Fix โ†’

  1. Set the JVM DNS TTL to a low value (networkaddress.cache.ttl=5)
  2. Turn on pool connection validation and max lifetime (for example, HikariCP maxLifetime)
  3. Restart the affected app instances to recover now

Prevent โ†’ Use RDS Proxy (it keeps client connections during failover) or the AWS Advanced JDBC Wrapper, and test failover regularly with aws rds reboot-db-instance --force-failover.

Copy link
Q108

Restoring a snapshot fails: InvalidParameterCombination: Cannot find version 11.22 for postgres.

Beginner

Likely causes โ†’ The engine version has reached end of standard support or is not offered in this Region any more, so you cannot create new instances on it without Extended Support or an upgrade.

Diagnose โ†’

bash
aws rds describe-db-engine-versions --engine postgres --query 'DBEngineVersions[].EngineVersion' --output text
aws rds describe-db-snapshots --db-snapshot-identifier snap-1 --query 'DBSnapshots[].EngineVersion'

Fix โ†’

  1. Restore with a supported version, specifying --engine-version if the restore path allows it
  2. Or upgrade the snapshot first: aws rds modify-db-snapshot --db-snapshot-identifier snap-1 --engine-version 12.22 (RDS PostgreSQL supports upgrading DB snapshots), then upgrade the restored instance further

Prevent โ†’ Track engine end-of-life dates, upgrade on a schedule, and run restore tests regularly.

Copy link
Q109

You changed work_mem in the parameter group, but SHOW work_mem; still shows the old value.

Intermediate

Likely causes โ†’ The instance uses a different parameter group, the parameter is static (it needs a reboot, status pending-reboot), or the session or role overrides it.

Diagnose โ†’

bash
aws rds describe-db-instances --db-instance-identifier mydb \
  --query 'DBInstances[].DBParameterGroups'
aws rds describe-db-parameters --db-parameter-group-name pg16-app \
  --query "Parameters[?ParameterName=='work_mem'].[ParameterValue,ApplyType,IsModifiable]"
psql -c "select name, setting, source from pg_settings where name='work_mem';"

Fix โ†’

  1. Attach the right custom group. The default group cannot be modified
  2. For static parameters, reboot during a window
  3. Remove role-level overrides (ALTER ROLE app RESET work_mem)

Prevent โ†’ Use one custom parameter group per engine and environment, managed in IaC, and check pending-reboot after every change.

Copy link
Q110

RDS IAM authentication fails: FATAL: PAM authentication failed for user "app_iam".

Advanced

Likely causes โ†’ The token was generated for a different host, port, user or Region, or it is older than 15 minutes. The DB user is missing the rds_iam role (PostgreSQL) or AWSAuthenticationPlugin (MySQL). The IAM policy has no rds-db:connect on the right dbuser ARN (it uses the DbiResourceId, not the instance name). Or TLS is not used.

Diagnose โ†’

bash
aws rds describe-db-instances --db-instance-identifier mydb --query 'DBInstances[].[DbiResourceId,IAMDatabaseAuthenticationEnabled]'
TOKEN=$(aws rds generate-db-auth-token --hostname mydb.abc.us-east-1.rds.amazonaws.com --port 5432 --username app_iam --region us-east-1)
psql "host=mydb.abc.us-east-1.rds.amazonaws.com user=app_iam dbname=orders sslmode=require password=$TOKEN"

Fix โ†’

  1. Run GRANT rds_iam TO app_iam;
  2. Policy resource: arn:aws:rds-db:us-east-1:111111111111:dbuser:db-ABCDEFGH123/app_iam
  3. Generate the token right before you connect, and always use TLS

Prevent โ†’ Wrap token generation in the connection factory, and keep the IAM auth rate limits in mind (use RDS Proxy at high connection rates).

Copy link
Q111

InvalidParameterCombination: Cannot delete protected DB Instance, please disable deletion protection and try again.

Beginner

Likely causes โ†’ Deletion protection is on, which is the intended safeguard.

Diagnose โ†’

bash
aws rds describe-db-instances --db-instance-identifier old-db --query 'DBInstances[].DeletionProtection'

Fix โ†’

bash
aws rds modify-db-instance --db-instance-identifier old-db --no-deletion-protection --apply-immediately
aws rds delete-db-instance --db-instance-identifier old-db --final-db-snapshot-identifier old-db-final

Prevent โ†’ Keep deletion protection on in production. Require a final snapshot, and do the disable step through a change ticket, not by hand.

Copy link
Q112

Writes fail on Aurora MySQL with ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement.

Intermediate

Likely causes โ†’ The app is connected to a reader: through the reader endpoint, an instance endpoint that became a reader after failover, or a pooled connection that lived through a failover.

Diagnose โ†’

bash
aws rds describe-db-clusters --db-cluster-identifier orders \
  --query 'DBClusters[].[Endpoint,ReaderEndpoint,DBClusterMembers[].[DBInstanceIdentifier,IsClusterWriter]]'
mysql -h <host> -e "select @@aurora_server_id, @@innodb_read_only;"

Fix โ†’

  1. Point write traffic at the cluster (writer) endpoint, never at an instance endpoint
  2. Recycle pools after failover. The AWS Advanced JDBC Wrapper handles this
  3. Retry the write after a reconnect

Prevent โ†’ Use separate writer and reader data sources in the app, and run failover drills (aws rds failover-db-cluster).

Copy link
Q113

RDS CPUUtilization is pinned at 100% and the API is timing out.

Advanced

Likely causes โ†’ One or a few bad queries: a missing index after a deploy, a plan regression from stale statistics, a runaway report, or lock contention that shows up as CPU spin.

Diagnose โ†’

bash
aws pi get-resource-metrics --service-type RDS --identifier db-ABCDEFGH123 \
  --metric-queries '[{"Metric":"db.load.avg","GroupBy":{"Group":"db.sql_tokenized","Limit":5}}]' \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ) --period-in-seconds 300
psql -c "select pid, now()-query_start dur, state, left(query,80) from pg_stat_activity where state<>'idle' order by dur desc limit 10;"

Fix โ†’

  1. Kill the runaway query: select pg_cancel_backend(<pid>);
  2. Add the missing index (CREATE INDEX CONCURRENTLY), and run ANALYZE on the affected tables
  3. Scale up only as a stopgap

Prevent โ†’ Keep Performance Insights and pg_stat_statements on, review query plans in CI for hot paths, and alarm on DB load above the vCPU count.

Copy link
Q114

An RDS major version upgrade fails, and the event says Database instance is in a state that cannot be upgraded: PreUpgrade checks failed.

Advanced

Likely causes โ†’ Pre-checks found blockers: unsupported extensions or extension versions (PostGIS, pg_repack), reg* data types, open prepared transactions, logical replication slots, or for MySQL, objects incompatible with 8.0/8.4 (reserved words, old temporal types).

Diagnose โ†’

bash
aws rds describe-events --source-identifier mydb --source-type db-instance --duration 60
aws rds describe-db-log-files --db-instance-identifier mydb --filename-contains upgrade
aws rds download-db-log-file-portion --db-instance-identifier mydb --log-file-name <precheck-log> --output text
aws rds describe-db-engine-versions --engine postgres --engine-version 15.8 --query 'DBEngineVersions[].ValidUpgradeTarget[].EngineVersion'

Fix โ†’

  1. Upgrade the extensions (ALTER EXTENSION postgis UPDATE;), drop replication slots, and commit or roll back prepared transactions
  2. Retry with a matching custom parameter group for the target version
  3. For minimal downtime, use RDS Blue/Green Deployments

Prevent โ†’ Rehearse upgrades on a restored snapshot, and use Blue/Green for major versions.

Copy link
Q115

Creating a DB fails: InsufficientDBInstanceCapacity: Cannot create a db.r6g.4xlarge instance in us-east-1d.

Beginner

Likely causes โ†’ The instance class has no capacity in that AZ right now, or the class is not offered there at all.

Diagnose โ†’

bash
aws rds describe-orderable-db-instance-options --engine postgres --db-instance-class db.r6g.4xlarge \
  --query 'OrderableDBInstanceOptions[].AvailabilityZones[].Name' --output text

Fix โ†’

  1. Retry in another AZ, or make sure the subnet group has subnets in AZs that offer the class
  2. Pick a sibling class (db.r7g, db.r6i)

Prevent โ†’ Use DB subnet groups that cover at least three AZs, and avoid pinning --availability-zone unless you need to.

Copy link
Q116

ProvisionedThroughputExceededException: The level of configured provisioned throughput for the table was exceeded.

Intermediate

Likely causes โ†’ The table is in provisioned mode and traffic is above its RCU/WCU. Auto scaling reacts only after a few minutes, so sudden spikes throttle first. Burst capacity covers only short spikes.

Diagnose โ†’

bash
aws dynamodb describe-table --table-name orders --query 'Table.[BillingModeSummary,ProvisionedThroughput]'
aws cloudwatch get-metric-statistics --namespace AWS/DynamoDB --metric-name WriteThrottleEvents \
  --dimensions Name=TableName,Value=orders --statistics Sum --period 60 \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)
aws application-autoscaling describe-scalable-targets --service-namespace dynamodb

Fix โ†’

  1. For spiky or unknown traffic, switch to on-demand: aws dynamodb update-table --table-name orders --billing-mode PAY_PER_REQUEST
  2. Or raise the capacity and the auto scaling minimum before known peaks
  3. Make sure the SDK retries with backoff

Prevent โ†’ Use on-demand by default, provisioned with auto scaling for steady, predictable load, and alarm on throttle events.

Copy link
Q117

One DynamoDB table throttles even though consumed capacity is far below provisioned (or it is on-demand).

Advanced

Likely causes โ†’ A hot partition. One partition key, such as status=PENDING, today's date or one big tenant, takes most of the traffic. Each partition is limited to about 3,000 RCU and 1,000 WCU per second, no matter how much the table has.

Diagnose โ†’

bash
aws dynamodb describe-contributor-insights --table-name orders
aws dynamodb update-contributor-insights --table-name orders --contributor-insights-action ENABLE
# then view top partition keys in CloudWatch Contributor Insights

Fix โ†’

  1. Redesign the key for higher cardinality, for example write-sharding the hot key: PENDING#<0-9>
  2. Cache hot reads with DAX or ElastiCache
  3. Spread time-series writes across shard suffixes

Prevent โ†’ Model access patterns before you build the table, and keep Contributor Insights on for important tables.

Copy link
Q118

ValidationException: One or more parameter values were invalid: Missing the key orderId in the item.

Beginner

Likely causes โ†’ The PutItem request does not include the partition key (or sort key) attribute, or uses a different name or case (orderID vs orderId), or a different type (S vs N).

Diagnose โ†’

bash
aws dynamodb describe-table --table-name orders --query 'Table.[KeySchema,AttributeDefinitions]'

Fix โ†’ Send every key attribute with the exact name and type:

bash
aws dynamodb put-item --table-name orders \
  --item '{"orderId":{"S":"o-1001"},"createdAt":{"N":"1731139200"},"total":{"N":"42.5"}}'

Prevent โ†’ Use a typed data layer (for example, the DynamoDB Document Client or ElectroDB) with a schema, and add contract tests.

Copy link
Q119

Updates fail with ConditionalCheckFailedException: The conditional request failed. Is it a bug?

Intermediate

Likely causes โ†’ Usually it is working as designed: the ConditionExpression (for example, an optimistic lock on version, or attribute_not_exists(pk)) was false because another writer changed the item first, or the item already exists.

Diagnose โ†’

bash
aws dynamodb get-item --table-name orders --key '{"orderId":{"S":"o-1001"}}' --consistent-read
aws dynamodb update-item --table-name orders --key '{"orderId":{"S":"o-1001"}}' \
  --update-expression 'SET #s=:s, version=version+:one' --condition-expression 'version=:v' \
  --expression-attribute-names '{"#s":"status"}' \
  --expression-attribute-values '{":s":{"S":"PAID"},":v":{"N":"3"},":one":{"N":"1"}}' \
  --return-values-on-condition-check-failure ALL_OLD

Fix โ†’

  1. Treat it as a conflict: re-read, merge, and retry with the new version
  2. Use ReturnValuesOnConditionCheckFailure=ALL_OLD to see the current item without a second read

Prevent โ†’ Handle the exception explicitly in code, and count it as a business metric, not an error.

Copy link
Q120

ValidationException: Item size has exceeded the maximum allowed size.

Beginner

Likely causes โ†’ A DynamoDB item, including attribute names, is limited to 400 KB. A common cause is lists that keep growing (events, comments) or embedded blobs.

Diagnose โ†’

bash
aws dynamodb get-item --table-name sessions --key '{"id":{"S":"u-1"}}' --output json | wc -c

Fix โ†’

  1. Store large payloads in S3 and keep the S3 key in the item
  2. Split unbounded lists into separate items under the same partition key (for example, pk=USER#1, sk=EVENT#<ts>)
  3. Compress large attributes (gzip into a Binary attribute)

Prevent โ†’ Never model unbounded collections inside one item, and keep attribute names short in hot tables.

Copy link
Q121

TransactionCanceledException: Transaction cancelled, please refer cancellation reasons for specific reasons [None, ConditionalCheckFailed].

Advanced

Likely causes โ†’ One item in TransactWriteItems failed, so the whole transaction rolled back. The reasons list matches the request order, so the second action's condition failed here. TransactionConflict in the list means a concurrent transaction touched the same item.

Diagnose โ†’

bash
aws dynamodb transact-write-items --transact-items file://tx.json 2>&1 | tail
# inspect CancellationReasons[].Code / Item in the SDK exception

Fix โ†’

  1. Map each reason back to its action, and handle ConditionalCheckFailed as a business conflict
  2. Retry TransactionConflict with backoff
  3. Use a ClientRequestToken for idempotent retries

Prevent โ†’ Keep transactions small (up to 100 items), avoid hot items inside transactions, and log cancellation reasons in a structured form.

Copy link
Q122

A user updates a profile and immediately reloads, but the GSI query still returns the old value.

Intermediate

Likely causes โ†’ Global secondary indexes are updated asynchronously and only support eventually consistent reads. ConsistentRead=true is rejected on a GSI.

Diagnose โ†’

bash
aws dynamodb query --table-name users --index-name email-index \
  --key-condition-expression 'email=:e' --expression-attribute-values '{":e":{"S":"[email protected]"}}'
aws dynamodb get-item --table-name users --key '{"userId":{"S":"u-1"}}' --consistent-read

Fix โ†’

  1. For read-after-write views, read from the base table by primary key with --consistent-read
  2. Or use an LSI (it supports strong consistency but must be created with the table)
  3. Or return the updated item to the client from the write response

Prevent โ†’ Decide consistency needs per access pattern during design, and watch OnlineIndexPercentageProgress and GSI throttles.

Copy link
Q123

A DynamoDB Query with a filter returns only 12 items, but you know there are hundreds.

Beginner

Likely causes โ†’ Each Query or Scan page reads at most 1 MB before the FilterExpression is applied. The response has a LastEvaluatedKey, and the code does not paginate.

Diagnose โ†’

bash
aws dynamodb query --table-name orders --key-condition-expression 'customerId=:c' \
  --filter-expression '#s=:s' --expression-attribute-names '{"#s":"status"}' \
  --expression-attribute-values '{":c":{"S":"c-9"},":s":{"S":"OPEN"}}' --no-paginate \
  --query '[Count,ScannedCount,LastEvaluatedKey]'

Fix โ†’

  1. Loop until LastEvaluatedKey is empty (the CLI paginates by default; SDKs have paginators)
  2. If the filter discards most items, add a GSI keyed on that attribute so you query instead of filter

Prevent โ†’ Always use paginators, and compare ScannedCount with Count in reviews; a big gap means the key design is wrong.

Copy link
Q124

Writes to the base table throttle, but the table itself has plenty of capacity.

Advanced

Likely causes โ†’ A GSI is under-provisioned or hot. GSI writes happen asynchronously, but when a GSI cannot keep up, DynamoDB throttles writes on the base table (back-pressure). This often follows adding a GSI with a low-cardinality key.

Diagnose โ†’

bash
aws dynamodb describe-table --table-name orders \
  --query 'Table.GlobalSecondaryIndexes[].[IndexName,ProvisionedThroughput,IndexStatus]'
# CloudWatch WriteThrottleEvents with dimensions TableName + GlobalSecondaryIndexName

Fix โ†’

  1. Raise the GSI's WCU, or switch the table to on-demand
  2. Redesign the GSI partition key so it has high cardinality
  3. Project only the attributes you need, to lower write size

Prevent โ†’ Give each GSI the same auto scaling as the base table, and alarm on GSI throttles separately.

Copy link
Q125

TTL is enabled, but expired items are still in the table days later.

Intermediate

Likely causes โ†’ The TTL attribute is not a Number in epoch seconds (a string or milliseconds is ignored), the attribute name does not match, or deletion is simply lagging. TTL deletes in the background, usually within a few days.

Diagnose โ†’

bash
aws dynamodb describe-time-to-live --table-name sessions
aws dynamodb get-item --table-name sessions --key '{"id":{"S":"s-1"}}' --query 'Item.expiresAt'
date +%s

Fix โ†’

  1. Write expiresAt as a Number with $(date -d '+1 day' +%s), not milliseconds
  2. Filter out expired items in reads (expiresAt > :now) until they are deleted

Prevent โ†’ Use a unit test for TTL values, and use the TimeToLiveDeletedItemCount metric to confirm deletes are happening.

Copy link

ECS, EKS, ECR and Lambda

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q126

docker push 111111111111.dkr.ecr.us-east-1.amazonaws.com/api:1.4 fails with no basic auth credentials (or denied: Your authorization token has expired. Reauthenticate and try again.).

Beginner

Likely causes โ†’ Docker never logged in to that registry and Region, or the ECR token (valid for 12 hours) expired. Another cause: the repository does not exist (name unknown: The repository with name 'api' does not exist in the registry).

Diagnose โ†’

bash
aws sts get-caller-identity
aws ecr describe-repositories --repository-names api --region us-east-1
cat ~/.docker/config.json | grep -A2 dkr.ecr

Fix โ†’

bash
aws ecr get-login-password --region us-east-1 | \
  docker login --username AWS --password-stdin 111111111111.dkr.ecr.us-east-1.amazonaws.com
aws ecr create-repository --repository-name api --image-scanning-configuration scanOnPush=true

Prevent โ†’ In CI, log in at the start of every job (for example, aws-actions/amazon-ecr-login), or use amazon-ecr-credential-helper.

Copy link
Q127

Fargate tasks stop with CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref ... dial tcp 52.x.x.x:443: i/o timeout.

Intermediate

Likely causes โ†’ The task runs in a private subnet with no route to ECR: no NAT gateway, and no VPC endpoints for ecr.api, ecr.dkr and S3 (gateway endpoint, because image layers come from S3). Or it is in a public subnet without assignPublicIp=ENABLED.

Diagnose โ†’

bash
aws ecs describe-tasks --cluster prod --tasks <task-arn> --query 'tasks[].[stoppedReason,containers[].reason]'
aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=subnet-0abc --query 'RouteTables[].Routes'
aws ec2 describe-vpc-endpoints --filters Name=vpc-id,Values=vpc-0abc --query 'VpcEndpoints[].ServiceName'

Fix โ†’

  1. Add a NAT route, or add the endpoints: com.amazonaws.us-east-1.ecr.api, ecr.dkr, logs (interface) and s3 (gateway)
  2. The endpoint SG must allow 443 from the task SG

Prevent โ†’ Ship a standard "private VPC endpoints" module, and test task launches in every new subnet.

Copy link
Q128

ResourceInitializationError: unable to pull secrets or registry auth: ... AccessDeniedException: User: arn:aws:sts::111111111111:assumed-role/ecsTaskExecutionRole/... is not authorized to perform: secretsmanager:GetSecretValue.

Intermediate

Likely causes โ†’ The task definition refers to a secret in secrets, but the execution role (not the task role) cannot read it, or cannot decrypt the KMS key behind it. Network reachability to Secrets Manager or SSM can also cause this error.

Diagnose โ†’

bash
aws ecs describe-task-definition --task-definition api:42 \
  --query 'taskDefinition.[executionRoleArn,containerDefinitions[].secrets]'
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::111111111111:role/ecsTaskExecutionRole \
  --action-names secretsmanager:GetSecretValue --resource-arns <secret-arn>

Fix โ†’ Add secretsmanager:GetSecretValue (or ssm:GetParameters) on the specific secret ARNs, plus kms:Decrypt on the CMK, to the execution role. If the tasks are in private subnets, add the secretsmanager endpoint.

Prevent โ†’ Keep one execution role per service, scoped to its own secret paths, and remember: the execution role is for the agent, the task role is for your code.

Copy link
Q129

A task stops with Essential container in task exited, exit code 137, and reason OutOfMemoryError: Container killed due to memory usage.

Beginner

Likely causes โ†’ The container went over its hard memory limit, so the kernel OOM killer sent SIGKILL (137 = 128 + 9). A JVM heap that is not sized to the container limit, or a memory leak, are the usual reasons.

Diagnose โ†’

bash
aws ecs describe-tasks --cluster prod --tasks <task-arn> \
  --query 'tasks[].containers[].[name,exitCode,reason]'
# Container Insights: MemoryUtilized vs MemoryReserved per task
aws logs tail /ecs/api --since 30m

Fix โ†’

  1. Raise the task or container memory
  2. Size runtimes to the container: -XX:MaxRAMPercentage=75 for Java, --max-old-space-size for Node.js
  3. Fix the leak (take a heap dump before you hit the limit)

Prevent โ†’ Turn on Container Insights, alarm on memory utilization above 85%, and load-test with production-like data.

Copy link
Q130

The ECS service event says service api was unable to place a task because no container instance met all of its requirements. The closest matching container-instance ... has insufficient memory available.

Intermediate

Likely causes โ†’ On the EC2 launch type, no container instance has enough free CPU, memory or ports (static host ports with bridge mode clash), or placement constraints such as distinctInstance rule them out. Capacity provider scaling may be off.

Diagnose โ†’

bash
aws ecs describe-services --cluster prod --services api --query 'services[].events[:5]'
aws ecs list-container-instances --cluster prod
aws ecs describe-container-instances --cluster prod --container-instances <arn> \
  --query 'containerInstances[].remainingResources[?name==`MEMORY` || name==`CPU`]'

Fix โ†’

  1. Use a capacity provider with managed scaling, so the ASG grows when tasks are pending
  2. Use awsvpc or dynamic host ports (hostPort 0) instead of fixed ports
  3. Right-size task reservations, or move to Fargate

Prevent โ†’ Use capacity providers with targetCapacity around 90%, and alarm on pending tasks.

Copy link
Q131

An ECS deployment rolls back automatically, and the event says deployment failed: tasks failed to start from the circuit breaker.

Advanced

Likely causes โ†’ The new tasks crash at startup (bad config or secret, failed migration), fail the container health check, or fail ALB health checks before healthCheckGracePeriodSeconds. The deployment circuit breaker detected repeated failures and rolled back.

Diagnose โ†’

bash
aws ecs describe-services --cluster prod --services api \
  --query 'services[].[deployments,events[:10]]'
aws ecs list-tasks --cluster prod --service-name api --desired-status STOPPED
aws ecs describe-tasks --cluster prod --tasks <stopped-task> --query 'tasks[].[stoppedReason,containers[].[exitCode,reason]]'
aws logs tail /ecs/api --since 20m --filter-pattern ERROR

Fix โ†’

  1. Fix the root cause from the stopped-task reasons and logs
  2. If the app is slow to start, raise healthCheckGracePeriodSeconds and the container health check startPeriod
  3. Redeploy

Prevent โ†’ Keep the circuit breaker with rollback on, add CloudWatch alarm-based rollback, and smoke-test images in staging with the same task definition.

Copy link
Q132

aws ecs execute-command fails: The execute command failed because execute command was not enabled when the task was run or the execute command agent isn't running.

Intermediate

Likely causes โ†’ The task was started without enableExecuteCommand. Other causes: the task role has no ssmmessages:* permissions, the private subnet cannot reach ssmmessages, or the Session Manager plugin is not installed locally.

Diagnose โ†’

bash
aws ecs describe-tasks --cluster prod --tasks <task-arn> \
  --query 'tasks[].[enableExecuteCommand,containers[].managedAgents]'
# AWS's open-source checker:
bash <(curl -s https://raw.githubusercontent.com/aws-containers/amazon-ecs-exec-checker/main/check-ecs-exec.sh) prod <task-id>

Fix โ†’

  1. aws ecs update-service --cluster prod --service api --enable-execute-command --force-new-deployment (existing tasks must be replaced)
  2. Give the task role ssmmessages:CreateControlChannel, CreateDataChannel, OpenControlChannel and OpenDataChannel
  3. Add the ssmmessages endpoint for private subnets

Prevent โ†’ Enable exec in non-production by default, log sessions to CloudWatch or S3, and restrict it with IAM conditions in production.

Copy link
Q133

kubectl get pods returns error: You must be logged in to the server (Unauthorized) on a new EKS cluster.

Beginner

Likely causes โ†’ Your IAM principal is not mapped into the cluster. Only the cluster creator gets admin automatically (and only if bootstrap admin was on). Other causes: the kubeconfig uses a different profile or role than the one that has an access entry.

Diagnose โ†’

bash
aws sts get-caller-identity
aws eks update-kubeconfig --name prod --region us-east-1
aws eks list-access-entries --cluster-name prod
aws eks describe-cluster --name prod --query 'cluster.accessConfig'

Fix โ†’

bash
aws eks create-access-entry --cluster-name prod --principal-arn arn:aws:iam::111111111111:role/platform-admin
aws eks associate-access-policy --cluster-name prod --principal-arn arn:aws:iam::111111111111:role/platform-admin \
  --policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy --access-scope type=cluster

Prevent โ†’ Use authentication mode API with access entries managed in IaC, not the aws-auth ConfigMap.

Copy link
Q134

New EKS worker nodes never join; kubectl get nodes does not list them, while the EC2 instances are running.

Intermediate

Likely causes โ†’ The node IAM role has no access entry (type EC2_LINUX) or aws-auth mapping. Other causes: the node SG cannot reach the API endpoint (private endpoint, missing 443 rule), the nodes cannot reach ECR or STS (no NAT or endpoints), or the bootstrap or nodeadm config has the wrong cluster name or CA.

Diagnose โ†’

bash
aws eks list-access-entries --cluster-name prod
aws eks describe-nodegroup --cluster-name prod --nodegroup-name ng-1 --query 'nodegroup.health'
# on the node via SSM:
sudo journalctl -u kubelet --no-pager | tail -50
sudo journalctl -u nodeadm-run --no-pager | tail -20   # AL2023

Fix โ†’

  1. Run aws eks create-access-entry --cluster-name prod --principal-arn <node-role-arn> --type EC2_LINUX
  2. Allow 443 from the node SG to the cluster SG, and add NAT or endpoints (ecr.api, ecr.dkr, s3, sts, ec2)

Prevent โ†’ Use managed node groups or Karpenter, which create the access entries, and check node health issues in describe-nodegroup.

Copy link
Q135

Pods stay Pending with 0/6 nodes are available: 6 Too many pods, but the nodes have plenty of CPU and memory.

Advanced

Likely causes โ†’ With the VPC CNI, every pod gets a VPC IP, and max pods per node is limited by ENIs ร— IPs per ENI (for example, 29 on m5.large). Small instance types fill up quickly. The subnet may also be running out of IPs (failed to assign an IP address to container in aws-node logs).

Diagnose โ†’

bash
kubectl get nodes -o custom-columns=NAME:.metadata.name,MAXPODS:.status.allocatable.pods
kubectl -n kube-system logs ds/aws-node -c aws-node | grep -i -E 'insufficient|failed to assign'
aws ec2 describe-subnets --subnet-ids subnet-0abc --query 'Subnets[].AvailableIpAddressCount'

Fix โ†’

  1. Turn on prefix delegation: kubectl set env ds/aws-node -n kube-system ENABLE_PREFIX_DELEGATION=true, and raise max pods (managed node groups and Karpenter calculate it)
  2. Use larger instances
  3. If the subnet is out of IPs, add a secondary CIDR (for example 100.64.0.0/16) with custom networking

Prevent โ†’ Plan pod IP capacity at design time (/19 or larger node subnets), and alarm on free IPs per subnet.

Copy link
Q136

A pod's S3 calls fail with AccessDenied ... User: arn:aws:sts::111111111111:assumed-role/eks-node-role/i-0abc is not authorized. Why is it using the node role?

Advanced

Likely causes โ†’ The pod has no working IRSA or Pod Identity setup, so the SDK falls back to the node's instance profile through IMDS. Common reasons: the service account has no eks.amazonaws.com/role-arn annotation (IRSA), or no Pod Identity association exists, or the Pod Identity Agent add-on is missing, or the pod was created before the association and was never restarted. An old SDK that does not support the credential source does the same.

Diagnose โ†’

bash
kubectl get sa app -n prod -o yaml | grep -A2 annotations
aws eks list-pod-identity-associations --cluster-name prod --namespace prod
kubectl exec -n prod deploy/app -- env | grep -E 'AWS_ROLE_ARN|AWS_WEB_IDENTITY|AWS_CONTAINER_CREDENTIALS_FULL_URI'
kubectl get ds -n kube-system eks-pod-identity-agent

Fix โ†’

  1. Pod Identity: install the add-on, then run aws eks create-pod-identity-association --cluster-name prod --namespace prod --service-account app --role-arn <role>. The role trust policy allows pods.eks.amazonaws.com with sts:AssumeRole and sts:TagSession
  2. Restart the pods so the credentials get injected

Prevent โ†’ Block pod access to IMDS (set the hop limit to 1 on nodes) so a missing setup fails loudly instead of quietly using node permissions.

Copy link
Q137

An Ingress never gets an ALB, and the AWS Load Balancer Controller logs Failed build model due to couldn't auto-discover subnets: unable to resolve at least one subnet.

Intermediate

Likely causes โ†’ The subnets do not have the discovery tags: kubernetes.io/role/elb=1 for public subnets (internet-facing) or kubernetes.io/role/internal-elb=1 for private ones. Another cause: fewer than two AZs qualify.

Diagnose โ†’

bash
kubectl -n kube-system logs deploy/aws-load-balancer-controller | tail -30
kubectl describe ingress web -n prod
aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-0abc \
  --query 'Subnets[].[SubnetId,AvailabilityZone,Tags[?starts_with(Key,`kubernetes.io/role`)]]'

Fix โ†’

bash
aws ec2 create-tags --resources subnet-0pub1 subnet-0pub2 --tags Key=kubernetes.io/role/elb,Value=1

Or list the subnets explicitly with the annotation alb.ingress.kubernetes.io/subnets. Also check that the controller's IAM role has the current policy, because new features need new permissions.

Prevent โ†’ Tag subnets in the VPC module, and pin the controller and its IAM policy version together.

Copy link
Q138

An EKS cluster upgrade to the next minor version is blocked, or workloads break right after it.

Advanced

Likely causes โ†’ Manifests or Helm charts still use removed APIs. Add-ons (VPC CNI, CoreDNS, kube-proxy, EBS CSI) are at versions that do not support the new Kubernetes version. Or nodes are more than the allowed skew behind the control plane.

Diagnose โ†’

bash
aws eks list-insights --cluster-name prod --filter kubernetesVersions=1.33
aws eks describe-insight --cluster-name prod --id <insight-id>
aws eks describe-addon-versions --addon-name vpc-cni --kubernetes-version 1.33 \
  --query 'addons[].addonVersions[].addonVersion' --output text | head
kubectl get --raw /metrics | grep apiserver_requested_deprecated_apis

Fix โ†’

  1. Migrate manifests (kubectl-convert, pluto detect-helm)
  2. Upgrade the add-ons to compatible versions before the control plane, then upgrade the control plane, then the nodes
  3. Update PDBs so node drains can finish

Prevent โ†’ Upgrade one minor version at a time, every quarter, rehearsed on a staging cluster. Track EKS upgrade insights in CI.

Copy link
Q139

A PVC stays Pending with waiting for a volume to be created, either by external provisioner "ebs.csi.aws.com" or manually created by system administrator.

Intermediate

Likely causes โ†’ The EBS CSI driver add-on is not installed, or its controller has no IAM permissions (no IRSA or Pod Identity role with AmazonEBSCSIDriverPolicy). Or the StorageClass uses WaitForFirstConsumer and no pod has been scheduled yet, which is normal.

Diagnose โ†’

bash
kubectl describe pvc data-db-0 -n prod
aws eks describe-addon --cluster-name prod --addon-name aws-ebs-csi-driver --query 'addon.[status,serviceAccountRoleArn]'
kubectl -n kube-system logs deploy/ebs-csi-controller -c csi-provisioner | tail -20
kubectl get sc

Fix โ†’

bash
aws eks create-addon --cluster-name prod --addon-name aws-ebs-csi-driver \
  --service-account-role-arn arn:aws:iam::111111111111:role/ebs-csi-role

If the volumes are KMS-encrypted, add KMS permissions for that key to the role.

Prevent โ†’ Install CSI drivers as managed add-ons with their roles in IaC, and set a default gp3 StorageClass.

Copy link
Q140

A deployment fails with ErrImagePull ... manifest unknown (or ECS CannotPullContainerError: ... not found) for an image that used to work.

Beginner

Likely causes โ†’ The tag does not exist in that repository or Region. A typo, a pipeline that never pushed, or an ECR lifecycle policy that expired old tags.

Diagnose โ†’

bash
aws ecr describe-images --repository-name api --image-ids imageTag=1.4.2
aws ecr get-lifecycle-policy --repository-name api
aws ecr describe-images --repository-name api --query 'sort_by(imageDetails,&imagePushedAt)[-5:].imageTags'

Fix โ†’

  1. Push the missing tag again, or deploy an existing digest
  2. Change the lifecycle policy so it keeps images that are still deployed (for example, keep the last 50, and expire only untagged images after 14 days)

Prevent โ†’ Deploy by immutable digest, turn on tag immutability, and make lifecycle rules generous enough for rollbacks.

Copy link
Q141

A container starts and immediately exits with exec /usr/local/bin/app: exec format error on the new Graviton nodes.

Intermediate

Likely causes โ†’ The image was built only for linux/amd64 and is running on an arm64 (Graviton) node, or the other way round.

Diagnose โ†’

bash
docker buildx imagetools inspect 111111111111.dkr.ecr.us-east-1.amazonaws.com/api:1.4
kubectl get nodes -L kubernetes.io/arch

Fix โ†’

bash
docker buildx build --platform linux/amd64,linux/arm64 \
  -t 111111111111.dkr.ecr.us-east-1.amazonaws.com/api:1.4 --push .

For a quick fix, pin the workload with nodeSelector: kubernetes.io/arch: amd64, or set ECS runtimePlatform.cpuArchitecture.

Prevent โ†’ Build multi-arch images in CI, and run arm64 smoke tests before you add Graviton capacity.

Copy link
Q142

Lambda logs end with Task timed out after 3.00 seconds.

Beginner

Likely causes โ†’ The default timeout is 3 seconds. The function is slow, or it hangs on a network call: a VPC function with no route to the internet or endpoint, a DB connection without a timeout, or a downstream that is slow.

Diagnose โ†’

bash
aws lambda get-function-configuration --function-name orders-api --query '[Timeout,MemorySize,VpcConfig]'
aws logs tail /aws/lambda/orders-api --since 15m
# enable X-Ray active tracing to see which segment takes the time

Fix โ†’

  1. Set client timeouts on every network call below the function timeout
  2. Raise the timeout to a realistic value: aws lambda update-function-configuration --function-name orders-api --timeout 15
  3. Raising memory also gives more CPU, which speeds up CPU-bound code

Prevent โ†’ Alarm on the Duration p99 against the timeout, and turn on X-Ray tracing.

Copy link
Q143

A Lambda function was moved into a VPC, and now every AWS SDK call hangs until timeout.

Intermediate

Likely causes โ†’ Lambda ENIs in a VPC never get public IPs, even in public subnets. Without a NAT gateway or VPC endpoints, the function cannot reach AWS APIs or the internet.

Diagnose โ†’

bash
aws lambda get-function-configuration --function-name worker --query 'VpcConfig'
aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=subnet-0priv --query 'RouteTables[].Routes'

Fix โ†’

  1. Put the function in private subnets with a route to a NAT gateway
  2. Or add interface or gateway endpoints for the services it calls (S3, DynamoDB gateway endpoints are free)
  3. Allow outbound 443 in the function's SG

Prevent โ†’ Only attach Lambda to a VPC when it needs private resources, and always pair that with endpoints or NAT.

Copy link
Q144

Runtime.ImportModuleError: Unable to import module 'app': No module named 'requests'.

Beginner

Likely causes โ†’ Third-party dependencies were not packaged with the function code (the zip contains only app.py). Other causes: they were built for the wrong platform (native wheels built on macOS), or the handler path is wrong.

Diagnose โ†’

bash
aws lambda get-function-configuration --function-name api --query '[Handler,Runtime,Layers]'
unzip -l function.zip | head

Fix โ†’

bash
pip install -r requirements.txt -t package/ --platform manylinux2014_x86_64 --only-binary=:all:
cp app.py package/ && (cd package && zip -r ../function.zip .)
aws lambda update-function-code --function-name api --zip-file fileb://function.zip

Or move shared dependencies into a layer, or ship the function as a container image.

Prevent โ†’ Build packages in CI with SAM or a container matching the Lambda runtime, never from a laptop.

Copy link
Q145

Callers get TooManyRequestsException: Rate Exceeded from Lambda and the Throttles metric spikes.

Intermediate

Likely causes โ†’ You hit concurrency limits: the account limit in the Region (1,000 by default), the function's reserved concurrency, or another function used up the shared pool.

Diagnose โ†’

bash
aws lambda get-account-settings --query 'AccountLimit.[ConcurrentExecutions,UnreservedConcurrentExecutions]'
aws lambda get-function-concurrency --function-name orders-api
aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name ConcurrentExecutions \
  --statistics Maximum --period 60 --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)

Fix โ†’

  1. Request an account concurrency increase through Service Quotas
  2. Give critical functions reserved concurrency, and cap noisy ones
  3. Put SQS in front of bursty async producers

Prevent โ†’ Alarm on ConcurrentExecutions near the limit, and on Throttles above 0 for synchronous APIs.

Copy link
Q146

A Java Lambda behind API Gateway has p99 latency of 6โ€“8 seconds on the first request after idle periods.

Advanced

Likely causes โ†’ Cold starts: JVM startup, heavy framework init (Spring) and large packages. VPC attachment adds little now (Hyperplane ENIs), so init code is usually the cause.

Diagnose โ†’

bash
aws logs filter-log-events --log-group-name /aws/lambda/orders-api \
  --filter-pattern '"Init Duration"' --max-items 5 --query 'events[].message'

Fix โ†’

  1. Turn on SnapStart (Java, Python, .NET): aws lambda update-function-configuration --function-name orders-api --snap-start ApplyOn=PublishedVersions, then publish a version and point the alias at it
  2. Or use provisioned concurrency on an alias for predictable traffic
  3. Trim dependencies, initialize lazily, and raise memory (more CPU during init)

Prevent โ†’ Track Init Duration as an SLO input, and choose lighter runtimes or frameworks for latency-critical paths.

Copy link
Q147

Deploying fails: InvalidParameterValueException: Unzipped size must be smaller than 262144000 bytes.

Beginner

Likely causes โ†’ The function code plus all layers is larger than 250 MB unzipped. Large ML libraries (numpy, pandas, torch) or bundled test files and caches usually cause it.

Diagnose โ†’

bash
unzip -l function.zip | tail -1
aws lambda get-function --function-name ml-infer --query 'Configuration.Layers[].CodeSize'
du -sh package/* | sort -h | tail

Fix โ†’

  1. Package the function as a container image (up to 10 GB)
  2. Or remove tests, __pycache__ and docs from the package, and use AWS-provided layers (for example AWS SDK for pandas)

Prevent โ†’ Use container images for heavy dependencies, and fail CI builds when package size grows past a set budget.

Copy link
Q148

An SQS-triggered Lambda processes the same messages again and again, and some end up in the DLQ even though the code succeeded.

Intermediate

Likely causes โ†’ The queue's visibility timeout is shorter than the function timeout, so messages become visible again while they are still being processed. Or one failing record makes the whole batch retry, because partial batch responses are not enabled.

Diagnose โ†’

bash
aws sqs get-queue-attributes --queue-url <url> --attribute-names VisibilityTimeout RedrivePolicy
aws lambda get-function-configuration --function-name consumer --query Timeout
aws lambda list-event-source-mappings --function-name consumer --query 'EventSourceMappings[].[BatchSize,FunctionResponseTypes]'

Fix โ†’

  1. Set the visibility timeout to at least 6ร— the function timeout (AWS guidance)
  2. Turn on ReportBatchItemFailures and return only the failed message IDs: aws lambda update-event-source-mapping --uuid <id> --function-response-types ReportBatchItemFailures
  3. Make handlers idempotent

Prevent โ†’ Use a standard SQS-Lambda module with these defaults, and alarm on DLQ depth above 0.

Copy link
Q149

A Lambda dies with Runtime exited with error: signal: killed and Runtime.ExitError, and no stack trace.

Intermediate

Likely causes โ†’ The function ran out of memory. The REPORT line shows Max Memory Used equal to Memory Size. Large files loaded into memory, or a leak across warm invocations from global caches, are common reasons.

Diagnose โ†’

bash
aws logs filter-log-events --log-group-name /aws/lambda/etl \
  --filter-pattern 'REPORT' --max-items 5 --query 'events[].message'

Fix โ†’

  1. Raise MemorySize. Use Lambda Power Tuning to find the cheapest setting that works
  2. Stream large objects instead of loading them whole, and use /tmp (configurable up to 10 GB) for scratch space
  3. Clear global caches between invocations

Prevent โ†’ Alarm when Max Memory Used goes above 80% of the configured memory (through Lambda Insights).

Copy link
Q150

An S3-triggered Lambda bill exploded, and you get a notification that Lambda stopped a recursive invocation loop.

Advanced

Likely causes โ†’ The function writes its output back into the same bucket and prefix that triggers it, so every write triggers the function again. Lambda recursive loop detection (for SQS, SNS, S3 and Lambda) stops it after about 16 iterations, but only for supported patterns.

Diagnose โ†’

bash
aws s3api get-bucket-notification-configuration --bucket images
aws lambda get-function-recursion-config --function-name thumbnailer
aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name RecursiveInvocationsDropped \
  --dimensions Name=FunctionName,Value=thumbnailer --statistics Sum --period 300 \
  --start-time $(date -u -d '-1 day' +%FT%TZ) --end-time $(date -u +%FT%TZ)

Fix โ†’

  1. Set reserved concurrency to 0 right away to stop it: aws lambda put-function-concurrency --function-name thumbnailer --reserved-concurrent-executions 0
  2. Write output to a different bucket, or scope the trigger to the uploads/ prefix and write to thumbs/

Prevent โ†’ Keep recursion detection set to Terminate, use prefix or suffix filters on triggers, and set billing alarms on Lambda spend.

Copy link

Route 53, CloudFront, API Gateway and Messaging

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q151

You created a public hosted zone and records for example.com, but dig example.com returns NXDOMAIN or old records.

Beginner

Likely causes โ†’ The registrar still points to the old name servers, not to the four NS records of the new hosted zone. Another cause: two hosted zones exist for the same name and you edited the one that is not delegated.

Diagnose โ†’

bash
aws route53 list-hosted-zones-by-name --dns-name example.com
aws route53 get-hosted-zone --id Z0123ABC --query 'DelegationSet.NameServers'
dig NS example.com +short
dig @a.gtld-servers.net NS example.com +norecurse   # what the parent zone delegates to

Fix โ†’

  1. Update the NS at the registrar to match the zone's delegation set. For Route 53 Domains, run aws route53domains update-domain-nameservers
  2. Delete the duplicate zone

Prevent โ†’ Use one hosted zone per domain in IaC, with an output that checks delegation, and lower NS TTLs before migrations.

Copy link
Q152

InvalidChangeBatch: RRSet of type CNAME with DNS name example.com. is not permitted at apex in zone example.com.

Beginner

Likely causes โ†’ DNS does not allow a CNAME at the zone apex, because it would clash with the SOA and NS records there.

Diagnose โ†’

bash
aws route53 list-resource-record-sets --hosted-zone-id Z0123ABC --query "ResourceRecordSets[?Name=='example.com.']"

Fix โ†’ Use a Route 53 alias A/AAAA record to the ALB, CloudFront or S3 target:

bash
aws route53 change-resource-record-sets --hosted-zone-id Z0123ABC --change-batch '{
 "Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"example.com","Type":"A",
 "AliasTarget":{"HostedZoneId":"Z35SXDOTRQ7X7K","DNSName":"dualstack.web-123.us-east-1.elb.amazonaws.com","EvaluateTargetHealth":true}}}]}'

The alias HostedZoneId is the load balancer's canonical zone ID, not your zone's ID.

Prevent โ†’ Use alias records for AWS targets everywhere. They are free to query and follow IP changes automatically.

Copy link
Q153

The primary Region is down, but Route 53 failover records still send traffic to it.

Intermediate

Likely causes โ†’ The primary record has no health check associated, or EvaluateTargetHealth is false on the alias. The health check tests something that is still up (for example, the ALB answers / even though the app is broken). Or clients cache DNS beyond the TTL.

Diagnose โ†’

bash
aws route53 list-resource-record-sets --hosted-zone-id Z0123ABC \
  --query "ResourceRecordSets[?Failover!=null].[Name,Failover,HealthCheckId,AliasTarget.EvaluateTargetHealth]"
aws route53 get-health-check-status --health-check-id <id>

Fix โ†’

  1. Attach a health check that tests a deep /healthz endpoint (checking the app and its dependencies) to the PRIMARY record
  2. Set EvaluateTargetHealth: true on alias records
  3. Use a 60s TTL

Prevent โ†’ Run regular game days that fail the primary, and consider Route 53 ARC routing controls for manual, deterministic failover.

Copy link
Q154

A Route 53 health check reports Failure: Connection timed out for an endpoint that works fine from your laptop.

Intermediate

Likely causes โ†’ The SG, NACL or WAF does not allow the Route 53 health checker IP ranges. Other causes: the check uses HTTP while only HTTPS is open, or the host header or SNI is wrong.

Diagnose โ†’

bash
aws route53 get-health-check --health-check-id <id> --query 'HealthCheck.HealthCheckConfig'
aws route53 get-health-check-last-failure-reason --health-check-id <id>
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[]|select(.service=="ROUTE53_HEALTHCHECKS").ip_prefix' | head

Fix โ†’

  1. Allow the ROUTE53_HEALTHCHECKS ranges (or the managed prefix list com.amazonaws.route53-healthchecks where available) on the port
  2. Set FullyQualifiedDomainName and EnableSNI for HTTPS checks

Prevent โ†’ For private resources, use CloudWatch alarm-based (calculated) health checks, because Route 53 checkers cannot reach private IPs.

Copy link
Q155

You changed an A record an hour ago, but some users still reach the old server, and a newly created name returned NXDOMAIN for a while.

Advanced

Likely causes โ†’ Resolvers cache the old answer for the record's TTL (it was 86400). For the new name, the earlier NXDOMAIN was negatively cached for the SOA minimum TTL (default 900s in Route 53, but it can be set higher). Some clients and JVMs cache longer still.

Diagnose โ†’

bash
dig app.example.com +noall +answer          # remaining TTL from your resolver
dig @ns-123.awsdns-45.com app.example.com   # authoritative answer
aws route53 list-resource-record-sets --hosted-zone-id Z0123ABC --query "ResourceRecordSets[?Type=='SOA']"

Fix โ†’

  1. Wait it out, or keep the old server forwarding or redirecting until the TTL passes
  2. Flush local caches (resolvectl flush-caches)

Prevent โ†’ Lower TTLs to 60s at least one old-TTL period before a migration, avoid querying names before you create them, and keep the SOA negative TTL reasonable.

Copy link
Q156

CloudFront returns 403 AccessDenied (S3 XML) for every object after you switched the S3 origin to Origin Access Control.

Intermediate

Likely causes โ†’ The bucket policy does not allow the cloudfront.amazonaws.com service principal with AWS:SourceArn set to this distribution. Other causes: objects are SSE-KMS and the key policy does not allow CloudFront, the request has no default root object, or the key is missing (S3 returns 403 instead of 404 without s3:ListBucket).

Diagnose โ†’

bash
aws cloudfront get-distribution-config --id E123ABC --query 'DistributionConfig.[DefaultRootObject,Origins.Items[].[DomainName,OriginAccessControlId]]'
aws s3api get-bucket-policy --bucket site-assets --output text
aws s3api head-object --bucket site-assets --key index.html

Fix โ†’

json
{"Effect":"Allow","Principal":{"Service":"cloudfront.amazonaws.com"},
 "Action":"s3:GetObject","Resource":"arn:aws:s3:::site-assets/*",
 "Condition":{"StringEquals":{"AWS:SourceArn":"arn:aws:cloudfront::111111111111:distribution/E123ABC"}}}

Add a kms:Decrypt statement for CloudFront to the key policy if the objects use SSE-KMS, and set DefaultRootObject to index.html.

Prevent โ†’ Create the OAC, the bucket policy and the distribution together in one IaC module.

Copy link
Q157

CloudFront shows 502 ERROR. The request could not be satisfied. CloudFront wasn't able to connect to the origin.

Intermediate

Likely causes โ†’ The CloudFront โ†’ origin TLS handshake fails: the origin certificate does not match the origin domain name, it is self-signed or expired, or the chain is incomplete. Or the origin protocol policy is wrong (HTTPS-only to an origin that only speaks HTTP), or the SG blocks CloudFront.

Diagnose โ†’

bash
aws cloudfront get-distribution-config --id E123ABC \
  --query 'DistributionConfig.Origins.Items[].[DomainName,CustomOriginConfig]'
openssl s_client -connect origin.example.com:443 -servername origin.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -dates

Fix โ†’

  1. Use an origin domain covered by a valid public certificate (for example, an ACM certificate on the ALB for origin.example.com), and forward the matching Host or SNI
  2. Match the origin protocol policy and ports to what the origin serves
  3. Allow the com.amazonaws.global.cloudfront.origin-facing prefix list on the ALB SG

Prevent โ†’ Monitor origin certificate expiry, and use CloudFront VPC origins or origin-facing prefix lists for ALB origins.

Copy link
Q158

After deploying a new frontend build, users still see the old JavaScript for hours.

Beginner

Likely causes โ†’ CloudFront (and browsers) cache the objects for the TTL set by the cache policy or by Cache-Control headers. Files with the same name, such as app.js and index.html, are not refetched.

Diagnose โ†’

bash
curl -sI https://www.example.com/app.js | grep -iE 'x-cache|age|cache-control|etag'
aws cloudfront list-invalidations --distribution-id E123ABC --max-items 3

Fix โ†’

bash
aws cloudfront create-invalidation --distribution-id E123ABC --paths "/index.html" "/app.js"

Prevent โ†’ Use content-hashed asset names (app.3f9c2.js) with long TTLs and immutable. Give index.html Cache-Control: no-cache (or a short TTL), and invalidate only index.html on deploy.

Copy link
Q159

When editing a CloudFront distribution, your ACM certificate does not appear in the dropdown.

Beginner

Likely causes โ†’ CloudFront only uses ACM certificates from us-east-1 (N. Virginia). Other causes: the certificate is not yet ISSUED, or it does not cover the alternate domain name you added.

Diagnose โ†’

bash
aws acm list-certificates --region us-east-1 --query 'CertificateSummaryList[].[DomainName,Status]'
aws acm describe-certificate --region us-east-1 --certificate-arn <arn> --query 'Certificate.SubjectAlternativeNames'

Fix โ†’ Request the certificate in us-east-1 with every CNAME (or a wildcard), validate it by DNS, then attach it.

Prevent โ†’ In Terraform, use a provider alias for us-east-1 just for CloudFront certificates.

Copy link
Q160

CloudFront cache hit ratio is under 20% and origin load is high, even for static content.

Advanced

Likely causes โ†’ The cache key includes high-cardinality values: all query strings (tracking parameters like utm_*), all cookies, or headers like User-Agent or Authorization. Legacy "forward all" settings split the cache. Short TTLs or Cache-Control: no-store from the origin also prevent caching.

Diagnose โ†’

bash
aws cloudfront get-distribution-config --id E123ABC \
  --query 'DistributionConfig.DefaultCacheBehavior.[CachePolicyId,OriginRequestPolicyId,ForwardedValues]'
aws cloudfront get-cache-policy --id <policy-id>
# CloudFront standard logs / real-time logs: x-edge-result-type Miss vs Hit, by URI

Fix โ†’

  1. Use a cache policy with a minimal key (for example, CachingOptimized for static paths)
  2. Forward the values the origin needs through an origin request policy, which does not affect the cache key
  3. Normalize or strip query strings, and set proper Cache-Control at the origin

Prevent โ†’ Use separate behaviors for /static/* and /api/*, and alarm on CacheHitRate (with additional metrics turned on).

Copy link
Q161

A React SPA on S3 + CloudFront: / works, but refreshing /dashboard/settings returns 403 AccessDenied.

Intermediate

Likely causes โ†’ There is no S3 object at dashboard/settings. With OAC and no ListBucket, S3 returns 403 for missing keys, and the client-side router never loads.

Diagnose โ†’

bash
curl -sI https://app.example.com/dashboard/settings | head -3
aws cloudfront get-distribution-config --id E123ABC --query 'DistributionConfig.CustomErrorResponses'

Fix โ†’

  1. Add custom error responses that map 403 and 404 to /index.html with response code 200
  2. Or (cleaner) use a CloudFront Function on viewer-request that rewrites paths with no file extension to /index.html, so real API 404s are not masked

Prevent โ†’ Make it part of your SPA hosting module, and keep APIs on a separate behavior or origin.

Copy link
Q162

Adding an alternate domain name fails: CNAMEAlreadyExists: One or more of the CNAMEs you provided are already associated with a different resource.

Intermediate

Likely causes โ†’ Another distribution, possibly in another account (an old environment or a vendor), already has that alternate domain name.

Diagnose โ†’

bash
aws cloudfront list-conflicting-aliases --distribution-id E123ABC --alias www.example.com
aws cloudfront list-distributions --query "DistributionList.Items[?contains(Aliases.Items,'www.example.com')].Id"

Fix โ†’

  1. Same account: remove the alias from the old distribution, then add it to the new one
  2. Different account: prove ownership with a TXT record (_www.example.com pointing to the new distribution's domain) and run aws cloudfront associate-alias --target-distribution-id E123ABC --alias www.example.com

Prevent โ†’ Track aliases in IaC, and remove them when you decommission distributions.

Copy link
Q163

Calling your API returns {"message":"Missing Authentication Token"}.

Beginner

Likely causes โ†’ Despite the name, this almost always means the route does not exist: a wrong path or method, a missing stage in the URL (/prod/orders), or the API was not deployed after the change (REST APIs need a deployment).

Diagnose โ†’

bash
aws apigateway get-resources --rest-api-id abc123 --query 'items[].[path,resourceMethods]'
aws apigateway get-stages --rest-api-id abc123 --query 'item[].[stageName,deploymentId,lastUpdatedDate]'
curl -i https://abc123.execute-api.us-east-1.amazonaws.com/prod/orders

Fix โ†’

  1. Call the correct stage, path and method
  2. Redeploy: aws apigateway create-deployment --rest-api-id abc123 --stage-name prod

Prevent โ†’ Deploy APIs through IaC, which creates deployments automatically, and add a smoke test per route after each deploy.

Copy link
Q164

API Gateway returns 502 with {"message": "Internal server error"}, and the execution log shows Execution failed due to configuration error: Malformed Lambda proxy response.

Intermediate

Likely causes โ†’ With Lambda proxy integration, the function must return {"statusCode": int, "headers": {...}, "body": "<string>"}. A dict or object as body, a missing statusCode, or an unhandled exception all produce this error.

Diagnose โ†’

bash
aws apigateway update-stage --rest-api-id abc123 --stage-name prod \
  --patch-operations op=replace,path=/*/*/logging/loglevel,value=INFO
aws logs tail API-Gateway-Execution-Logs_abc123/prod --since 10m
aws lambda invoke --function-name orders-api --payload fileb://event.json out.json && cat out.json

Fix โ†’ Return the exact proxy shape and serialize the body:

python
return {"statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": json.dumps(result)}

Catch exceptions and return a 500 response yourself.

Prevent โ†’ Use a framework (Powertools for AWS Lambda event handler) that builds responses, and add contract tests with a sample API Gateway event.

Copy link
Q165

API Gateway returns 504 with {"message": "Endpoint request timed out"} on long requests.

Intermediate

Likely causes โ†’ The integration took longer than the integration timeout. The default is 29 seconds; for Regional and private REST APIs it can be raised with a quota increase, which may lower throttle limits.

Diagnose โ†’

bash
aws apigateway get-integration --rest-api-id abc123 --resource-id res1 --http-method POST --query timeoutInMillis
aws cloudwatch get-metric-statistics --namespace AWS/ApiGateway --metric-name IntegrationLatency \
  --dimensions Name=ApiName,Value=orders --extended-statistics p99 --period 60 \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)

Fix โ†’

  1. Make the long work asynchronous: the API puts a job on SQS or Step Functions and returns 202 with a job ID, and the client polls or gets a callback
  2. Optimize the backend call

Prevent โ†’ Design APIs so every synchronous call finishes in a few seconds.

Copy link
Q166

The browser shows a CORS error only when the API returns 401 or 4XX, while successful calls work.

Advanced

Likely causes โ†’ The Lambda adds Access-Control-Allow-Origin to its own responses, but errors produced by API Gateway itself (authorizer denies, throttling, missing routes) are gateway responses without CORS headers. The browser then hides the real 401 behind a CORS error.

Diagnose โ†’

bash
curl -i -X GET https://abc123.execute-api.us-east-1.amazonaws.com/prod/me -H 'Origin: https://app.example.com'
aws apigateway get-gateway-responses --rest-api-id abc123 --query 'items[].[responseType,responseParameters]'

Fix โ†’

bash
aws apigateway put-gateway-response --rest-api-id abc123 --response-type DEFAULT_4XX \
  --response-parameters '{"gatewayresponse.header.Access-Control-Allow-Origin":"'"'"'https://app.example.com'"'"'"}'
aws apigateway create-deployment --rest-api-id abc123 --stage-name prod

Do the same for DEFAULT_5XX. On HTTP APIs, use the built-in CORS configuration, which covers this.

Prevent โ†’ Define CORS once at the API level in IaC, and test error paths from a browser origin.

Copy link
Q167

A REST API returns {"message":"Forbidden"} (403) to a client that sends the right path.

Intermediate

Likely causes โ†’ The method requires an API key and the x-api-key header is missing, or the key is not in a usage plan tied to this stage. For a private API, the call does not come through the allowed VPC endpoint, or the resource policy denies it. A WAF rule may also block it.

Diagnose โ†’

bash
aws apigateway get-method --rest-api-id abc123 --resource-id res1 --http-method GET --query apiKeyRequired
aws apigateway get-usage-plans --query 'items[].[name,apiStages]'
aws apigateway get-rest-api --rest-api-id abc123 --query '[endpointConfiguration,policy]'

Fix โ†’

  1. Send x-api-key, and link the key to a usage plan with this stage: aws apigateway create-usage-plan-key --usage-plan-id up1 --key-id k1 --key-type API_KEY
  2. For private APIs, call through the execute-api VPC endpoint and allow aws:SourceVpce in the resource policy

Prevent โ†’ Do not use API keys as authentication (use IAM, Cognito or JWT authorizers), and turn on access logging with $context.error.responseType.

Copy link
Q168

Clients get 429 Too Many Requests with {"message":"Too Many Requests"} from API Gateway at modest traffic.

Beginner

Likely causes โ†’ Throttling at one of the levels: the usage plan or API key limit, a stage or method throttle set low, or the account-level Regional limit (10,000 rps steady with a 5,000 burst by default) shared by all APIs.

Diagnose โ†’

bash
aws apigateway get-stage --rest-api-id abc123 --stage-name prod --query methodSettings
aws apigateway get-usage-plan --usage-plan-id up1 --query '[throttle,quota]'
aws apigateway get-account --query throttleSettings

Fix โ†’

  1. Raise the stage, method or usage plan throttles to match the expected load
  2. Request an account limit increase if needed
  3. Make clients retry with backoff and jitter

Prevent โ†’ Load-test with real limits, alarm on the 4XXError rate, and document per-client quotas.

Copy link
Q169

Messages keep landing in the SQS dead-letter queue even though consumers look healthy.

Intermediate

Likely causes โ†’ Each message was received maxReceiveCount times without being deleted. Reasons: consumers crash or time out on certain payloads ("poison messages"), the visibility timeout is too short, or the code never calls DeleteMessage.

Diagnose โ†’

bash
aws sqs get-queue-attributes --queue-url <main-url> --attribute-names RedrivePolicy VisibilityTimeout
aws sqs receive-message --queue-url <dlq-url> --max-number-of-messages 5 \
  --attribute-names ApproximateReceiveCount --message-attribute-names All

Fix โ†’

  1. Inspect the DLQ payloads, and fix the parser or the code path
  2. Make sure consumers delete messages only after success
  3. Once fixed, redrive: aws sqs start-message-move-task --source-arn <dlq-arn> --destination-arn <main-arn>

Prevent โ†’ Alarm on ApproximateNumberOfMessagesVisible above 0 on every DLQ, and log the message ID on failures.

Copy link
Q170

You subscribed an email address to an SNS topic, but nothing arrives when you publish.

Beginner

Likely causes โ†’ The subscription is still PendingConfirmation; the recipient never clicked the confirmation link (check spam). Another cause: a filter policy on the subscription does not match the message attributes.

Diagnose โ†’

bash
aws sns list-subscriptions-by-topic --topic-arn arn:aws:sns:us-east-1:111111111111:alerts \
  --query 'Subscriptions[].[Protocol,Endpoint,SubscriptionArn]'
aws sns get-subscription-attributes --subscription-arn <arn> --query 'Attributes.FilterPolicy'

Fix โ†’

  1. Confirm the subscription, or delete it and subscribe again to resend the email
  2. Fix or remove the filter policy
  3. Publish a test message: aws sns publish --topic-arn <arn> --message test

Prevent โ†’ Prefer chat integrations (Amazon Q Developer in chat applications, formerly AWS Chatbot) or an SQS/Lambda fan-out over personal emails for operations alerts.

Copy link
Q171

SNS in account A publishes successfully, but the SQS queue in account B never receives anything.

Intermediate

Likely causes โ†’ The SQS queue policy does not allow sqs:SendMessage from sns.amazonaws.com with aws:SourceArn set to the topic. The queue uses SSE with the AWS managed key aws/sqs, which SNS cannot use. Or the cross-account subscription was never confirmed.

Diagnose โ†’

bash
aws sqs get-queue-attributes --queue-url <url> --attribute-names Policy KmsMasterKeyId
aws sns list-subscriptions-by-topic --topic-arn <topic-arn>
# SNS delivery status logging / NumberOfNotificationsFailed metric on the topic

Fix โ†’

  1. Add a queue policy statement that allows sns.amazonaws.com with "ArnEquals":{"aws:SourceArn":"<topic-arn>"}
  2. Switch the queue to a CMK whose key policy allows sns.amazonaws.com to use kms:GenerateDataKey* and kms:Decrypt, or to SSE-SQS
  3. Confirm the subscription from account B

Prevent โ†’ Use a reusable cross-account fan-out module, and alarm on NumberOfNotificationsFailed.

Copy link
Q172

An SQS FIFO queue has thousands of messages, but consumers receive nothing for minutes at a time.

Advanced

Likely causes โ†’ FIFO guarantees order per message group. While a message from a group is in flight (received but not deleted), no other message in that group is delivered. If most messages share one MessageGroupId, a single slow or failing message blocks everything behind it until the visibility timeout ends.

Diagnose โ†’

bash
aws sqs get-queue-attributes --queue-url <fifo-url> \
  --attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible VisibilityTimeout RedrivePolicy
# check producer code: what is MessageGroupId set to?

Fix โ†’

  1. Use a finer-grained group ID (per customer or order), so groups process in parallel
  2. Add a DLQ so poison messages leave the group
  3. Make sure consumers delete or extend visibility promptly

Prevent โ†’ Choose the group key for the ordering you really need. Use high-throughput FIFO mode only with many groups.

Copy link
Q173

An EventBridge rule should trigger a Lambda on EC2 state changes, but the Lambda never runs.

Advanced

Likely causes โ†’ The event pattern does not match: a typo, wrong case, or values not wrapped in arrays. The rule is on the wrong event bus or Region. The Lambda resource policy does not allow events.amazonaws.com, which shows up as FailedInvocations. Or the rule is disabled.

Diagnose โ†’

bash
aws events describe-rule --name ec2-state --query '[State,EventBusName,EventPattern]'
aws events test-event-pattern --event-pattern file://pattern.json --event file://sample-event.json
aws cloudwatch get-metric-statistics --namespace AWS/Events --metric-name FailedInvocations \
  --dimensions Name=RuleName,Value=ec2-state --statistics Sum --period 300 \
  --start-time $(date -u -d '-1 day' +%FT%TZ) --end-time $(date -u +%FT%TZ)
aws lambda get-policy --function-name on-ec2-change

Fix โ†’

  1. Correct the pattern, for example {"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["stopped"]}}
  2. Add the permission: aws lambda add-permission --function-name on-ec2-change --statement-id evb --action lambda:InvokeFunction --principal events.amazonaws.com --source-arn <rule-arn>
  3. Add a DLQ on the target

Prevent โ†’ Unit-test patterns with test-event-pattern in CI, and alarm on FailedInvocations.

Copy link
Q174

Kinesis consumers fall behind: GetRecords.IteratorAgeMilliseconds keeps rising, and producers see ProvisionedThroughputExceededException.

Advanced

Likely causes โ†’ Shards are saturated (1 MB/s or 1,000 records/s in, 2 MB/s out per shard), often because of a hot partition key. Too many consumers share the 5 reads/s per shard limit. Or the consumer is slow (a Lambda batch that keeps failing and retrying blocks the shard).

Diagnose โ†’

bash
aws kinesis describe-stream-summary --stream-name clicks --query 'StreamDescriptionSummary.[StreamModeDetails,OpenShardCount]'
aws cloudwatch get-metric-statistics --namespace AWS/Kinesis --metric-name WriteProvisionedThroughputExceeded \
  --dimensions Name=StreamName,Value=clicks --statistics Sum --period 60 \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)
aws lambda list-event-source-mappings --function-name clicks-consumer --query 'EventSourceMappings[].[BatchSize,ParallelizationFactor,BisectBatchOnFunctionError]'

Fix โ†’

  1. Switch to on-demand mode, or reshard: aws kinesis update-shard-count --stream-name clicks --target-shard-count 8 --scaling-type UNIFORM_SCALING
  2. Use a high-cardinality partition key
  3. Use enhanced fan-out for multiple consumers
  4. On the Lambda mapping, set ParallelizationFactor, BisectBatchOnFunctionError, MaximumRetryAttempts and an on-failure destination

Prevent โ†’ Alarm on iterator age, and turn on shard-level metrics to spot hot shards.

Copy link
Q175

The SDK fails with AWS.SimpleQueueService.NonExistentQueue: The specified queue does not exist. but the queue is in the console.

Beginner

Likely causes โ†’ The client is in a different Region or account from the queue, the queue URL or name has a typo (FIFO queues need the .fifo suffix), or the queue was deleted and re-created within 60 seconds.

Diagnose โ†’

bash
aws sts get-caller-identity
aws sqs get-queue-url --queue-name orders.fifo --region eu-west-1
aws sqs list-queues --queue-name-prefix orders --region eu-west-1

Fix โ†’ Use the full queue URL from get-queue-url with the matching Region, and add --queue-owner-aws-account-id for cross-account queues.

Prevent โ†’ Inject queue URLs from IaC outputs through environment variables or SSM, never hand-typed names.

Copy link

CloudFormation, CloudWatch, KMS, Secrets and Cost

๐ŸŽฅ Learn this hands-on with DevOps Shack โ†’ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com

Q176

Updating a stack fails: Stack:arn:aws:cloudformation:...:stack/app/... is in ROLLBACK_COMPLETE state and can not be updated.

Beginner

Likely causes โ†’ The first create of the stack failed and rolled back. A stack in ROLLBACK_COMPLETE cannot be updated; it can only be deleted.

Diagnose โ†’

bash
aws cloudformation describe-stack-events --stack-name app \
  --query "StackEvents[?ResourceStatus=='CREATE_FAILED'].[LogicalResourceId,ResourceStatusReason]" --output table

Fix โ†’

  1. Read the first CREATE_FAILED reason and fix the template
  2. Run aws cloudformation delete-stack --stack-name app && aws cloudformation wait stack-delete-complete --stack-name app
  3. Create the stack again

Prevent โ†’ Use --disable-rollback (or --on-failure DO_NOTHING) in dev to debug failed creates, and run cfn-lint in CI.

Copy link
Q177

A stack is stuck in UPDATE_ROLLBACK_FAILED.

Advanced

Likely causes โ†’ During rollback, CloudFormation could not return a resource to its old state. Typical reasons: the resource was changed or deleted outside CloudFormation, a dependency is gone, or permissions were removed.

Diagnose โ†’

bash
aws cloudformation describe-stack-events --stack-name app \
  --query "StackEvents[?contains(ResourceStatus,'FAILED')].[Timestamp,LogicalResourceId,ResourceStatusReason]" --max-items 10

Fix โ†’

  1. Fix the underlying issue if you can (re-create the deleted dependency, restore permissions)
  2. Run aws cloudformation continue-update-rollback --stack-name app
  3. If a resource cannot be recovered, skip it: aws cloudformation continue-update-rollback --stack-name app --resources-to-skip MyBrokenResource. Then reconcile that resource manually, because CloudFormation now treats it as matching the old template

Prevent โ†’ Never change stack resources by hand. Use stack policies and drift detection, and deploy through change sets.

Copy link
Q178

A pipeline fails with An error occurred (ValidationError) when calling the UpdateStack operation: No updates are to be performed.

Beginner

Likely causes โ†’ The template and parameters are identical to what is deployed. CloudFormation treats this as an error for update-stack.

Diagnose โ†’

bash
aws cloudformation get-template --stack-name app --query TemplateBody > deployed.yaml
diff deployed.yaml template.yaml

Fix โ†’ Use aws cloudformation deploy --no-fail-on-empty-changeset, which handles this case. Or catch that specific message and treat it as success.

Prevent โ†’ Deploy with aws cloudformation deploy or change sets in pipelines, not raw update-stack.

Copy link
Q179

InsufficientCapabilitiesException: Requires capabilities : [CAPABILITY_NAMED_IAM].

Beginner

Likely causes โ†’ The template creates IAM resources with custom names (RoleName, PolicyName). CloudFormation makes you acknowledge that explicitly. Templates that use Transform macros (SAM) also need CAPABILITY_AUTO_EXPAND.

Diagnose โ†’

bash
grep -nE 'AWS::IAM::|RoleName|Transform' template.yaml

Fix โ†’

bash
aws cloudformation deploy --template-file template.yaml --stack-name app \
  --capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND

Prevent โ†’ Avoid hard-coded IAM names (let CloudFormation generate them) so you only need CAPABILITY_IAM, and let only reviewed pipelines pass capabilities.

Copy link
Q180

Stack deletion ends in DELETE_FAILED with The bucket you tried to delete is not empty on an S3 bucket resource.

Intermediate

Likely causes โ†’ CloudFormation does not empty buckets. A non-empty or versioned bucket blocks deletion. The same thing happens with ECR repositories that contain images and security groups still attached to ENIs.

Diagnose โ†’

bash
aws cloudformation describe-stack-events --stack-name app \
  --query "StackEvents[?ResourceStatus=='DELETE_FAILED'].[LogicalResourceId,PhysicalResourceId,ResourceStatusReason]"

Fix โ†’

  1. Empty the bucket, including all versions (see Q82), then delete the stack again
  2. Or keep the bucket: aws cloudformation delete-stack --stack-name app --retain-resources LogsBucket (only allowed when the stack is in DELETE_FAILED)

Prevent โ†’ Set DeletionPolicy: Retain on data buckets, and use auto-delete custom resources (CDK autoDeleteObjects) only for ephemeral stacks.

Copy link
Q181

Drift detection shows MODIFIED on a security group and an RDS instance that someone changed in the console. How do you reconcile?

Advanced

Likely causes โ†’ Changes made outside CloudFormation (console hotfix during an incident). The next stack update may silently undo them, or fail.

Diagnose โ†’

bash
ID=$(aws cloudformation detect-stack-drift --stack-name app --query StackDriftDetectionId --output text)
aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id $ID
aws cloudformation describe-stack-resource-drifts --stack-name app --stack-resource-drift-status-filters MODIFIED DELETED \
  --query 'StackResourceDrifts[].[LogicalResourceId,PropertyDifferences]'

Fix โ†’

  1. Decide which version is correct
  2. If the console change should stay, put it into the template and deploy a change set (it should show no replacement)
  3. If not, deploy the template to overwrite it
  4. For resources deleted out of band, remove them from the template, or re-create and import them (create-change-set --change-set-type IMPORT)

Prevent โ†’ Run scheduled drift detection (AWS Config rule cloudformation-stack-drift-detection-check), make production console access read-only, and have a break-glass process that requires a follow-up PR.

Copy link
Q182

Deleting or updating a stack fails: Export network-VpcId cannot be deleted as it is in use by app-stack.

Intermediate

Likely causes โ†’ Another stack imports the output through Fn::ImportValue. CloudFormation will not let you change or remove an export while it is imported.

Diagnose โ†’

bash
aws cloudformation list-imports --export-name network-VpcId
aws cloudformation list-exports --query "Exports[?Name=='network-VpcId']"

Fix โ†’

  1. In the importing stacks, replace ImportValue with a hard-coded value or an SSM parameter and deploy them
  2. Then change or remove the export in the producer stack

Prevent โ†’ For loose coupling, share values between stacks through SSM Parameter Store ({{resolve:ssm:/network/vpc-id}}) rather than exports.

Copy link
Q183

A stack has been in CREATE_IN_PROGRESS for an hour on a Custom::DbSeeder resource.

Advanced

Likely causes โ†’ The custom resource Lambda never sent a response to the pre-signed ResponseURL. It crashed, timed out, could not reach S3 (in a VPC without NAT or an endpoint), or forgot to answer on Delete. CloudFormation waits up to the service timeout, which is one hour by default.

Diagnose โ†’

bash
aws cloudformation describe-stack-resource --stack-name app --logical-resource-id DbSeeder
aws logs tail /aws/lambda/app-DbSeeder --since 2h

Fix โ†’

  1. To unblock now, send a response yourself with curl -X PUT -H 'Content-Type:' --data-binary '{"Status":"FAILURE","Reason":"manual","PhysicalResourceId":"seed","StackId":"...","RequestId":"...","LogicalResourceId":"DbSeeder"}' "<ResponseURL from logs>"
  2. Fix the handler so it always responds in try/finally, including on Delete

Prevent โ†’ Use the cfn-response module or CDK Provider framework, and set ServiceTimeout on the custom resource to something short (for example, 300 seconds).

Copy link
Q184

A CloudWatch alarm on a custom metric stays in INSUFFICIENT_DATA forever.

Beginner

Likely causes โ†’ The alarm's namespace, metric name or dimensions do not match exactly what is published (an alarm must specify all dimensions). Other causes: the period is shorter than the publish interval, or the metric stopped being sent.

Diagnose โ†’

bash
aws cloudwatch describe-alarms --alarm-names api-errors \
  --query 'MetricAlarms[].[Namespace,MetricName,Dimensions,Period,StateReason]'
aws cloudwatch list-metrics --namespace MyApp --metric-name Errors

Fix โ†’

  1. Copy the exact dimension set from list-metrics into the alarm
  2. Make the period match the publishing rate
  3. For sparse metrics, set --treat-missing-data notBreaching

Prevent โ†’ Create alarms in the same IaC module that defines the metric names, and test alarms with set-alarm-state.

Copy link
Q185

The CloudWatch agent is running, but no mem_used_percent or disk metrics appear in the CWAgent namespace.

Intermediate

Likely causes โ†’ The agent was started with the default or no config, so the metrics section is missing. Other causes: the instance role has no CloudWatchAgentServerPolicy, or the agent cannot reach the CloudWatch endpoint (private subnet with no monitoring endpoint).

Diagnose โ†’

bash
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status
sudo tail -50 /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
aws cloudwatch list-metrics --namespace CWAgent --dimensions Name=InstanceId,Value=i-0abc

Fix โ†’

bash
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
  -a fetch-config -m ec2 -s -c ssm:AmazonCloudWatch-linux

Attach CloudWatchAgentServerPolicy, and add the monitoring and logs endpoints for private subnets.

Prevent โ†’ Store the agent config in SSM Parameter Store, and push it with State Manager to every instance.

Copy link
Q186

An app writes logs, but its CloudWatch log group stays empty.

Intermediate

Likely causes โ†’ The role cannot write logs (logs:CreateLogStream, logs:PutLogEvents, or logs:CreateLogGroup if the group does not exist). The log group is KMS-encrypted and the key policy does not allow the logs.<region>.amazonaws.com principal. Or you are looking in the wrong Region or group name.

Diagnose โ†’

bash
aws logs describe-log-groups --log-group-name-prefix /aws/lambda/orders --query 'logGroups[].[logGroupName,kmsKeyId]'
aws logs describe-log-streams --log-group-name /aws/lambda/orders --order-by LastEventTime --descending --max-items 3
aws iam list-attached-role-policies --role-name orders-lambda-role

Fix โ†’

  1. For Lambda, attach AWSLambdaBasicExecutionRole. For ECS, give the execution role logs:* on the group
  2. Create the group in IaC with retention set
  3. Fix the KMS key policy for CloudWatch Logs

Prevent โ†’ Pre-create every log group with retention and permissions, rather than relying on auto-create, which also means infinite retention.

Copy link
Q187

A CPU alarm flaps between OK and ALARM every few minutes and pages the on-call engineer all night.

Intermediate

Likely causes โ†’ The alarm uses 1 datapoint of 1 over a short period on a noisy metric. Or missing data is treated as breaching while the metric is published irregularly.

Diagnose โ†’

bash
aws cloudwatch describe-alarm-history --alarm-name web-cpu --history-item-type StateUpdate --max-items 20 \
  --query 'AlarmHistoryItems[].[Timestamp,HistorySummary]'
aws cloudwatch describe-alarms --alarm-names web-cpu \
  --query 'MetricAlarms[].[Period,EvaluationPeriods,DatapointsToAlarm,TreatMissingData,Threshold]'

Fix โ†’

bash
aws cloudwatch put-metric-alarm --alarm-name web-cpu --namespace AWS/EC2 --metric-name CPUUtilization \
  --dimensions Name=AutoScalingGroupName,Value=web-asg --statistic Average --period 60 \
  --evaluation-periods 5 --datapoints-to-alarm 4 --threshold 85 --comparison-operator GreaterThanThreshold \
  --treat-missing-data notBreaching --alarm-actions <sns-arn>

Use composite alarms (for example, high CPU and high latency) for paging.

Prevent โ†’ Page on symptoms (SLO burn, errors, latency) and send resource alarms to tickets.

Copy link
Q188

Decrypt calls fail with KMSInvalidStateException: arn:aws:kms:...:key/... is pending deletion.

Intermediate

Likely causes โ†’ Someone scheduled the key for deletion (7โ€“30 day waiting period). While pending, the key cannot be used, and everything encrypted with it stops working.

Diagnose โ†’

bash
aws kms describe-key --key-id <key-id> --query 'KeyMetadata.[KeyState,DeletionDate]'
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=ScheduleKeyDeletion --max-results 5

Fix โ†’

bash
aws kms cancel-key-deletion --key-id <key-id>
aws kms enable-key --key-id <key-id>      # cancel leaves it Disabled

Prevent โ†’ Deny kms:ScheduleKeyDeletion through SCP except for a break-glass role, alarm on that CloudTrail event through EventBridge, and use the 30-day window.

Copy link
Q189

A cross-account decrypt fails: AccessDeniedException: The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access it.

Advanced

Likely causes โ†’ One of three: (1) the key is in another Region, because KMS keys are Regional unless multi-Region, (2) the key policy in the owning account does not allow the caller's account or role, or (3) the caller's IAM policy has no kms:Decrypt on the key ARN. Cross-account access needs both the key policy and IAM. The error deliberately does not say which one failed.

Diagnose โ†’

bash
aws kms describe-key --key-id arn:aws:kms:us-east-1:222222222222:key/abcd... --query 'KeyMetadata.[Arn,KeyState,MultiRegion]'
aws kms get-key-policy --key-id <arn> --policy-name default --output text   # run in owning account
aws iam simulate-principal-policy --policy-source-arn <caller-role-arn> --action-names kms:Decrypt --resource-arns <key-arn>

Fix โ†’

  1. Add a key policy statement allowing arn:aws:iam::111111111111:role/consumer to use kms:Decrypt and kms:DescribeKey
  2. Add a matching IAM allow on the consumer role, referencing the key ARN (not an alias)
  3. Call KMS in the key's Region, or use a multi-Region replica

Prevent โ†’ Template cross-account key grants, and use encryption context conditions to scope them.

Copy link
Q190

Under load, S3 and SSM calls start failing with ThrottlingException: You have exceeded the rate at which you may call KMS. Reduce the frequency of your calls.

Advanced

Likely causes โ†’ Every SSE-KMS object read or write, every SecureString parameter read and every envelope encryption call hits KMS, and they share a per-account, per-Region request quota for cryptographic operations (thousands of requests per second, depending on the Region).

Diagnose โ†’

bash
aws service-quotas list-service-quotas --service-code kms \
  --query "Quotas[?contains(QuotaName,'Cryptographic operations')].[QuotaName,Value]"
# CloudWatch AWS/Usage: Service=KMS, Type=API, Resource=Decrypt/GenerateDataKey
aws s3api get-bucket-encryption --bucket data --query 'ServerSideEncryptionConfiguration.Rules[].BucketKeyEnabled'

Fix โ†’

  1. Turn on S3 Bucket Keys, which cut KMS calls from S3 by up to 99%: aws s3api put-bucket-encryption --bucket data --server-side-encryption-configuration '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"aws:kms","KMSMasterKeyID":"<key>"},"BucketKeyEnabled":true}]}'
  2. Cache decrypted secrets and parameters in the app (Secrets Manager caching client, Parameters and Secrets Lambda extension)
  3. Use data key caching (AWS Encryption SDK)
  4. Request a quota increase

Prevent โ†’ Alarm on KMS usage at 70% of the quota, and design for caching from the start.

Copy link
Q191

ResourceNotFoundException: Secrets Manager can't find the specified secret. but the secret is in the console.

Beginner

Likely causes โ†’ The call goes to the wrong Region or account. Or the code uses a partial ARN: Secrets Manager adds a random 6-character suffix to ARNs, so arn:...:secret:prod/db without the suffix fails, while the name prod/db works. The secret may also be scheduled for deletion.

Diagnose โ†’

bash
aws secretsmanager describe-secret --secret-id prod/db --region us-east-1 --query '[ARN,DeletedDate]'
aws secretsmanager list-secrets --filters Key=name,Values=prod/ --region us-east-1 --query 'SecretList[].Name'

Fix โ†’

  1. Reference the secret by name, or by full ARN including the suffix
  2. Set the Region explicitly
  3. If the secret is pending deletion: aws secretsmanager restore-secret --secret-id prod/db

Prevent โ†’ Pass secret ARNs from IaC outputs, and in IAM policies use secret:prod/db-?????? to match the suffix.

Copy link
Q192

Secrets Manager rotation fails, and the secret shows AWSPENDING stuck on a version.

Advanced

Likely causes โ†’ The rotation Lambda failed in one of its four steps (createSecret, setSecret, testSecret, finishSecret). Common reasons: it cannot reach the DB (VPC or SG), it cannot reach the Secrets Manager endpoint from a private subnet, the DB user has no rights to change its password, or a previous failed rotation left AWSPENDING behind, which blocks the next try.

Diagnose โ†’

bash
aws secretsmanager describe-secret --secret-id prod/db --query '[RotationEnabled,LastRotatedDate,VersionIdsToStages]'
aws logs tail /aws/lambda/SecretsManagerRDSPostgreSQLRotationSingleUser --since 2h

Fix โ†’

  1. Fix the network path: the Lambda must reach both the DB and the secretsmanager endpoint
  2. Remove the stale stage: aws secretsmanager update-secret-version-stage --secret-id prod/db --version-stage AWSPENDING --remove-from-version-id <id>
  3. Retry: aws secretsmanager rotate-secret --secret-id prod/db

Prevent โ†’ Prefer RDS managed master passwords, use the alternating-users strategy for apps, and alarm on rotation failures through EventBridge (RotationFailed).

Copy link
Q193

aws ssm get-parameter --name /prod/db/password returns an encrypted blob instead of the password.

Beginner

Likely causes โ†’ The parameter is a SecureString, and the call did not ask for decryption. If you add the flag and get AccessDeniedException, the caller has no kms:Decrypt on the key.

Diagnose โ†’

bash
aws ssm describe-parameters --parameter-filters Key=Name,Values=/prod/db/password --query 'Parameters[].[Type,KeyId]'

Fix โ†’

bash
aws ssm get-parameter --name /prod/db/password --with-decryption --query Parameter.Value --output text
aws ssm get-parameters-by-path --path /prod/db --recursive --with-decryption

Grant ssm:GetParameter* on arn:aws:ssm:...:parameter/prod/db/* and kms:Decrypt on the key.

Prevent โ†’ Scope parameter access by path per service, and use ParameterNotFound checks in startup code so missing config fails fast.

Copy link
Q194

Re-creating a secret fails: InvalidRequestException: You can't create this secret because a secret with this name is already scheduled for deletion.

Beginner

Likely causes โ†’ A secret with that name was deleted with a recovery window (7โ€“30 days) and is still recoverable. This often happens in IaC teardown and re-create cycles.

Diagnose โ†’

bash
aws secretsmanager describe-secret --secret-id dev/api-key --query '[Name,DeletedDate]'

Fix โ†’

  1. To reuse it, restore it: aws secretsmanager restore-secret --secret-id dev/api-key
  2. For dev only, force deletion now: aws secretsmanager delete-secret --secret-id dev/api-key --force-delete-without-recovery

Prevent โ†’ For ephemeral environments, set recovery_window_in_days = 0 in Terraform, and keep a 30-day window in production.

Copy link
Q195

A production security group rule disappeared overnight. How do you find out who removed it?

Beginner

Likely causes โ†’ A manual console change, an automation job, or an IaC apply that removed the rule as drift.

Diagnose โ†’

bash
aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceName,AttributeValue=sg-0abc \
  --start-time $(date -u -d '-2 day' +%FT%TZ) \
  --query 'Events[].[EventTime,EventName,Username]' --output table
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=RevokeSecurityGroupIngress --max-results 10
aws configservice get-resource-config-history --resource-type AWS::EC2::SecurityGroup --resource-id sg-0abc --limit 5

Fix โ†’

  1. Restore the rule through IaC
  2. Find the principal (userIdentity.arn, sourceIPAddress, user agent such as Terraform) and close the gap

Prevent โ†’ Keep an organization trail with Athena queries, AWS Config rules for SG baselines, and EventBridge alerts on SG changes in production. Note that lookup-events covers only 90 days of management events.

Copy link
Q196

The NAT Gateway line is the second-biggest item on the AWS bill.

Intermediate

Likely causes โ†’ NAT charges per GB processed as well as per hour. Big traffic through NAT, such as pulling container images, S3 or DynamoDB transfers, or backups, adds up quickly. Cross-AZ NAT usage adds data transfer charges on top.

Diagnose โ†’

bash
aws ce get-cost-and-usage --time-period Start=2026-10-01,End=2026-11-01 --granularity MONTHLY --metrics UnblendedCost \
  --filter '{"Dimensions":{"Key":"USAGE_TYPE_GROUP","Values":["EC2: NAT Gateway - Data Processed"]}}'
# CloudWatch AWS/NATGateway BytesOutToDestination per NAT
# VPC Flow Logs on the NAT ENI -> top destinations by bytes (Athena)

Fix โ†’

  1. Add free gateway endpoints for S3 and DynamoDB
  2. Add interface endpoints for ECR, Logs and STS where the volume justifies their hourly cost
  3. Use one NAT per AZ with AZ-local routes
  4. Cache images (ECR pull-through cache)

Prevent โ†’ Tag and dashboard NAT bytes, and review the top talkers through flow logs every month.

Copy link
Q197

Data transfer costs jumped after you spread services across three AZs.

Advanced

Likely causes โ†’ Inter-AZ traffic is charged in both directions (about $0.01/GB each way). Chatty microservices, Kafka or Elasticsearch replication, and cross-AZ load balancing to targets (on ALB it is free inside the LB; on NLB with cross-zone on, you pay inter-AZ) add up. Calling through public IPs or Elastic IPs inside the Region costs even more.

Diagnose โ†’

bash
aws ce get-cost-and-usage --time-period Start=2026-10-01,End=2026-11-01 --granularity DAILY \
  --metrics UnblendedCost --group-by Type=DIMENSION,Key=USAGE_TYPE \
  --filter '{"Dimensions":{"Key":"SERVICE","Values":["Amazon Elastic Compute Cloud - Compute","EC2 - Other"]}}' \
  --query 'ResultsByTime[-1].Groups[?contains(Keys[0],`DataTransfer-Regional`)]'
# Flow logs with az-id fields to find top cross-AZ pairs

Fix โ†’

  1. Use topology-aware routing (Kubernetes trafficDistribution: PreferClose, or Istio locality LB)
  2. Use rack- or AZ-aware consumers (Kafka client.rack)
  3. Use private IPs, not public ones, for in-Region calls

Prevent โ†’ Make data transfer a design review item, and put cross-AZ bytes on a dashboard per service.

Copy link
Q198

A budget alert fired at 120% of forecast mid-month. How do you find what is spending money?

Intermediate

Likely causes โ†’ A new or forgotten resource (a big instance, a GPU node pool, a NAT), runaway usage (Lambda loop, logs ingestion), or a missing commitment discount.

Diagnose โ†’

bash
aws ce get-cost-and-usage --time-period Start=2026-11-01,End=2026-11-09 --granularity DAILY \
  --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE \
  --query 'ResultsByTime[-1].Groups | sort_by(@,&to_number(Metrics.UnblendedCost.Amount))[-5:]'
aws ce get-cost-and-usage --time-period Start=2026-11-01,End=2026-11-09 --granularity DAILY \
  --metrics UnblendedCost --group-by Type=DIMENSION,Key=LINKED_ACCOUNT
aws ce get-anomalies --date-interval StartDate=2026-11-01,EndDate=2026-11-09

Fix โ†’

  1. Drill down from service to usage type, then account, then tag (Type=TAG,Key=team)
  2. Stop or right-size the offender
  3. Fix the runaway trigger

Prevent โ†’ Turn on Cost Anomaly Detection with alerts to a channel, use per-team budgets with actions, and enforce cost allocation tags.

Copy link
Q199

All dev instances are stopped every night, yet the account still costs money each day.

Beginner

Likely causes โ†’ Stopped instances still have charged EBS volumes. Other charges continue too: snapshots, Elastic IPs and all public IPv4 addresses (charged hourly since February 2024), NAT gateways, load balancers, RDS instances (which also restart automatically after 7 days stopped) and CloudWatch Logs storage.

Diagnose โ†’

bash
aws ec2 describe-volumes --filters Name=status,Values=available --query 'Volumes[].[VolumeId,Size,CreateTime]'
aws ec2 describe-addresses --query 'Addresses[?AssociationId==null].[PublicIp,AllocationId]'
aws ec2 describe-nat-gateways --filter Name=state,Values=available --query 'NatGateways[].NatGatewayId'
aws elbv2 describe-load-balancers --query 'LoadBalancers[].LoadBalancerName'

Fix โ†’

  1. Delete unattached volumes and unused EIPs
  2. Expire old snapshots with Data Lifecycle Manager
  3. Remove idle NATs and ALBs in dev (recreate them with IaC when needed)

Prevent โ†’ Run ephemeral dev environments from IaC that are destroyed nightly, and use Trusted Advisor or Compute Optimizer idle-resource checks.

Copy link
Q200

You bought a Compute Savings Plan last month, but Cost Explorer shows only 40% coverage and costs barely moved.

Advanced

Likely causes โ†’ The commitment covers less spend than you thought (the commitment is $/hour of discounted usage). Other reasons: most spend is on services the plan does not cover (RDS, OpenSearch, ElastiCache and Redshift are not covered by Compute Savings Plans and need their own Reserved Instances), usage is in member accounts with discount sharing turned off, or you bought an EC2 Instance Savings Plan locked to a family and Region you then moved away from.

Diagnose โ†’

bash
aws ce get-savings-plans-coverage --time-period Start=2026-10-01,End=2026-11-01 --granularity MONTHLY
aws ce get-savings-plans-utilization --time-period Start=2026-10-01,End=2026-11-01
aws savingsplans describe-savings-plans --query 'savingsPlans[].[savingsPlanType,commitment,region,ec2InstanceFamily,state]'
aws ce get-savings-plans-purchase-recommendation --savings-plans-type COMPUTE_SP --term-in-years ONE_YEAR \
  --payment-option NO_UPFRONT --lookback-period-in-days THIRTY_DAYS

Fix โ†’

  1. If utilization is low, move workloads onto the covered family or Region, or switch to Compute SP for new purchases
  2. If coverage is low, layer extra commitments based on the recommendation, plus RIs for databases
  3. Turn on RI/SP discount sharing in the payer account

Prevent โ†’ Buy in small tranches every quarter based on a steady-state baseline, prefer Compute SP for flexibility, and alarm on utilization below 95%.

Copy link
Feedback