|
| 1 | +import json |
| 2 | +from unittest import TestCase |
| 3 | + |
| 4 | +import boto3 |
| 5 | + |
| 6 | + |
| 7 | +def get_lambda_client(): |
| 8 | + return boto3.client('lambda', |
| 9 | + aws_access_key_id='', |
| 10 | + aws_secret_access_key='', |
| 11 | + region_name='eu-west-2', |
| 12 | + endpoint_url='http://localhost:4574') |
| 13 | + |
| 14 | + |
| 15 | +def deploy_lambda(): |
| 16 | + with open('lambda.zip', 'rb') as f: |
| 17 | + zipped_code = f.read() |
| 18 | + get_lambda_client().create_function( |
| 19 | + FunctionName='geo-lambda', |
| 20 | + Runtime='python3.7', |
| 21 | + Role='a-role', |
| 22 | + Handler='lambda.handler', |
| 23 | + Code={'ZipFile': zipped_code}, |
| 24 | + Environment={ |
| 25 | + 'Variables': { |
| 26 | + 'GDAL_DATA': '/opt/share/gdal', |
| 27 | + 'PROJ_LIB': '/opt/share/proj' |
| 28 | + } |
| 29 | + } |
| 30 | + ) |
| 31 | + |
| 32 | + |
| 33 | +def invoke_lambda_and_get_response(): |
| 34 | + return json.loads(get_lambda_client().invoke( |
| 35 | + FunctionName='geo-lambda', |
| 36 | + InvocationType='RequestResponse' |
| 37 | + )['Payload'].read().decode('utf-8')) |
| 38 | + |
| 39 | + |
| 40 | +class Test(TestCase): |
| 41 | + def setup_method(self, method): |
| 42 | + deploy_lambda() |
| 43 | + |
| 44 | + def test_that_layer_works(self): |
| 45 | + resp = invoke_lambda_and_get_response() |
| 46 | + self.assertEqual(resp["message"], "Printed all versions") |
0 commit comments