-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdeploy.py
90 lines (76 loc) · 2.26 KB
/
deploy.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
"""Deploy aws lambda layer."""
import click
from boto3.session import Session as boto3_session
from botocore.client import Config
AWS_REGIONS = [
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2",
"ca-central-1",
"eu-central-1",
"eu-north-1",
"eu-west-1",
"eu-west-2",
"eu-west-3",
"sa-east-1",
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2",
]
CompatibleRuntimes_al2 = [
"nodejs22.x",
"nodejs20.x",
"nodejs18.x",
"python3.13",
"python3.12",
"python3.11",
"python3.10",
"java21",
"java17",
"java11",
"java8.al2",
"dotnet8",
"dotnet6",
"ruby3.3",
"ruby3.2",
"provided.al2023",
"provided.al2",
]
@click.command()
@click.argument('gdalversion', type=str)
@click.option('--deploy', is_flag=True)
def main(gdalversion, deploy):
"""Build and Deploy Layers."""
gdalversion_nodot = gdalversion.replace(".", "")
layer_name = f"gdal{gdalversion_nodot}"
description = f"Lambda Layer with GDAL{gdalversion} for amazonlinux2"
if deploy:
session = boto3_session()
# Increase connection timeout to work around timeout errors
config = Config(connect_timeout=6000, retries={'max_attempts': 5})
click.echo(f"Deploying {layer_name}", err=True)
for region in AWS_REGIONS:
click.echo(f"AWS Region: {region}", err=True)
client = session.client("lambda", region_name=region, config=config)
click.echo("Publishing new version", err=True)
with open("package.zip", 'rb') as zf:
res = client.publish_layer_version(
LayerName=layer_name,
Content={"ZipFile": zf.read()},
CompatibleRuntimes=CompatibleRuntimes_al2,
Description=description,
LicenseInfo="MIT"
)
click.echo("Adding permission", err=True)
client.add_layer_version_permission(
LayerName=layer_name,
VersionNumber=res["Version"],
StatementId='make_public',
Action='lambda:GetLayerVersion',
Principal='*',
)
if __name__ == '__main__':
main()