Skip to content

Instantly share code, notes, and snippets.

@stewmi
Created February 21, 2019 14:54
Show Gist options
  • Save stewmi/cbf51c6dd0ab52fb81953d3e802e273b to your computer and use it in GitHub Desktop.
Save stewmi/cbf51c6dd0ab52fb81953d3e802e273b to your computer and use it in GitHub Desktop.
Handling Exceptions in Boto3
import boto3
from botocore.exceptions import ClientError
try:
iam = boto3.client('iam')
user = iam.create_user(UserName='fred')
print("Created user: %s" % user)
except ClientError as e:
if e.response['Error']['Code'] == 'EntityAlreadyExists':
print("User already exists")
else:
print("Unexpected error: %s" % e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment