Skip to content

Instantly share code, notes, and snippets.

@theburningmonk theburningmonk/thundra-example.py Secret
Last active Feb 14, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.