You need to copy an AMI to three regions and share it with two accounts as part of a release. How do you automate it?
AdvancedScenarioAWS automation with boto3
Answer
Situation read → Multi-region, multi-account, slow async operations.
What I'd do →
- For each region, call
copy_image(SourceRegionId=..., SourceImageId=..., Name=..., Encrypted=True, KmsKeyId=regional_key)from a client in the destination region. - Wait with
get_waiter("image_available")in each region (in parallel threads). - Share:
modify_image_attribute(ImageId=..., LaunchPermission={"Add": [{"UserId": acct}]}), and grant the accounts use of the KMS key (or the snapshots will be unusable). - Tag copies with source AMI and version; publish IDs to SSM parameters per region.
- Use EC2 Image Builder distribution settings if available.
Why → Encrypted AMI sharing fails silently without KMS grants; that is the usual gotcha.
Interview tip → Mention KMS key permissions for shared encrypted snapshots.
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