def test_create_client_with_aws_role_arn_and_profile(boto3: object): boto3.DEFAULT_SESSION = None creds = get_credentials(dict()) finalArgs = {} aws_client( 'ecs', configuration=CONFIG_WITH_ARN_AND_PROFILE) boto3.client.assert_any_call( 'sts', region_name="us-east-1", **creds) boto3.client.assert_called_with( 'ecs', region_name="us-east-1", aws_access_key_id=ANY, aws_secret_access_key=ANY, aws_session_token=ANY) aws_client( 'ecs', configuration=CONFIG_WITH_ARN_AND_PROFILE) boto3.client.assert_any_call( 'sts', region_name="us-east-1", **creds) boto3.setup_default_session.assert_called_with( profile_name="myprofile", region_name="us-east-1", **creds) boto3.client.assert_called_with( 'ecs', region_name="us-east-1", aws_access_key_id=ANY, aws_secret_access_key=ANY, aws_session_token=ANY)
def test_create_client_with_aws_role_arn(boto3: object): boto3.DEFAULT_SESSION = None creds = get_credentials(dict()) aws_client("ecs", configuration=CONFIG_WITH_ARN) boto3.client.assert_any_call("sts", region_name="us-east-1", **creds) boto3.client.assert_called_with( "ecs", region_name="us-east-1", aws_access_key_id=ANY, aws_secret_access_key=ANY, aws_session_token=ANY, ) aws_client("ecs", configuration=CONFIG_WITH_ARN) boto3.client.assert_any_call("sts", region_name="us-east-1", **creds) boto3.setup_default_session.assert_called_with(profile_name=None, region_name="us-east-1", **creds) boto3.client.assert_called_with( "ecs", region_name="us-east-1", aws_access_key_id=ANY, aws_secret_access_key=ANY, aws_session_token=ANY, )
def test_region_can_be_set_via_config( logger: logging.Logger, boto3: object): boto3.DEFAULT_SESSION = None creds = get_credentials(dict()) aws_client('ecs', configuration={"aws_region": "us-west2"}) logger.debug.assert_any_call("Using AWS region 'us-west2'") logger.warning.assert_not_called()
def test_region_must_be_set(logger: logging.Logger, boto3: object): boto3.DEFAULT_SESSION = None creds = get_credentials(dict()) with pytest.raises(InterruptExecution): aws_client('ecs') logger.debug.assert_any_call( 'The configuration key `aws_region` is not set, looking in the ' 'environment instead for `AWS_REGION` or `AWS_DEFAULT_REGION`')
def test_create_client_from_profile_name(boto3: object): boto3.DEFAULT_SESSION = None creds = get_credentials(dict()) aws_client("ecs", configuration=CONFIG_WITH_PROFILE) boto3.client.assert_called_with("ecs", region_name="us-east-1", **creds) aws_client("ecs", configuration=CONFIG_WITH_PROFILE) boto3.setup_default_session.assert_called_with(profile_name="myprofile", region_name="us-east-1", **creds) boto3.client.assert_called_with("ecs", region_name="us-east-1", **creds)
def test_create_client_from_cred_keys(boto3: object): boto3.DEFAULT_SESSION = None creds = get_credentials(SECRETS) aws_client("ecs", configuration=CONFIGURATION, secrets=SECRETS) boto3.client.assert_called_with("ecs", region_name="us-east-1", **creds) aws_client("ecs", configuration=CONFIGURATION, secrets=SECRETS) boto3.setup_default_session.assert_called_with(profile_name=None, region_name="us-east-1", **creds) boto3.client.assert_called_with("ecs", region_name="us-east-1", **creds)
def test_region_can_be_set_as_AWS_REGION(logger: logging.Logger, boto3: object): boto3.DEFAULT_SESSION = None creds = get_credentials(dict()) try: os.environ["AWS_REGION"] = "us-west-2" aws_client('ecs') logger.debug.assert_any_call( 'The configuration key `aws_region` is not set, looking in the ' 'environment instead for `AWS_REGION` or `AWS_DEFAULT_REGION`') logger.warning.assert_not_called() logger.debug.assert_any_call("Using AWS region 'us-west2'") except: os.environ.pop("AWS_REGION", None)