Predictive Hacks

How to choose an AWS profile in boto3

Running Boto3 in python, it uses the default AWS profile. However, there is an option to use a different one that we will show you how in the following lines of code. Let’s suppose that we want to use the comprehend service and the profile name is ‘billy’.

import pandas as pd
import numpy as np
import boto3

session = boto3.session.Session(profile_name='billy')
client = session.client('comprehend')

mytxt = """My name is Joe Smith and I was born in 1988 and I am 33 years old.
I work at Predictive Hacks and my email is [email protected]. 
I live in Athens, Greece. My phone number is 623 12 34 567 and my bank account is 123-123-567-888"""
response = client.detect_pii_entities(
    Text= mytxt,

{'Entities': [{'Score': 0.9999711513519287,
   'Type': 'NAME',
   'BeginOffset': 11,
   'EndOffset': 20},
  {'Score': 0.9998830556869507,
   'Type': 'DATE_TIME',
   'BeginOffset': 39,
   'EndOffset': 43},
  {'Score': 0.9999682307243347,
   'Type': 'AGE',
   'BeginOffset': 53,
   'EndOffset': 61},
  {'Score': 0.9999246597290039,
   'Type': 'EMAIL',
   'BeginOffset': 110,
   'EndOffset': 139},
  {'Score': 0.9961787462234497,
   'Type': 'ADDRESS',
   'BeginOffset': 152,
   'EndOffset': 166},
  {'Score': 0.9999889135360718,
   'Type': 'PHONE',
   'BeginOffset': 187,
   'EndOffset': 200},
  {'Score': 0.9999783039093018,
   'BeginOffset': 224,
   'EndOffset': 239}],
 'ResponseMetadata': {'RequestId': '85e00a92-a5c0-4747-8b61-c95c269e5f2f',
  'HTTPStatusCode': 200,
  'HTTPHeaders': {'x-amzn-requestid': '85e00a92-a5c0-4747-8b61-c95c269e5f2f',
   'content-type': 'application/x-amz-json-1.1',
   'content-length': '571',
   'date': 'Mon, 21 Mar 2022 10:49:39 GMT'},
  'RetryAttempts': 0}}

In order to make it work, you should have the credentials of the “billy” profile in the configuration files.

In your root folder, there must be a hidden folder called .aws that inside it there is the config and the credentials file.
The credentials should have the access_key_id and the secret_access_key as follows:

aws_access_key_id = ACCESS KEY ID
aws_secret_access_key = SECRET ACCESS KEY 

aws_access_key_id = ACCESS KEY ID OF BILLY
aws_secret_access_key = SECRET ACCESS KEY OF BILLY

And in the config file the region and the output.

region = us-east-1
output = json

[profile billy]
region = us-east-1

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore


Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.


Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s