Skip to content

Commit

Permalink
Add missing common utils and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtj committed May 3, 2021
1 parent f24c17d commit cfabcad
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
tests/fixtures
__pycache__
samconfig.toml
packaged.yaml
Empty file.
11 changes: 11 additions & 0 deletions functions/training_info_getter/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import boto3

from common.json_utils import clean_json

sagemaker_client = boto3.client('sagemaker')

def lambda_handler(event, context):
training_name = event['training_info']['TrainingJobName']
training_info = sagemaker_client.describe_training_job(TrainingJobName=training_name)
event['training_info'] = clean_json(training_info)
return event
Empty file.
Empty file added layers/utils/__init__.py
Empty file.
Empty file added layers/utils/common/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions layers/utils/common/json_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json
from datetime import datetime, date

def json_serial(obj):
'''JSON serializer for objects not serializable by default json code'''
if isinstance(obj, (datetime, date)):
return obj.isoformat()
raise TypeError(f'Type {type(obj)} not serializable')

def clean_json(obj):
''' Cleans a json object from datettimes. '''
return json.loads(json.dumps(obj, default=json_serial))
Empty file added layers/utils/requirements.txt
Empty file.
4 changes: 2 additions & 2 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Resources:
This lambda function gets training results and other information
after the training has finished.
Properties:
CodeUri: ../common/functions/training_info_getter/
CodeUri: functions/training_info_getter/
Handler: app.lambda_handler
Runtime: python3.8
Timeout: 10
Expand Down Expand Up @@ -249,7 +249,7 @@ Resources:
Type: AWS::Serverless::LayerVersion
Description: Lambda layer containing common utils
Properties:
ContentUri: ../common/layers/utils
ContentUri: layers/utils
CompatibleRuntimes:
- python3.8
Metadata:
Expand Down

0 comments on commit cfabcad

Please sign in to comment.