我正在尝试使用 aws sts 获取 aws 凭据。下面的代码在 Pycharm 中运行良好,但是当我在 docker 容器中运行它时,我得到“无法找到凭据”。
def assumed_role_session(role_arn):
try:
base_session = boto3.session.Session()._session.profile
sts_client = boto3.client('sts').assume_role(RoleArn=role_arn, RoleSessionName=base_session)
credentials = sts_client['Credentials']
return credentials
except Exception as e:
return None
assumed_role_session('arn:aws:iam::{AWS_ACCOUNT_NUMBER}:role/{AWS_ROLE_NAME}')