Skip to content

Commit d05cbe1

Browse files
committed
bin: Expect separate profiles for CN region
Signed-off-by: Ferenc Géczi <ferenc.geczi@ibm.com>
1 parent 132f465 commit d05cbe1

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

bin/aws-lambda/build_and_publish_lambda_layer.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
import shutil
1010
import time
1111
import distutils.spawn
12-
from subprocess import call, check_output
12+
from subprocess import call, check_call, check_output, CalledProcessError, DEVNULL
13+
14+
for profile in ('china', 'non-china'):
15+
try:
16+
check_call(['aws', 'configure', 'list', '--profile', profile], stdout=DEVNULL)
17+
except CalledProcessError:
18+
raise ValueError(
19+
f"Please ensure, that your aws configuration includes a profile called '{profile}'"
20+
"and has the 'access_key' and 'secret_key' configured for the respective regions")
1321

1422
# Either -dev or -prod must be specified (and nothing else)
1523
if len(sys.argv) != 2 or (('-dev' not in sys.argv) and ('-prod' not in sys.argv)):
@@ -67,11 +75,17 @@
6775
aws_zip_filename = "fileb://%s" % fq_zip_filename
6876
print("Zipfile should be at: ", fq_zip_filename)
6977

78+
cn_regions = [
79+
'cn-north-1',
80+
'cn-northwest-1',
81+
]
82+
7083
if dev_mode:
71-
regions = ['us-west-1']
84+
target_regions = ['us-west-1']
7285
LAYER_NAME = "instana-py-dev"
7386
else:
74-
regions = [
87+
88+
target_regions = [
7589
'af-south-1',
7690
'ap-east-1',
7791
'ap-northeast-1',
@@ -107,14 +121,17 @@
107121

108122
published = dict()
109123

110-
for region in regions:
124+
for region in target_regions:
111125
print("===> Uploading layer to AWS %s " % region)
126+
profile = 'china' if region in cn_regions else 'non-china'
127+
112128
response = check_output(["aws", "--region", region, "lambda", "publish-layer-version",
113129
"--description",
114130
"Provides Instana tracing and monitoring of AWS Lambda functions built with Python",
115131
"--license-info", "MIT", "--output", "json",
116132
"--layer-name", LAYER_NAME, "--zip-file", aws_zip_filename,
117-
"--compatible-runtimes", "python3.7", "python3.8", "python3.9", "python3.10"])
133+
"--compatible-runtimes", "python3.7", "python3.8", "python3.9", "python3.10",
134+
"--profile", profile])
118135

119136
json_data = json.loads(response)
120137
version = json_data['Version']
@@ -127,7 +144,8 @@
127144
"--statement-id", "public-permission-all-accounts",
128145
"--principal", "*",
129146
"--action", "lambda:GetLayerVersion",
130-
"--output", "text"])
147+
"--output", "text",
148+
"--profile", profile])
131149

132150
published[region] = json_data['LayerVersionArn']
133151

0 commit comments

Comments
 (0)