aws_service.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:aws-ops-automator 作者: awslabs 项目源码 文件源码
def get_session(role_arn=None, sts_client=None):
        """
        Created a session for the specified role
        :param role_arn: Role arn
        :param sts_client: Optional sts client, if not specified a (cache) sts client instance is used
        :return: Session for the specified role
        """

        if role_arn is not None:
            sts = sts_client if sts_client is not None else boto3.client("sts")
            account = AwsService.account_from_role_arn(role_arn)
            token = sts.assume_role(RoleArn=role_arn, RoleSessionName="{}-{}".format(account, str(uuid.uuid4())))
            credentials = token["Credentials"]
            return boto3.Session(aws_access_key_id=credentials["AccessKeyId"],
                                 aws_secret_access_key=credentials["SecretAccessKey"],
                                 aws_session_token=credentials["SessionToken"])
        else:
            return boto3.Session()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号