-
Notifications
You must be signed in to change notification settings - Fork 0
/
biosteamHelper.py
71 lines (60 loc) · 2.14 KB
/
biosteamHelper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import uuid
import boto3
import time
# Define the client to interact with AWS Lambda
client = boto3.client('lambda')
# =============================================================================
# Lambda Function: accepts biosteam data from api gateway, routes values to
# corresponding biosteam simulation functions and returns jobId and jobTimestamp
# =============================================================================
def lambda_handler(event, context):
# read input biosteam data
params = event['params']
# samples = event['samples']
# model = event['model']
# create UUID (use type 4 for generic uuid)
jobId = str(uuid.uuid4())
# create timestamp for transaction, in unix format
jobTimestamp = time.time()
# =============================================================================
# Function router: send input biosteam data to corresponding function
# =============================================================================
print('random')
# temp = json.dumps({
# 'jobId': jobId,
# 'jobTimestamp': jobTimestamp,
# 'params': params,
# 'samples': samples,
# 'model': model
# })
# print(temp)
# csUncertainty function
response = client.invoke(
FunctionName = 'arn:aws:lambda:us-west-1:085967298430:function:csUncertainty',
InvocationType = 'Event',
Payload = json.dumps({
'jobId': jobId,
'jobTimestamp': jobTimestamp,
**event
# 'params': params,
# 'samples': samples,
# 'model': model,
# 'sim_type':
})
)
print(response)
return {
'statusCode': 200,
"headers": {
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
},
'body': json.dumps({
'jobId': jobId,
'jobTimestamp': str(int(jobTimestamp)),
'params': params,
'status': 'job being proccessed'
})
}