forked from lambci/docker-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump-python27.py
62 lines (51 loc) · 1.84 KB
/
dump-python27.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
from __future__ import print_function
import os
import sys
import subprocess
import boto3
from boto3.s3.transfer import S3Transfer
client = boto3.client('s3')
transfer = S3Transfer(client)
def lambda_handler(event, context):
if ('cmd' in event):
return subprocess.call(['sh', '-c', event['cmd']])
filename = 'python2.7.tgz'
cmd = 'tar -cpzf /tmp/{} --numeric-owner --ignore-failed-read /var/runtime'.format(filename)
subprocess.call(['sh', '-c', cmd])
print('Zipping done! Uploading...')
data = transfer.upload_file('/tmp/' + filename, 'lambci', 'fs/' + filename,
extra_args={'ACL': 'public-read'})
print('Uploading done!')
print(sys.executable)
print(sys.argv)
print(os.getcwd())
print(__file__)
print(os.environ)
return data
# /usr/bin/python2.7
# ['/var/runtime/awslambda/bootstrap.py']
# /var/task
# /var/task/lambda_function.py
# {
# 'PATH': '/usr/local/bin:/usr/bin/:/bin',
# 'LD_LIBRARY_PATH': '/lib64:/usr/lib64:/var/runtime:/var/task:/var/task/lib',
# 'PYTHONPATH': '/var/runtime',
# 'AWS_REGION': 'us-east-1',
# 'AWS_DEFAULT_REGION': 'us-east-1',
# 'AWS_ACCESS_KEY_ID': 'ASIA...C37A',
# 'AWS_SECRET_ACCESS_KEY': 'JZvD...BDZ4L',
# 'AWS_SESSION_TOKEN': 'FQoDYXdzEMb//////////...0oog7bzuQU=',
# 'AWS_SECURITY_TOKEN': 'FQoDYXdzEMb//////////...0oog7bzuQU=',
# 'LAMBDA_CONSOLE_SOCKET': '16',
# 'LAMBDA_SHARED_MEM_FD': '11',
# 'LAMBDA_LOG_FD': '9',
# 'LAMBDA_CONTROL_SOCKET': '14',
# 'LAMBDA_RUNTIME_DIR': '/var/runtime',
# 'LAMBDA_RUNTIME_LOAD_TIME': '1530232235231',
# 'LAMBDA_TASK_ROOT': '/var/task',
# 'AWS_LAMBDA_LOG_GROUP_NAME': '/aws/lambda/dump-python27',
# 'AWS_LAMBDA_LOG_STREAM_NAME': '2016/05/18/[$LATEST]27e5a905...392c2c0b',
# 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE': '1536',
# 'AWS_LAMBDA_FUNCTION_VERSION': '$LATEST',
# 'AWS_LAMBDA_FUNCTION_NAME': 'dump-python27'
# }