|
| 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 | + |
| 13 | +def lambda_handler(event, context): |
| 14 | + if 'cmd' in event: |
| 15 | + return print(subprocess.check_output(['sh', '-c', event['cmd']]).decode('utf-8')) |
| 16 | + |
| 17 | + filename = 'python3.8.tgz' |
| 18 | + |
| 19 | + subprocess.call(['sh', '-c', f'tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read ' + |
| 20 | + '/var/runtime /var/lang /var/rapid']) |
| 21 | + |
| 22 | + print('Zipping done! Uploading...') |
| 23 | + |
| 24 | + TRANSFER.upload_file(f'/tmp/{filename}', 'lambci', |
| 25 | + f'fs/{filename}', extra_args={'ACL': 'public-read'}) |
| 26 | + |
| 27 | + print('Uploading done!') |
| 28 | + |
| 29 | + info = {'sys.executable': sys.executable, |
| 30 | + 'sys.argv': sys.argv, |
| 31 | + 'sys.path': sys.path, |
| 32 | + 'os.getcwd': os.getcwd(), |
| 33 | + '__file__': __file__, |
| 34 | + 'os.environ': {k: str(v) for k, v in os.environ.items()}, |
| 35 | + 'context': {k: str(v) for k, v in context.__dict__.items()}, |
| 36 | + 'proc environ': subprocess.check_output( |
| 37 | + ['sh', '-c', 'echo /proc/1/environ; xargs -n 1 -0 < /proc/1/environ']).decode('utf-8').splitlines(), |
| 38 | + 'ps aux': subprocess.check_output( |
| 39 | + ['bash', '-O', 'extglob', '-c', 'for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done']).decode('utf-8').splitlines()} |
| 40 | + |
| 41 | + print(json.dumps(info, indent=2)) |
| 42 | + |
| 43 | + return info |
0 commit comments