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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With