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 in AWS by akhtar
• 27,980 points
40 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 by MD
• 64,820 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
• 57,680 points
623 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 7 in AWS by MD
• 64,820 points
36 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 in AWS by MD
• 64,820 points
30 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 in AWS by MD
• 64,820 points
77 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 in AWS by MD
• 64,820 points
35 views