-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlambda.py
More file actions
57 lines (45 loc) · 1.75 KB
/
lambda.py
File metadata and controls
57 lines (45 loc) · 1.75 KB
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
import base64
import json
import os
import boto3
bucket = os.environ.get('bucket')
def lambda_handler(event, context):
print('event', event)
s3 = boto3.client('s3')
start = str(event['start'])
end = str(event['end'])
range = base64.b64decode(event['range'][2:-1])
mapper = base64.b64decode(event['script'][2:-1])
print("streamed obj")
glue = f"""
import pickle
mapper=pickle.loads({mapper})
range=pickle.loads({range})
hist=mapper(range)
pickle.dump(hist, open('/tmp/out.pickle','wb'))
"""
script_file = open('/tmp/to_execute.py', "w")
script_file.write(glue)
script_file.close()
result = os.system('''
export PATH=/mnt/cern_root/chroot/usr/local/sbin:/mnt/cern_root/chroot/usr/local/bin:/mnt/cern_root/chroot/usr/sbin:/mnt/cern_root/chroot/usr/bin:/mnt/cern_root/chroot/sbin:/mnt/cern_root/chroot/bin:$PATH && \
export LD_LIBRARY_PATH=/mnt/cern_root/chroot/usr/lib64:/mnt/cern_root/chroot/usr/lib:/usr/lib64:/usr/lib:$LD_LIBRARY_PATH && \
export CPATH=/mnt/cern_root/chroot/usr/include:$CPATH && \
export PYTHONPATH=/mnt/cern_root/root_install/PyRDF:/mnt/cern_root/root_install:$PYTHONPATH && \
export roothome=/mnt/cern_root/root_install && \
cd /mnt/cern_root/root_install/PyRDF && \
. ${roothome}/bin/thisroot.sh && \
/mnt/cern_root/chroot/usr/bin/python3.7 /tmp/to_execute.py
''')
s3.upload_file(f'/tmp/out.pickle', bucket, f'partial_{start}_{end}.pickle')
if not result:
return {
'statusCode': 500,
'body': json.dumps('Failed!'),
'result': json.dumps(result)
}
return {
'statusCode': 200,
'body': json.dumps('Extracted ROOT to EFS!'),
'result': json.dumps(result)
}