Interview Prep/Python for DevOps/boto3 & AWS automation

What does `DryRun=True` do on EC2 API calls?

IntermediateConceptboto3 & AWS automation
Answer

EC2 checks whether you have permission to perform the action, without performing it. Success is reported as an error with code DryRunOperation; lack of permission as UnauthorizedOperation.

try:
    ec2.stop_instances(InstanceIds=[iid], DryRun=True)
except ClientError as e:
    if e.response["Error"]["Code"] != "DryRunOperation":
        raise

It is a great preflight for destructive scripts. Not every service supports it.

All Python for DevOps questions Roadmap: Python for automation

More on boto3 & AWS automation