Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The security token included in the request is invalid. When no profile specified

When running this:

session = boto3.session.Session()
client = session.client(service_name="secretsmanager", region_name='region')
secret_response = client.get_secret_value(SecretId='secret_name')
print(secret_response)

This is the error that I get: botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the GetSecretValue operation: The security token included in the request is invalid.

But when I run the exact same code but specify my profile like this:

session = boto3.session.Session(profile_name='default')

it works.

boto3 version: 1.27.6

like image 894
Alex Nae Avatar asked Dec 19 '25 08:12

Alex Nae


1 Answers

You probably have mulitple profiles in aws credentials. Whats baffling is that even if you use boto3.session.Session() without specifying a profile, it's supposed to use the default profile.

However, try to remove aws credentials first by running rm ~/.aws/credentials. After that, run aws configure again and follow the prompt to add your credentials properly. This should solve the problem.

like image 181
Olasimbo Avatar answered Dec 20 '25 22:12

Olasimbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!