You must audit 40 AWS accounts in an Organization from one script. How do you handle credentials?
AdvancedScenarioAWS automation with boto3
Answer
Situation read → Cross-account access, centrally.
What I'd do →
- Deploy an
AuditReadOnlyrole to every account via StackSets or Terraform, trusting only a role in the security/tooling account. - List accounts with
organizations.list_accounts(paginator) from the management or delegated admin account. - For each account,
sts.assume_roleinto the audit role and build a fresh Session from the returned credentials. - Run accounts in parallel with a bounded pool; catch
AccessDeniedper account and report rather than abort.
Why → One trust path, least privilege, no keys in any account.
Interview tip → Mention ExternalId only matters for third-party access; inside an org, condition on aws:PrincipalOrgID.
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?AdvancedA Lambda written in Python times out at 15 minutes while processing a big S3 prefix. What are your options?AdvancedYou are asked to tag every untagged resource in an account with `Owner=unknown`. What questions do you ask and how do you implement it?Intermediate