'boto3 connects from EC2 instance to secrets manager but unable to connect from inside docker container after IMDSv2 required upgrade

boto3 connects from EC2 instance with the following command returns a result.

session = boto3.session.Session()
client = session.client(service_name = 'secretmanager', region_name = 'us-east-1')
get_secret_value_response = client.get_secret_value(secretId = secret_name)

However, when I run the same set of commands from inside a docker container deployed on the EC2 instance it fails with the No credentials error. EC2 instance has an IAM role attached to be able to fetch passwords from secrets manager.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source