For lambda, it's best practice to initialise dependencies outside the handler.
I am creating a simple python function that works like the blueprints:
import boto3
s3 = boto3.client('ssm')
def lambda_handler(event, context):
# some code here
And the test
from lambda_function import handler # Option 1
import lambda_function # Option 2
class TestHandler(unittest.TestCase):
@patch('lambda_function.handler.boto3.client')
def test(self, boto3_mock):
# ...
I can't seem to properly setup a mock so that the boto.client call doesn't error out with You must specify a region.
On Option 1 it errors out during import call, and on Option 2 it does so during the patch setup
I can't use a ~/.aws/config because it will be used on a CI that can't have that. I also don't wan't to change the boto.client call to include a default region.
Is there something I am missing?