How to handle exceptions with boto3

0 votes

Hi Guys,

I am new to AWS boto. I am managing my AWS resource using the boto module. But how can I handle the exceptions with boot module.

Sep 21, 2020 in AWS by akhtar
• 38,230 points
1,814 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use botocore.exceptions package in your script. It will allow you to manage the exceptions. I have attached one example below for your reference.

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)
answered Sep 21, 2020 by MD
• 95,440 points

Related Questions In AWS

+1 vote
1 answer

How to authenticate session in application running on Beanstalk with boto3

The recommended way of managing credentials used ...READ MORE

answered Aug 28, 2018 in AWS by Priyaj
• 58,090 points
1,411 views
0 votes
1 answer

How to download S3 Objects With Python and Boto3?

Hi@akhtar, You can download one file from a ...READ MORE

answered Oct 8, 2020 in AWS by MD
• 95,440 points
2,411 views
0 votes
1 answer

How to Describe security groups with Boto3?

Hi@akhtar, An EC2 instance is a virtual server ...READ MORE

answered Oct 8, 2020 in AWS by MD
• 95,440 points
5,773 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to list contents of a bucket with boto3?

Hi@akhtar, You can create a session for an ...READ MORE

answered Sep 21, 2020 in AWS by MD
• 95,440 points
13,077 views
0 votes
1 answer

How to open S3 object as a string with Boto3?

Hi@akhtar, If you want to return a string, you ...READ MORE

answered Sep 21, 2020 in AWS by MD
• 95,440 points
3,865 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP