def create_session()

in functions/password_policy/app.py [0:0]


    def create_session(self):
        """Creates boto3 session."""
        target_account = self.role_arn.split(":")[4]
        sts_client = boto3.client('sts')
        caller_identity = sts_client.get_caller_identity()
        if caller_identity['Account'] != target_account:
            response = sts_client.assume_role(RoleArn=self.role_arn, RoleSessionName=self.role_session_name)
            return boto3.Session(
                aws_access_key_id=response['Credentials']['AccessKeyId'],
                aws_secret_access_key=response['Credentials']['SecretAccessKey'],
                aws_session_token=response['Credentials']['SessionToken']
            )
        else:
            return boto3.Session()