You need to rotate IAM access keys older than 90 days for service users and notify owners. What do you build?
AdvancedScenarioAWS automation with boto3
Answer
Situation read → Keys should not exist at all for most services; the script is a stopgap.
What I'd do →
- Get the credential report (
iam.generate_credential_report, poll, thenget_credential_report, parse CSV) for key age and last used. - Flag keys older than 90 days; for unused keys (no
last_used_datein 90 days) deactivate, then delete after a grace period. - Notify owners via the
Ownertag on the user, with a deadline. - Track the real fix: move each workload to roles (OIDC, instance profiles, IRSA) and delete the user.
Why → The credential report gives everything in one call instead of N list_access_keys calls.
Interview tip → Say the goal is zero long-lived keys; rotation is risk reduction, not the solution.
More on AWS automation with boto3
You are asked to write a script that stops all dev EC2 instances at 8 PM and starts them at 8 AM. How do you build it?BeginnerA script that lists all S3 objects in a bucket reports 1,000 objects, but the console says there are 48,000. What happened, and how do you fix the script?BeginnerYou need to find and delete EBS snapshots older than 90 days, but some are used by AMIs and backup plans. How do you write it safely?IntermediateYour audit script hits `ThrottlingException` / `RequestLimitExceeded` when scanning large accounts. What do you change?AdvancedYou must audit 40 AWS accounts in an Organization from one script. How do you handle credentials?AdvancedA Lambda written in Python times out at 15 minutes while processing a big S3 prefix. What are your options?Advanced