-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
102 lines (90 loc) · 3.03 KB
/
setup.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import boto3
LambdaFunctionExecutionRole = "LambdaWebProxyRole"
LambdaFunctionExecutionRoleDescription = "Lambda Execution Role that intends to allow nothing, but has to allow/deny something so allows listing tags which will not be done."
LambdaFunctionName = "webproxy"
LambdaFunctionRuntime = "python3.9"
LambdaFunctionHandler="lambda_handler"
LambdaFunctionDescription="Lambda function to act as a web proxy"
LambdaFunctionTimeout=5
LambdaFunctionMemorySize=128 # TODO Benchmark with https://github.com/byrro/awslambda-memory-tradeoff or dashbird.io: 3 different sized pages, upto 3GB of memory sizes, both architectures
LambdaFunctionPublish=True
LambdaFunctionDeploymentPackageType="Zip"
LambdaFunctionTags={
"Project": "Lambda Web Proxy"
}
LambdaFunctionLayers=[
LambdaBS4LayerName
]
LambdaFunctionArchitecture="x86_64"
LambdaBS4LayerName="BeautifulSoup4"
LambdaBS4LayerDescription="BeautifulSoup4 v4.10.0"
LambdaBS4LayerRuntimes=[
LambdaFunctionRuntime
]
LambdaRequestsLayerName="BeautifulSoup4"
LambdaRequestsLayerDescription="BeautifulSoup4 v4.10.0"
LambdaRequestsLayerRuntimes=[
LambdaFunctionRuntime
]
def get_deployment_package():
pass
def get_bs4_layer():
pass
def get_requests_layer():
pass
iam = boto3.client('iam')
awslambda = boto3.client('lambda')
with open("lambda-execution-policy.json") as policy_file:
LambdaFunctionExecutionRolePolicy = policy_file.read().strip()
iam_role = iam.create_role(
RoleName=LambdaFunctionExecutionRole,
AssumeRolePolicyDocument=LambdaFunctionExecutionRolePolicy,
Description=LambdaFunctionExecutionRoleDescription
)
lambda_bs4_layer = awslambda.publish_layer_version(
LayerName=LambdaBS4LayerName,
Description=LambdaBS4LayerDescription,
Content={
'ZipFile': get_bs4_layer()
},
CompatibleRuntimes=LambdaBS4LayerRuntimes,
LicenseInfo='MIT', # BeautifulSoup4 License
CompatibleArchitectures=[
'x86_64',
'arm64',
]
)
lambda_requests_layer = awslambda.publish_layer_version(
LayerName=LambdaRequestsLayerName,
Description=LambdaRequestsLayerDescription,
Content={
'ZipFile': get_requests_layer()
},
CompatibleRuntimes=LambdaRequestsLayerRuntimes,
LicenseInfo='Apache-2.0', # Python-Requests License
CompatibleArchitectures=[
'x86_64',
'arm64',
]
)
lambda_function = awslambda.create_function(
FunctionName=LambdaFunctionName,
Runtime=LambdaFunctionRuntime,
Role=LambdaFunctionExecutionRole,
Handler=LambdaFunctionHandler,
Code={
'ZipFile': get_deployment_package()
},
Description=LambdaFunctionDescription,
Timeout=LambdaFunctionTimeout,
MemorySize=LambdaFunctionMemorySize,
Publish=LambdaFunctionPublish,
PackageType=LambdaFunctionDeploymentPackageType,
DeadLetterConfig={} # Maybe later, for testing?
Environment={
"Variables": ""
},
Tags=LambdaFunctionTags,
Layers=LambdaFunctionLayers,
Architecture=LambdaFunctionArchitecture
)