Last active
January 3, 2020 05:35
-
-
Save gwsu2008/6650742c7edc4a3040ba13b1916d805f to your computer and use it in GitHub Desktop.
Python boto3 client exception
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
""" | |
=========================================== | |
['Error']['Code'] e.g. 'EntityAlreadyExists' or 'ValidationError' | |
['ResponseMetadata']['HTTPStatusCode'] e.g. 400 | |
['ResponseMetadata']['RequestId'] e.g. 'd2b06652-88d7-11e5-99d0-812348583a35' | |
['Error']['Message'] e.g. "An error occurred (EntityAlreadyExists) ..." | |
['Error']['Type'] e.g. 'Sender' | |
"""" | |
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. Received error: %s", e, exc_info=True" | |
else: | |
print "Unexpected error: %s" % e | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment