Skip to content
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

fix for issue #68 remove inits from cold start #69

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 21 additions & 17 deletions handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@
print("boto3 version: ",boto3.__version__)

# query active health API endpoint
health_dns = socket.gethostbyname_ex('global.health.amazonaws.com')
(current_endpoint, global_endpoint, ip_endpoint) = health_dns
health_active_list = current_endpoint.split('.')
health_active_region = health_active_list[1]
print("current health region: ", health_active_region)

# create a boto3 health client w/ backoff/retry
config = Config(
region_name=health_active_region,
retries=dict(
max_attempts=10 # org view apis have a lower tps than the single
# account apis so we need to use larger
# backoff/retry values than than the boto defaults
def get_health_active_region():
health_dns = socket.gethostbyname_ex('global.health.amazonaws.com')
(current_endpoint, global_endpoint, ip_endpoint) = health_dns
health_active_list = current_endpoint.split('.')
health_active_region = health_active_list[1]
print("current health region: ", health_active_region)
return health_active_region

def create_config_file():
# create a boto3 health client w/ backoff/retry
config = Config(
region_name=get_health_active_region(),
retries=dict(
max_attempts=10 # org view apis have a lower tps than the single
# account apis so we need to use larger
# backoff/retry values than than the boto defaults
)
)
)
return config

# TODO decide if account_name should be blank on error
# Get Account Name
Expand Down Expand Up @@ -871,14 +875,14 @@ def get_sts_token(service):
# create service client using the assumed role credentials, e.g. S3
boto3_client = boto3.client(
service,
config=config,
config=create_config_file(),
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
aws_session_token=SESSION_TOKEN,
)
print("Running in member account deployment mode")
else:
boto3_client = boto3.client(service, config=config)
boto3_client = boto3.client(service, config=create_config_file())
print("Running in management account deployment mode")

return boto3_client
Expand All @@ -900,4 +904,4 @@ def main(event, context):
describe_org_events(health_client)

if __name__ == "__main__":
main('', '')
main('', '')