Skip to content

Commit 9809199

Browse files
authored
Refactor: Use AppConfig class from the moesifapi-python api (#23)
Refactor: Use AppConfig class from the moesifapi-python api Refactor: Update moesifpythonrequest version to 0.3.5 Bump version to 1.2.3
1 parent f231c10 commit 9809199

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

eventV2.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
"requestId": "id",
5555
"routeKey": "$default",
5656
"stage": "$default",
57-
"time": "12/Mar/2020:19:03:58 +0000",
58-
"timeEpoch": 1698901826000
57+
"time": "12/Mar/2020:19:03:58 +0000"
5958
},
6059
"body": "Hello from Lambda",
6160
"pathParameters": {

moesif_aws_lambda/global_variable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""This module is to declare global objects."""
22
from datetime import datetime
3-
from moesifpythonrequest.app_config.app_config import AppConfig
3+
from moesifapi.app_config.app_config import AppConfig
44
from moesifapi.moesif_api_client import *
55
import os
66

moesif_aws_lambda/middleware.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ def before(self, event, context):
276276
return event, context
277277

278278
# Request headers
279-
req_headers = {}
279+
req_headers = event.get('headers', {})
280280
try:
281-
if 'headers' in event:
282-
req_headers = APIHelper.json_deserialize(event['headers'])
281+
if isinstance(req_headers, str):
282+
req_headers = APIHelper.json_deserialize(req_headers)
283283
except Exception as e:
284284
if self.DEBUG:
285285
print('[moesif] Error while fetching request headers')
@@ -312,7 +312,10 @@ def before(self, event, context):
312312
'trace_id': str(context.aws_request_id),
313313
'function_name': context.function_name,
314314
'request_context': event['requestContext'],
315-
'context': context
315+
# Lambda context object - https://docs.aws.amazon.com/lambda/latest/dg/python-context.html
316+
'context': {
317+
'aws_request_id': str(getattr(context, 'aws_request_id', ''))
318+
}
316319
}
317320
except:
318321
if self.DEBUG:
@@ -456,7 +459,7 @@ def after(self, retval):
456459
random_percentage = random.random() * 100
457460
gv.sampling_percentage = gv.app_config.get_sampling_percentage(
458461
event_model,
459-
gv.config,
462+
json.loads(gv.config.raw_body),
460463
self.user_id,
461464
self.company_id,
462465
)

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
moesifapi==1.4.1
2-
lambda_decorators==0.3.0
3-
moesifpythonrequest==0.3.2
1+
moesifapi==1.5.5
2+
lambda_decorators==0.6.0
3+
moesifpythonrequest==0.3.5

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Versions should comply with PEP440. For a discussion on single-sourcing
2929
# the version across setup.py and the project code, see
3030
# https://packaging.python.org/en/latest/single_source_version.html
31-
version='1.2.2',
31+
version='1.2.3',
3232

3333
description='Moesif Middleware to automatically log API calls from AWS Lambda functions',
3434
long_description=long_description,
@@ -84,7 +84,7 @@
8484
# your project is installed. For an analysis of "install_requires" vs pip's
8585
# requirements files see:
8686
# https://packaging.python.org/en/latest/requirements.html
87-
install_requires=['moesifapi>=1.4.0', 'lambda_decorators', 'moesifpythonrequest>=0.3.0'],
87+
install_requires=['moesifapi>=1.5.5', 'lambda_decorators', 'moesifpythonrequest>=0.3.5'],
8888

8989
# List additional groups of dependencies here (e.g. development
9090
# dependencies). You can install these using the following syntax,

0 commit comments

Comments
 (0)