|
18 | 18 | get_message_for_teams, get_org_message_for_teams, get_message_for_email, get_org_message_for_email, \
|
19 | 19 | get_org_message_for_eventbridge, get_message_for_eventbridge
|
20 | 20 |
|
21 |
| -# query active health API endpoint |
22 |
| -health_dns = socket.gethostbyname_ex('global.health.amazonaws.com') |
23 |
| -(current_endpoint, global_endpoint, ip_endpoint) = health_dns |
24 |
| -health_active_list = current_endpoint.split('.') |
25 |
| -health_active_region = health_active_list[1] |
26 |
| -print("current health region: ", health_active_region) |
27 |
| - |
28 |
| -# create a boto3 health client w/ backoff/retry |
29 |
| -config = Config( |
30 |
| - region_name=health_active_region, |
31 |
| - retries=dict( |
32 |
| - max_attempts=10 # org view apis have a lower tps than the single |
33 |
| - # account apis so we need to use larger |
34 |
| - # backoff/retry values than than the boto defaults |
| 21 | + |
| 22 | +boto3_config = None |
| 23 | + |
| 24 | + |
| 25 | +# Create a boto3 config object |
| 26 | +def create_boto3_config(): |
| 27 | + # query active health API endpoint |
| 28 | + health_dns = socket.gethostbyname_ex('global.health.amazonaws.com') |
| 29 | + (current_endpoint, global_endpoint, ip_endpoint) = health_dns |
| 30 | + health_active_list = current_endpoint.split('.') |
| 31 | + health_active_region = health_active_list[1] |
| 32 | + print("current health region: ", health_active_region) |
| 33 | + # create a boto3 health client w/ backoff/retry |
| 34 | + return Config( |
| 35 | + region_name=health_active_region, |
| 36 | + retries=dict( |
| 37 | + max_attempts=10 # org view apis have a lower tps than the single |
| 38 | + # account apis so we need to use larger |
| 39 | + # backoff/retry values than than the boto defaults |
| 40 | + ) |
35 | 41 | )
|
36 |
| -) |
| 42 | + |
37 | 43 |
|
38 | 44 | # Get Account Name
|
39 | 45 | def get_account_name(account_id):
|
@@ -844,20 +850,22 @@ def get_sts_token(service):
|
844 | 850 | # create service client using the assumed role credentials, e.g. S3
|
845 | 851 | boto3_client = boto3.client(
|
846 | 852 | service,
|
847 |
| - config=config, |
| 853 | + config=boto3_config, |
848 | 854 | aws_access_key_id=ACCESS_KEY,
|
849 | 855 | aws_secret_access_key=SECRET_KEY,
|
850 | 856 | aws_session_token=SESSION_TOKEN,
|
851 | 857 | )
|
852 | 858 | print("Running in member account deployment mode")
|
853 | 859 | else:
|
854 |
| - boto3_client = boto3.client(service, config=config) |
| 860 | + boto3_client = boto3.client(service, config=boto3_config) |
855 | 861 | print("Running in management account deployment mode")
|
856 | 862 |
|
857 | 863 | return boto3_client
|
858 | 864 |
|
859 | 865 | def main(event, context):
|
860 | 866 | print("THANK YOU FOR CHOOSING AWS HEALTH AWARE!")
|
| 867 | + global boto3_config |
| 868 | + boto3_config = create_boto3_config() |
861 | 869 | health_client = get_sts_token('health')
|
862 | 870 | org_status = os.environ['ORG_STATUS']
|
863 | 871 | #str_ddb_format_sec = '%s'
|
|
0 commit comments