AWS IAM, KMS, Secrets Manager and GuardDuty Interview Questions: Hands-On CLI and Security Scenarios (50 Questions)
This page has 50 hands-on security interview questions on IAM, KMS, Secrets Manager and GuardDuty, with full answers. The basic ideas are in Sets 1 and 2. Here you practise the commands, error messages and situations that security and cloud engineers handle every week.
1. An everyday example: an office building's security desk
Why do hands-on security questions matter?
Security is where small mistakes become big incidents. Interviewers want to see that you can test a policy before you deploy it, read an encrypted error message, rotate a secret without downtime, and act on a threat finding calmly.
Think of an office building. IAM is the badge system that decides which doors each badge opens. KMS is the locksmith who makes and guards the master keys. Secrets Manager is the locked key cabinet, which also changes the locks on a schedule. GuardDuty is the CCTV team that watches for strange behaviour and raises an alarm.
How to use this page
- Practise in a sandbox account. Never test with real secrets or production keys.
- All account IDs, ARNs and values here are examples, such as account 111122223333.
- Read-only commands (simulate, describe, list) are safe to try first.
2. Fresher level questions
Start here if you are a fresher or have less than two years of experience. Try to answer each question aloud first. Then open it and compare.
Q1. How do you test whether a role can perform an action before deploying the policy? Fresher
Use the IAM policy simulator from the CLI:
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::111122223333:role/app-role --action-names s3:GetObject s3:DeleteObject --resource-arns arn:aws:s3:::shop-data-111122223333/reports/q3.csv --query "EvaluationResults[].[EvalActionName,EvalDecision]" --output textOutput:
s3:GetObject allowed
s3:DeleteObject implicitDenyThe role can read the file but cannot delete it, because no policy allows delete.
The simulator checks identity policies (and can include a resource policy and boundaries you pass). It is a quick way to catch mistakes before a release.
Q2. What is an IAM credential report, and what do you look for in it? Fresher
A credential report is a CSV file listing every IAM user in the account and the state of their credentials.
aws iam generate-credential-report
aws iam get-credential-report --query Content --output text | base64 -d | cut -d, -f1,4,8,9,10 | head -3Output:
user,password_enabled,mfa_active,access_key_1_active,access_key_1_last_rotated
deploy-bot,false,false,true,2024-02-10T08:00:00+00:00deploy-bot has an access key that is very old and never rotated.
Look for: users without MFA, old or unused access keys, and users who have not logged in for months.
Q3. What does the policy variable ${aws:username} do? Fresher
It is replaced by the name of the IAM user making the request. It lets one policy work for many users.
Example: each user may only use their own folder:
Output:
"Resource": "arn:aws:s3:::team-files-111122223333/home/${aws:username}/*"user asha can access home/asha/ but not home/ravi/.
For roles and federated users, aws:username does not exist; use other keys such as ${aws:PrincipalTag/team} or the session name instead.
Q4. Why is an "AccessDenied" message sometimes encoded, and how do you read it? Fresher
Some services (EC2 is common) return an encoded authorization failure message to avoid leaking details to the caller.
Output:
An error occurred (UnauthorizedOperation) when calling the RunInstances operation: You are not authorized to perform this operation. Encoded authorization failure message: 4bXa9...aws sts decode-authorization-message --encoded-message 4bXa9... --query DecodedMessage --output textOutput:
{"allowed":false,"explicitDeny":false,"matchedStatements":{"items":[]},"context":{"action":"ec2:RunInstances","resource":"arn:aws:ec2:ap-south-1:111122223333:volume/*"...}}No statement allowed RunInstances on the volume resource. You need permission to sts:DecodeAuthorizationMessage to run this.
Q5. How do you see which IAM policies are attached to a role from the CLI? Fresher
aws iam list-attached-role-policies --role-name app-role --query "AttachedPolicies[].PolicyName" --output textOutput:
AmazonS3ReadOnlyAccess orders-table-rwaws iam list-role-policies --role-name app-roleOutput:
{"PolicyNames": ["inline-sqs-send"]}The role has two managed policies and one inline policy. You must check all three, plus any permissions boundary (get-role shows PermissionsBoundary), to understand what the role can do.
To read a managed policy's current document, use get-policy to find the default version, then get-policy-version.
Q6. How do you get temporary credentials with MFA from the CLI? Fresher
aws sts get-session-token --serial-number arn:aws:iam::111122223333:mfa/asha-phone --token-code 123456 --duration-seconds 3600Output:
"Credentials": {"AccessKeyId": "ASIA...", "SecretAccessKey": "...", "SessionToken": "...", "Expiration": "2026-11-20T12:00:00Z"}You get short-term credentials that carry MFA information, so policies that require aws:MultiFactorAuthPresent will allow your actions.
Put them in a profile or environment variables. Better still, use IAM Identity Center sign-in, which handles MFA and short sessions for you.
Q7. How do you encrypt and decrypt a small piece of text with KMS from the CLI? Fresher
aws kms encrypt --key-id alias/app-key --plaintext fileb://token.txt --query CiphertextBlob --output text | base64 -d > token.enc
aws kms decrypt --ciphertext-blob fileb://token.enc --query Plaintext --output text | base64 -dOutput:
sample-token-123KMS encrypted the file content and returned it in readable form after decryption. For symmetric keys, decrypt does not need the key ID, because it is stored inside the ciphertext.
The Encrypt API accepts only up to 4 KB of data. For larger data, use data keys.
Q8. How do you check the state and type of a KMS key? Fresher
aws kms describe-key --key-id alias/app-key --query "KeyMetadata.[KeyId,KeyState,KeyManager,KeySpec,KeyUsage,Enabled]" --output textOutput:
1234abcd-12ab-34cd-56ef-1234567890ab Enabled CUSTOMER SYMMETRIC_DEFAULT ENCRYPT_DECRYPT TrueIt is an enabled, customer managed, symmetric encryption key.
If KeyState shows Disabled or PendingDeletion, every encrypt and decrypt call with it fails, which can break applications, EBS volumes and databases that use it.
Q9. How do you create a secret in Secrets Manager and read it back? Fresher
aws secretsmanager create-secret --name prod/shop/db --secret-string '{"username":"app","password":"Example-Only-Pass-1"}'
aws secretsmanager get-secret-value --secret-id prod/shop/db --query SecretString --output textOutput:
{"username":"app","password":"Example-Only-Pass-1"}The secret is stored encrypted with KMS and can be read by anyone allowed secretsmanager:GetSecretValue (and kms:Decrypt for a customer managed key).
Never paste real secrets into shell history; read them from a file or let the service generate them.
Q10. What are staging labels in Secrets Manager? Fresher
Each secret can have several versions. Labels point to versions:
- AWSCURRENT: the version applications should use now.
- AWSPENDING: a new version being created during rotation.
- AWSPREVIOUS: the last version, kept for rollback.
aws secretsmanager list-secret-version-ids --secret-id prod/shop/db --query "Versions[].[VersionId,VersionStages]" --output textOutput:
a1b2... AWSPREVIOUS
c3d4... AWSCURRENTrotation has happened at least once. Apps reading without a version get AWSCURRENT.
Q11. How do you let Secrets Manager generate a strong random password? Fresher
aws secretsmanager get-random-password --password-length 32 --exclude-characters "/@\"'\\" --query RandomPassword --output textIt returns a random password without characters that often break connection strings or shell commands.
Even better, let the service create and rotate the value itself (for example managed rotation for RDS), so no human ever sees the password.
Q12. How do you turn on GuardDuty in a Region from the CLI? Fresher
aws guardduty create-detector --enable --finding-publishing-frequency FIFTEEN_MINUTESOutput:
{"DetectorId": "12abc34d567e8fa901bc2d34e56789f0"}GuardDuty is now analysing data for this account in this Region.
GuardDuty is Regional, so turn it on in every Region you use and also in unused Regions, because attackers often launch resources in Regions you do not watch. In an organisation, enable it centrally through a delegated administrator.
Q13. How do you list high-severity GuardDuty findings from the CLI? Fresher
aws guardduty list-findings --detector-id 12abc34d567e8fa901bc2d34e56789f0 --finding-criteria '{"Criterion":{"severity":{"Gte":7}}}' --query FindingIds --output textOutput:
7cb4f2a1e3d5...aws guardduty get-findings --detector-id 12abc34d567e8fa901bc2d34e56789f0 --finding-ids 7cb4f2a1e3d5... --query "Findings[].[Type,Severity,Resource.ResourceType]" --output textOutput:
CryptoCurrency:EC2/BitcoinTool.B!DNS 8.0 InstanceAn instance is querying domains linked to cryptocurrency mining, a high-severity finding.
Q14. How does GuardDuty severity work? Fresher
GuardDuty gives each finding a severity number, grouped into bands: low, medium, high and critical (critical is used for some attack sequence findings).
- Low: suspicious but blocked or minor activity.
- Medium: unusual activity that should be investigated.
- High: a resource is likely compromised and needs action now.
Use severity to route alerts: high and critical to the on-call engineer through EventBridge, medium to a ticket queue, low to a weekly review.
Q15. How do you see sample GuardDuty findings to test your alerting? Fresher
aws guardduty create-sample-findings --detector-id 12abc34d567e8fa901bc2d34e56789f0 --finding-types "Recon:EC2/PortProbeUnprotectedPort"GuardDuty creates a fake finding marked as a sample. It flows through EventBridge like a real one.
Use it to test that your EventBridge rule, SNS topic, chat alert or ticketing workflow works, without waiting for a real attack. Archive the samples afterwards.
Q16. What GuardDuty protection plans can you turn on beyond the basic data sources? Fresher
Besides the foundational sources (CloudTrail management events, VPC Flow Logs and DNS logs), optional protection plans include:
- S3 Protection (S3 data events).
- EKS Protection (EKS audit logs) and Runtime Monitoring (agent for EKS, ECS and EC2).
- Malware Protection for EC2 (scans EBS volumes) and for S3 (scans new uploads).
- RDS Protection (suspicious logins to Aurora and some RDS engines).
- Lambda Protection (network activity of functions).
Turn on the plans that match the services you use; each has its own cost.
Q17. Why should you never put an AWS access key in application code, even for a test? Fresher
- Code is copied: into Git, CI logs, container images and laptops. Keys leak this way very often.
- Bots scan public repositories for keys within minutes.
- A leaked key works from anywhere until someone disables it.
Use roles instead: instance profiles on EC2, task roles on ECS, execution roles on Lambda, Pod Identity on EKS, OIDC federation for CI, and IAM Identity Center for people. Add secret scanning in Git to catch mistakes early.
3. Mid level questions
These questions check how you use the service in real projects. Interviewers expect the why, the how and one real example.
Q18. What is the difference between StringEquals and StringLike, and ForAnyValue and ForAllValues, in IAM conditions? Mid level
- StringEquals: exact match. StringLike: allows wildcards * and ?.
- ForAnyValue: the condition is true if at least one value in the request's list matches.
- ForAllValues: true if every value in the request's list matches the allowed set (and also true when the list is empty, which is a common trap).
Example trap: "ForAllValues:StringEquals": {"aws:TagKeys": ["team","env"]} allows requests with no tags at all. Add a Null or separate check if tags are required.
Q19. What is role chaining, and what limit does it have? Mid level
Role chaining is when you use a role's temporary credentials to assume another role.
- The session from a chained role is limited to a maximum of one hour, even if the role allows longer sessions.
- Session tags marked transitive can pass through the chain.
Example: a CI job assumes a deploy role in the tools account, then assumes a role in the production account. The second session lasts at most one hour, so long deployments must re-assume the role.
Avoid long chains; they are hard to audit.
Q20. How do session tags work, and why are they useful? Mid level
Session tags are key-value tags you pass when assuming a role (or from your identity provider during federation).
aws sts assume-role --role-arn arn:aws:iam::111122223333:role/dev-access --role-session-name asha --tags Key=team,Value=paymentsPolicies can then use ${aws:PrincipalTag/team}, for example to allow access only to resources tagged team=payments.
Benefit: one role works for many teams, with access decided by tags (ABAC). Protect the tags: allow sts:TagSession only from trusted sources, so users cannot set any team they like.
Q21. How do you restrict a GitHub Actions OIDC role so only one repository and branch can assume it? Mid level
In the role's trust policy, check the token's audience and subject:
Output:
"Condition": {
"StringEquals": {"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"},
"StringLike": {"token.actions.githubusercontent.com:sub": "repo:shop-org/orders-api:ref:refs/heads/main"}}Only workflows running on the main branch of shop-org/orders-api can get credentials.
A trust policy that checks only the audience lets any repository on GitHub assume the role, which is a serious mistake. Use GitHub environments in the sub claim for production deploys.
Q22. What is IAM Roles Anywhere? Mid level
IAM Roles Anywhere lets servers outside AWS (on-premises machines, other clouds) get temporary AWS credentials using X.509 certificates, instead of long-term access keys.
- You register a certificate authority (such as AWS Private CA or your own) as a trust anchor.
- You create a profile that lists which roles can be assumed.
- The server uses a credential helper with its certificate and private key to get short-term credentials.
It removes static keys from data centres, and access stops when the certificate expires or is revoked.
Q23. Why can NotAction with Allow be dangerous? Mid level
"Effect": "Allow" with "NotAction": ["iam:*"] means "allow every action except IAM actions". It also allows all future actions AWS adds, in every service.
It is sometimes used for power-user policies, but it gives very wide access.
NotAction is safer with Deny, for example "deny everything except these global services" in a Region restriction policy.
Prefer listing what is allowed. Review policies with NotAction or NotResource carefully, and use Access Analyzer policy validation to see warnings.
Q24. A policy uses aws:SourceIp to allow only the office IP, but requests through a VPC endpoint are denied. Why? Mid level
When a request comes through a VPC endpoint, AWS sees a private source address, not your public office IP. aws:SourceIp does not match, so the request fails.
Fix:
- For traffic through VPC endpoints, use aws:SourceVpce or aws:SourceVpc instead.
- Combine both in the policy: allow from the office IP or from the endpoint.
Also, aws:SourceIp does not work as expected when an AWS service calls another service on your behalf; use aws:ViaAWSService or service-specific conditions there.
Q25. How do you encrypt a large file with a KMS data key (envelope encryption) from the command line? Mid level
aws kms generate-data-key --key-id alias/app-key --key-spec AES_256 > dk.jsonThe response has Plaintext (the data key, base64) and CiphertextBlob (the same key, encrypted by KMS).
- Use the plaintext key locally to encrypt the file (for example with OpenSSL or the AWS Encryption SDK), then delete it from memory and disk.
- Store the encrypted data key next to the encrypted file.
- To decrypt, call kms decrypt on the encrypted data key, then decrypt the file locally.
In real code, use the AWS Encryption SDK, which does all of this safely.
Q26. An app gets "ThrottlingException: You have exceeded the rate at which you may call KMS". How do you fix it? Mid level
KMS has request quotas per account and Region (shared by cryptographic operations, with different values by Region and key type).
- Find the caller: CloudTrail events for the KMS key, or CloudWatch usage metrics.
- Cache data keys: the AWS Encryption SDK supports data key caching, so many messages reuse one data key for a short time.
- For S3, turn on S3 Bucket Keys to reduce KMS calls a lot.
- Retry with backoff in the client.
- Request a quota increase in Service Quotas if usage is valid.
Q27. What happens if you disable a KMS key used by an RDS database or EBS volumes? Mid level
- Existing running instances may keep working for a while, because the data key is already in memory, but anything that needs a new decrypt fails.
- EBS: volumes cannot be attached or the instance cannot start after a stop.
- RDS: the database can become inaccessible and move to an inaccessible-encryption-credentials state; restoring access needs the key re-enabled.
- New snapshots, copies and restores fail.
Never disable keys without checking which resources use them (CloudTrail and key usage). Re-enable the key quickly if this happens by mistake.
Q28. What is imported key material (BYOK) in KMS, and what extra work does it bring? Mid level
You can create a KMS key with no key material, then import your own key material generated in your own HSM.
Why: some regulations require that you generate the key and can remove it from AWS.
Extra work:
- You must keep a secure copy of the key material yourself; AWS cannot recover it.
- You can set an expiry time; after it, the key becomes unusable until you import again.
- You can delete the imported material immediately, making encrypted data unreadable.
- Automatic rotation works differently (on-demand rotation for imported keys is supported in newer releases; check current docs).
Q29. What are KMS custom key stores? Mid level
A custom key store keeps key material outside the standard KMS hardware:
- CloudHSM key store: keys live in your own AWS CloudHSM cluster, which you control.
- External key store (XKS): keys live in an HSM outside AWS, and KMS calls it through a proxy for every operation.
Trade-offs: more control and compliance, but more cost, more operations work, and lower availability and performance (especially for XKS, because every request leaves AWS).
Most companies use standard KMS keys; custom key stores are for strict regulatory needs.
Q30. What are the four steps of a Secrets Manager rotation function? Mid level
A rotation Lambda function is called four times with a step:
- createSecret: create a new secret value and store it as AWSPENDING.
- setSecret: change the password in the database or service to the pending value.
- testSecret: log in with the pending value to prove it works.
- finishSecret: move AWSCURRENT to the new version (the old one becomes AWSPREVIOUS).
If any step fails, AWSCURRENT is not moved, so applications keep working with the old value. AWS provides templates for common databases.
Q31. Rotation failed and the secret shows AWSPENDING stuck on a version. How do you debug it? Mid level
- Read the rotation function's CloudWatch logs to see which step failed.
- Common causes: the function cannot reach the database (VPC, security group, no endpoint to Secrets Manager), the database user lacks permission to change passwords, or wrong connection details in the secret.
- Check that the function's role can call GetSecretValue, PutSecretValue and UpdateSecretVersionStage, and use the KMS key.
- Fix the cause, then retry with rotate-secret.
aws secretsmanager rotate-secret --secret-id prod/shop/dbBecause AWSCURRENT did not move, the app should still work during the investigation.
Q32. How do you let RDS manage the master password in Secrets Manager? Mid level
Turn on managed master user password:
aws rds modify-db-instance --db-instance-identifier shop-db --manage-master-user-password --apply-immediatelyRDS creates a secret in Secrets Manager, stores the master password there, and rotates it automatically (every 7 days by default, configurable).
Benefits: no human knows the password, and rotation needs no Lambda function. Apps should read the secret at runtime and handle rotation by reconnecting on authentication errors.
Q33. How do you share a secret with another AWS account? Mid level
- Encrypt the secret with a customer managed KMS key (the AWS managed key cannot be shared).
- Add a resource policy on the secret that allows the other account's role to call GetSecretValue.
- Allow the same role to use kms:Decrypt in the key policy.
- In the other account, the role's identity policy must also allow both actions.
aws secretsmanager put-resource-policy --secret-id prod/shop/partner-api --resource-policy file://policy.json --block-public-policyThe --block-public-policy flag stops you from accidentally making the secret public.
Q34. How do you send GuardDuty high-severity findings to your team's chat automatically? Mid level
Create an EventBridge rule that matches GuardDuty findings with high severity:
Output:
{"source": ["aws.guardduty"], "detail-type": ["GuardDuty Finding"], "detail": {"severity": [{"numeric": [">=", 7]}]}}Target: an SNS topic connected to chat (for example through Amazon Q Developer in chat applications) or a Lambda function that formats and posts the message.
In a multi-account setup, create the rule in the GuardDuty delegated administrator account, which receives findings from all member accounts. Test it with sample findings.
Q47. How do you add a trusted IP list to GuardDuty, and when should you be careful? Mid level
A trusted IP list tells GuardDuty not to create findings for traffic from those IPs, such as your own scanners or office ranges.
aws guardduty create-ip-set --detector-id 12abc34d567e8fa901bc2d34e56789f0 --name office-scanners --format TXT --location https://s3.amazonaws.com/sec-config-111122223333/trusted-ips.txt --activateBe careful: if one of those IPs is compromised, GuardDuty will stay silent about it. Keep the list short, review it often, and prefer suppression rules with narrow filters for expected findings. Threat lists (known bad IPs) work the other way and add findings.
4. Senior level and scenario questions
These questions check design thinking and troubleshooting. Think aloud. Say what you check first, what you change, and how you prevent it next time.
Q35. How do you stop a KMS key from being used outside one AWS service, such as only through S3? Senior
Combine conditions in the key policy so the key is limited by who uses it, through which service, and for which data:
- Key policy: allow Encrypt, Decrypt and GenerateDataKey only to the application roles, with "kms:ViaService": "s3.ap-south-1.amazonaws.com".
- Add an encryption context condition so the key works only for one bucket: "kms:EncryptionContext:aws:s3:arn": "arn:aws:s3:::shop-data-111122223333".
- Keep key administration (policy changes, deletion) in a separate security role.
Result: even if a role has kms:Decrypt, it cannot decrypt data outside S3 or for other buckets with this key. Test with a direct kms decrypt call, which should fail.
Q36. Developers keep asking for broader permissions "just to make it work". How do you handle permissions at scale? Senior
- Give developers broad access in sandbox accounts, so experimentation does not need production rights.
- In shared accounts, generate least-privilege policies from real usage (Access Analyzer policy generation from CloudTrail), then refine them.
- Use permission boundaries so developers can create roles for their apps safely.
- Self-service requests through IaC pull requests, reviewed by the platform team, with automated policy checks (Access Analyzer custom policy checks in the pipeline).
- Time-limited elevated access through an approval workflow for emergencies.
Q37. A KMS key was scheduled for deletion by mistake 20 days ago. What do you do? Senior
- Check the deletion date: keys have a waiting period of 7 to 30 days. If it has not passed, you can cancel.
aws kms cancel-key-deletion --key-id 1234abcd-12ab-34cd-56ef-1234567890ab
aws kms enable-key --key-id 1234abcd-12ab-34cd-56ef-1234567890ab- The key returns in the Disabled state; enable it again.
- Check CloudTrail for who scheduled the deletion, and for any failed decrypt attempts during the waiting period (a CloudWatch alarm on those is a good early warning).
- Prevent: deny kms:ScheduleKeyDeletion except for a security role, through IAM and SCPs.
Q38. How would you design secret handling for 200 microservices across many accounts? Senior
- Naming standard: env/app/purpose (for example prod/orders/db).
- One customer managed KMS key per environment or domain, with key policies that limit who can decrypt.
- ABAC: tag secrets with team and env, and allow access only when the principal's tags match.
- Rotation on for all database and service credentials, with alarms for rotation failures.
- Apps read secrets at runtime with caching; no secrets in environment variables of images or in Git.
- Central visibility: Security Hub controls for unused or unrotated secrets, and CloudTrail data on GetSecretValue for audit.
Q39. GuardDuty reports "UnauthorizedAccess:EC2/SSHBruteForce" against an instance. How do you respond? Senior
- Read the finding: is the instance the target (inbound attack) or the source (it may be compromised and attacking others)?
- If the target: check that SSH is not open to 0.0.0.0/0; restrict the security group or remove port 22 and use Session Manager. Check auth logs for successful logins.
- If the source: treat the instance as compromised. Isolate it with a restrictive security group, snapshot volumes for forensics, revoke its role sessions, and replace it from a clean image.
- Look for other findings on the same resource and in the same time window.
- Close the gap and document the incident.
Q40. How do you use GuardDuty Malware Protection for S3 in an upload workflow? Senior
- Turn on Malware Protection for S3 for the upload bucket (or a prefix).
- New objects are scanned automatically; results are added as object tags (for example a scan status of no threats found or threats found) and sent as EventBridge events.
- Design: users upload to a quarantine bucket; only objects tagged clean are copied to the processing bucket, or a bucket policy denies GetObject unless the clean tag is present.
- Threats trigger an alert and the object is moved or deleted.
Check current limits on file size and types, and costs per GB scanned.
Q41. A security review found long-lived IAM user access keys used by an on-premises backup script. How do you remove them safely? Senior
- Find usage: when and from where the key is used (credential report, CloudTrail with the access key ID, last used info).
- Replace with temporary credentials: IAM Roles Anywhere with a certificate for the server, or an agent that uses SSM hybrid activation.
- Give the new role only the permissions the script needs.
- Deploy the change, confirm the script works, then deactivate the old key (do not delete yet) and watch for failures.
- After a safe period, delete the key and the IAM user.
- Add a Config rule to detect old access keys.
Q42. GuardDuty raised an "attack sequence" finding. What is it and how do you approach it? Senior
Attack sequence findings come from GuardDuty Extended Threat Detection. GuardDuty links several signals over time (for example unusual API calls, privilege changes and data access) into one finding that describes a likely multi-stage attack, often with critical severity.
Approach:
- Read the timeline: which identities and resources are involved, and what each step was.
- Contain fast: revoke the identity's sessions, disable keys, and isolate resources.
- Check data access: S3 reads, snapshots shared, new IAM users or roles.
- Preserve evidence and follow the incident response runbook.
It saves time because GuardDuty has already joined the dots.
Q43. How would you limit damage if an application server's role credentials are stolen? Senior
- Least privilege on the role: only the needed actions and resources.
- IMDSv2 required with hop limit 1, which makes SSRF-based theft much harder.
- Conditions so credentials work only from expected networks: aws:SourceVpc or aws:SourceVpce in bucket and key policies, and the aws:EC2InstanceSourceVPC condition key for instance credentials.
- GuardDuty detects instance credentials used from outside AWS (InstanceCredentialExfiltration findings).
- Short session durations and the ability to revoke sessions quickly.
- Data perimeter with SCPs and RCPs so stolen credentials cannot reach outside resources.
Q44. How do you prove that a sensitive S3 dataset was decrypted only by approved roles last quarter? Senior
- KMS records every Decrypt call in CloudTrail, with the calling principal, the key, and the encryption context (for S3, the bucket and object ARN).
- Query CloudTrail Lake or Athena for Decrypt events on that key in the time window, grouped by principal.
- Compare with the approved roles list; investigate anything else.
- Strengthen for the future: key policy that allows Decrypt only to approved roles, with an encryption context condition on the bucket, and an alert on unexpected principals.
This turns encryption into an audit trail, not just a checkbox.
Q45. A developer accidentally printed a database secret in application logs. What do you do? Senior
- Rotate the secret immediately (rotate-secret, or change it in the database), so the leaked value stops working.
- Remove or restrict the log data: delete affected log events if possible, or lower access to the log group, and check exports to S3 or third-party tools.
- Check who could read the logs and whether the old credential was used from unexpected places (database logs, CloudTrail).
- Fix the code: never log full config objects; use Powertools logging with redaction, and add log scanning for secret patterns.
- Record the incident and the follow-up actions.
Q46. How do you stop a compromised IAM Identity Center user's active AWS sessions? Senior
- In Identity Center (or your external identity provider), disable the user, so no new sign-ins are possible.
- Existing AWS role sessions from permission sets may stay valid until they expire. Revoke them: for each affected account and role, add a deny policy for sessions issued before now (the "revoke active sessions" option on the role adds a condition on aws:TokenIssueTime).
- Check CloudTrail for what the user did, using their user name in the session.
- Review and reset MFA devices.
- Keep session durations for permission sets short to reduce exposure in future.
Q48. A Lambda function's role was given AdministratorAccess "temporarily" six months ago. How do you fix it without breaking the function? Senior
- Find what the function really uses: CloudTrail events for the role, and IAM last accessed data (service and action level).
- Generate a policy from CloudTrail activity with IAM Access Analyzer policy generation, then review and tighten resources.
- Deploy the new least-privilege policy alongside, test in a staging copy, then remove AdministratorAccess.
- Watch for AccessDenied errors in logs and CloudTrail for a few days, and fix only what is truly needed.
- Prevent repeats: policy checks in the pipeline that block admin policies on application roles.
Q49. How do you rotate the KMS key used for an encrypted RDS database to a different key? Senior
You cannot change the KMS key of an existing RDS instance in place.
Steps:
- Take a snapshot of the instance.
- Copy the snapshot and choose the new KMS key during the copy.
- Restore a new instance from the copied snapshot.
- Switch the application to the new endpoint (or rename instances), ideally in a maintenance window. For low downtime, use replication (for example DMS or native replication) from the old instance until cutover.
- Keep the old key enabled until the old instance and its snapshots are deleted.
Automatic yearly rotation of the same key is a different thing and needs no data changes.
Q50. An access key belonging to a CI user is being used from an unknown country. Walk through your first 15 minutes. Senior
- Deactivate the access key immediately (do not delete yet, keep it for investigation).
aws iam update-access-key --user-name ci-deploy --access-key-id AKIAEXAMPLE123 --status Inactive- Check CloudTrail for every action made with that key: which Regions, which resources, any new users, roles, keys or instances created.
- Look for persistence: new IAM users, access keys, roles with outside trust, Lambda functions or EC2 instances in unused Regions.
- Check GuardDuty findings for the same principal.
- Tell the incident channel and start the runbook.
- Plan the permanent fix: replace the CI user with OIDC federation and no long-lived keys.
5. Frequently asked questions
Which security topic is asked most?
IAM. Almost every cloud interview has at least one "why is this AccessDenied?" or "how do you give X access to Y safely?" question.
Do I need to know GuardDuty finding types by heart?
No. Know how findings are named (threat purpose, resource type, detail), how severity works, and what you do first when a high-severity finding appears.
What should I practise?
Write a policy with a condition, test it with the policy simulator, encrypt a file with a KMS data key, create a secret with rotation, and generate GuardDuty sample findings.
6. Quick revision
- Test policies with simulate-principal-policy before deploying.
- Decode encoded authorization failures with sts decode-authorization-message.
- KMS encrypt directly handles only small data (up to 4 KB); use data keys for files.
- Secrets Manager labels: AWSCURRENT, AWSPENDING and AWSPREVIOUS.
- GuardDuty severity: low, medium, high and critical bands; route high and critical to on-call.
7. Related chapters
- AWS IAM and Security Interview Questions and Answers (50 Questions for Freshers to Senior)
- AWS Security Services Interview Questions and Answers: KMS, WAF, Shield, GuardDuty, Inspector, Macie and Security Hub (50 Questions)
- AWS Multi-Account Interview Questions and Answers: Organizations, SCPs, Control Tower and IAM Identity Center (50 Questions)
- 1000 AWS Interview Questions and Answers for Freshers and Experienced (Complete Set)
This page is one part of the complete AWS interview question set. Open the full list here: All 2052 AWS interview questions.