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.
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?Beginner