Created
February 21, 2019 14:54
-
-
Save stewmi/cbf51c6dd0ab52fb81953d3e802e273b to your computer and use it in GitHub Desktop.
Handling Exceptions in Boto3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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