Skip to content

bin: Expect separate profiles for CN region #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions bin/aws-lambda/build_and_publish_lambda_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
import shutil
import time
import distutils.spawn
from subprocess import call, check_output
from subprocess import call, check_call, check_output, CalledProcessError, DEVNULL

for profile in ('china', 'non-china'):
try:
check_call(['aws', 'configure', 'list', '--profile', profile], stdout=DEVNULL)
except CalledProcessError:
raise ValueError(
f"Please ensure, that your aws configuration includes a profile called '{profile}'"
"and has the 'access_key' and 'secret_key' configured for the respective regions")

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

cn_regions = [
'cn-north-1',
'cn-northwest-1',
]

if dev_mode:
regions = ['us-west-1']
target_regions = ['us-west-1']
LAYER_NAME = "instana-py-dev"
else:
regions = [

target_regions = [
'af-south-1',
'ap-east-1',
'ap-northeast-1',
Expand Down Expand Up @@ -107,14 +121,17 @@

published = dict()

for region in regions:
for region in target_regions:
print("===> Uploading layer to AWS %s " % region)
profile = 'china' if region in cn_regions else 'non-china'

response = check_output(["aws", "--region", region, "lambda", "publish-layer-version",
"--description",
"Provides Instana tracing and monitoring of AWS Lambda functions built with Python",
"--license-info", "MIT", "--output", "json",
"--layer-name", LAYER_NAME, "--zip-file", aws_zip_filename,
"--compatible-runtimes", "python3.7", "python3.8", "python3.9", "python3.10"])
"--compatible-runtimes", "python3.7", "python3.8", "python3.9", "python3.10",
"--profile", profile])

json_data = json.loads(response)
version = json_data['Version']
Expand All @@ -127,7 +144,8 @@
"--statement-id", "public-permission-all-accounts",
"--principal", "*",
"--action", "lambda:GetLayerVersion",
"--output", "text"])
"--output", "text",
"--profile", profile])

published[region] = json_data['LayerVersionArn']

Expand Down