in code/lab-3/generic-unicorn-management-service/app.py [0:0]
def lambda_handler(event, context):
print('{} received event: {}'.format(SERVICE_NAME, json.dumps(event)))
# we only send a quote, if we are available at that time
if i_am_not_available(event):
return
# if we send a quote, we wait between 0 and 60 seconds to mimic the quote computation
time.sleep(random.randint(0,60))
# send the response to the quotes response queue
message = json.loads(event['Records'][0]['Sns']['Message'])
response_message = json.dumps({
'responder': SERVICE_NAME,
'rfq-id': message['rfq-id'],
'quote': random.randint(0,100)
})
response = sqs.send_message(
QueueUrl = QUEUE_URL,
MessageBody = response_message
)
print('sent SQS message: {}'.format(response_message))
return