/thundra-example.py Secret
Last active
February 14, 2019 00:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from thundra.thundra_agent import Thundra | |
thundra = Thundra() | |
from thundra.plugins.trace.traceable import Traceable | |
from thundra.plugins.trace import trace_support | |
from thundra.listeners import ErrorInjectorSpanListener, FilteringSpanListener | |
from thundra.listeners.thundra_span_filterer import ThundraSpanFilterer, ThundraSpanFilter | |
import os | |
import json | |
import boto3 | |
dynamodb = boto3.client('dynamodb') | |
def putUser(userId, payload): | |
dynamodb.put_item( | |
TableName='users', | |
Item={ | |
'Id': { | |
'S': userId | |
}, | |
'firstName': { | |
'S': payload['firstName'] | |
}, | |
'lastName': { | |
'S': payload['lastName'] | |
} | |
} | |
) | |
if 'preference' in payload.keys(): | |
dynamodb.put_item( | |
TableName='user_preferences', | |
Item={ | |
'Id': { | |
'S': userId | |
}, | |
'preference': { | |
'S': payload['preference'] | |
} | |
} | |
) | |
return { | |
'firstName': payload['firstName'], | |
'lastName': payload['lastName'] | |
} | |
def getPreference(userId): | |
resp = dynamodb.get_item( | |
TableName='user_preferences', | |
Key={ | |
'Id': { | |
'S': userId | |
} | |
} | |
) | |
print(json.dumps(resp)) | |
return { | |
'preference': resp.Item['preference'] | |
} | |
@thundra | |
def addUser(event, context): | |
userId = event['pathParameters']['userId'] | |
print('user id:' + userId) | |
payload = json.loads(event['body']) | |
print('payload:' + event['body']) | |
user = putUser(userId, payload) | |
return { | |
'statusCode': 200, | |
'body': json.dumps(user) | |
} | |
@thundra | |
def getUserPreference(event, context): | |
userId = event['pathParameters']['userId'] | |
print('user id:' + userId) | |
pref = getPreference(userId) | |
return { | |
'statusCode': 200, | |
'body': json.dumps(pref) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment