You need to do something when it fails to handle the issue. Right now you are returning the actual exception. For example, if its not a problem that the user exists already and you want to use it as a get_or_create function maybe you handle the issue by returning the existing user object.
try:
user = iam_conn.create_user(UserName=username)
return user
except botocore.exceptions.ClientError as e:
#this exception could actually be other things other than exists, so you want to evaluate it further in your real code.
if e.message.startswith(
'enough of the exception message to identify it as the one you want')
print('that user already exists.')
user = iam_conn.get_user(UserName=username)
return user
elif e.message.some_other_condition:
#something else
else:
#unhandled ClientError
raise(e)
except SomeOtherExceptionTypeYouCareAbout as e:
#handle it
# any unhandled exception will raise here at this point.
# if you want a general handler
except Exception as e:
#handle it.
That said, maybe it is a problem for your app, in which case you want to want to put the exception handler around the code that called your create user function and let the calling function determine how to deal with it, for example, by asking the user to input another username, or whatever makes sense for your application.