|
| 1 | +from __future__ import print_function |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | +import subprocess |
| 6 | +import json |
| 7 | +import boto3 |
| 8 | +from boto3.s3.transfer import S3Transfer |
| 9 | + |
| 10 | +TRANSFER = S3Transfer(boto3.client('s3')) |
| 11 | + |
| 12 | +def lambda_handler_arm64(event, context): |
| 13 | + return lambda_handler(event, context, "arm64") |
| 14 | + |
| 15 | +def lambda_handler_x86_64(event, context): |
| 16 | + return lambda_handler(event, context, "x86_64") |
| 17 | + |
| 18 | +def lambda_handler(event, context, arch): |
| 19 | + if 'cmd' in event: |
| 20 | + return print(subprocess.check_output(['sh', '-c', event['cmd']]).decode('utf-8')) |
| 21 | + |
| 22 | + filename = f'python3.10-{arch}.tgz' |
| 23 | + |
| 24 | + subprocess.call(['touch', f'/tmp/{filename}']) |
| 25 | + |
| 26 | + subprocess.call(['sh', '-c', f'tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read ' + |
| 27 | + '/var/runtime /var/lang /var/rapid']) |
| 28 | + |
| 29 | + print('Zipping done! Uploading...') |
| 30 | + |
| 31 | + TRANSFER.upload_file(f'/tmp/{filename}', 'docker-lambda', |
| 32 | + f'fs/{filename}', extra_args={'ACL': 'public-read'}) |
| 33 | + |
| 34 | + print('Uploading done!') |
| 35 | + |
| 36 | + info = {'sys.executable': sys.executable, |
| 37 | + 'sys.argv': sys.argv, |
| 38 | + 'sys.path': sys.path, |
| 39 | + 'os.getcwd': os.getcwd(), |
| 40 | + '__file__': __file__, |
| 41 | + 'os.environ': {k: str(v) for k, v in os.environ.items()}, |
| 42 | + 'context': {k: str(v) for k, v in context.__dict__.items()}, |
| 43 | + 'proc environ': subprocess.check_output( |
| 44 | + ['sh', '-c', 'echo /proc/1/environ; xargs -n 1 -0 < /proc/1/environ']).decode('utf-8').splitlines(), |
| 45 | + 'ps aux': subprocess.check_output( |
| 46 | + ['bash', '-O', 'extglob', '-c', 'for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done']).decode('utf-8').splitlines()} |
| 47 | + |
| 48 | + print(json.dumps(info, indent=2)) |
| 49 | + |
| 50 | + return info |
0 commit comments