forked from mLupine/docker-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.py
More file actions
50 lines (36 loc) · 1.72 KB
/
Copy pathhandler.py
File metadata and controls
50 lines (36 loc) · 1.72 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
from __future__ import print_function
import os
import sys
import subprocess
import json
import boto3
from boto3.s3.transfer import S3Transfer
TRANSFER = S3Transfer(boto3.client('s3'))
def lambda_handler_arm64(event, context):
return lambda_handler(event, context, "arm64")
def lambda_handler_x86_64(event, context):
return lambda_handler(event, context, "x86_64")
def lambda_handler(event, context, arch):
if 'cmd' in event:
return print(subprocess.check_output(['sh', '-c', event['cmd']]).decode('utf-8'))
filename = f'python3.9-{arch}.tgz'
subprocess.call(['touch', f'/tmp/{filename}'])
subprocess.call(['sh', '-c', f'tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read ' +
'/var/runtime /var/lang /var/rapid'])
print('Zipping done! Uploading...')
TRANSFER.upload_file(f'/tmp/{filename}', 'docker-lambda',
f'fs/{filename}', extra_args={'ACL': 'public-read'})
print('Uploading done!')
info = {'sys.executable': sys.executable,
'sys.argv': sys.argv,
'sys.path': sys.path,
'os.getcwd': os.getcwd(),
'__file__': __file__,
'os.environ': {k: str(v) for k, v in os.environ.items()},
'context': {k: str(v) for k, v in context.__dict__.items()},
'proc environ': subprocess.check_output(
['sh', '-c', 'echo /proc/1/environ; xargs -n 1 -0 < /proc/1/environ']).decode('utf-8').splitlines(),
'ps aux': subprocess.check_output(
['bash', '-O', 'extglob', '-c', 'for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done']).decode('utf-8').splitlines()}
print(json.dumps(info, indent=2))
return info