'Botocore Stubber - Unable to locate credentials

I'm working on unit tests for my lambda which is getting some files from S3, processing them and loading data from them to DynamoDB. I created botocore stubbers that are used during tests, but I got botocore.exceptions.NoCredentialsError: Unable to locate credentials

My lambda handler code

s3_client = boto3.client('s3')
ddb_client = boto3.resource('dynamodb', region_name='eu-west-1')

def lambda_handler(event, context):
    for record in event['Records']:
        s3_event = record.get('s3')

        bucket = s3_event.get('bucket', {}).get('name', '')
        file_key = s3_event.get('object', {}).get('key', '')

        file = s3_client.get_object(Bucket=bucket, Key=file_key)

and tests file:

class TestLambda(unittest.TestCase):
    def setUp(self) -> None:
        self.session = botocore.session.get_session()

        # S3 Stubber Set Up
        self.s3_client = self.session.create_client('s3', region_name='eu-west-1')
        self.s3_stubber = Stubber(self.s3_client)

        # DDB Stubber Set Up
        self.ddb_resource = boto3.resource('dynamodb', region_name='eu-west-1')
        self.ddb_stubber = Stubber(self.ddb_resource.meta.client)
    
    def test_s3_to_ddb_handler(self) -> None:
        event = {}
        with self.s3_stubber:
            with self.ddb_stubber:
                response = s3_to_ddb_handler.s3_to_ddb_handler(event, ANY)

Issue seems to be that actual call to AWS resources is done which shouldnt be the case and stubber should be used, how can I force that?



Solution 1:[1]

Turned out that plesk has a feature called "Fix incorrectly set sender for outgoing mail under Tools & Settings > Mail Server.

unchecked that, works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fogbreaker