Skip to content

Mock assumed role for global default session. #8820

Answered by bonext
bonext asked this question in Q&A
Discussion options

You must be logged in to vote

Answering my own question, here's how.

import pytest
from moto import mock_aws
import json
 

@pytest.fixture()
def aws_credentials(monkeypatch):
    """Mocked AWS Credentials for moto."""
    monkeypatch.setenv("AWS_DEFAULT_REGION", "eu-west-2")
    monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
    monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
    monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
    monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
 
 
@pytest.fixture()
def mocked_aws(aws_credentials):
    """
    Mock all AWS interactions
    Requires you to create your own boto3 clients
    """
    with mock_aws():
        yield


@pytest.fixture()
def mock_role_name(…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bblommers
Comment options

Answer selected by bblommers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants