-
-
Save coingraham/dc6585ed010b3b3b0c5aa39468052c1d to your computer and use it in GitHub Desktop.
Handling Exceptions in Boto3
This file contains 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