|
9 | 9 | import shutil |
10 | 10 | import time |
11 | 11 | 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") |
13 | 21 |
|
14 | 22 | # Either -dev or -prod must be specified (and nothing else) |
15 | 23 | if len(sys.argv) != 2 or (('-dev' not in sys.argv) and ('-prod' not in sys.argv)): |
|
67 | 75 | aws_zip_filename = "fileb://%s" % fq_zip_filename |
68 | 76 | print("Zipfile should be at: ", fq_zip_filename) |
69 | 77 |
|
| 78 | +cn_regions = [ |
| 79 | + 'cn-north-1', |
| 80 | + 'cn-northwest-1', |
| 81 | + ] |
| 82 | + |
70 | 83 | if dev_mode: |
71 | | - regions = ['us-west-1'] |
| 84 | + target_regions = ['us-west-1'] |
72 | 85 | LAYER_NAME = "instana-py-dev" |
73 | 86 | else: |
74 | | - regions = [ |
| 87 | + |
| 88 | + target_regions = [ |
75 | 89 | 'af-south-1', |
76 | 90 | 'ap-east-1', |
77 | 91 | 'ap-northeast-1', |
|
107 | 121 |
|
108 | 122 | published = dict() |
109 | 123 |
|
110 | | -for region in regions: |
| 124 | +for region in target_regions: |
111 | 125 | print("===> Uploading layer to AWS %s " % region) |
| 126 | + profile = 'china' if region in cn_regions else 'non-china' |
| 127 | + |
112 | 128 | response = check_output(["aws", "--region", region, "lambda", "publish-layer-version", |
113 | 129 | "--description", |
114 | 130 | "Provides Instana tracing and monitoring of AWS Lambda functions built with Python", |
115 | 131 | "--license-info", "MIT", "--output", "json", |
116 | 132 | "--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]) |
118 | 135 |
|
119 | 136 | json_data = json.loads(response) |
120 | 137 | version = json_data['Version'] |
|
127 | 144 | "--statement-id", "public-permission-all-accounts", |
128 | 145 | "--principal", "*", |
129 | 146 | "--action", "lambda:GetLayerVersion", |
130 | | - "--output", "text"]) |
| 147 | + "--output", "text", |
| 148 | + "--profile", profile]) |
131 | 149 |
|
132 | 150 | published[region] = json_data['LayerVersionArn'] |
133 | 151 |
|
|
0 commit comments