Skip to content

Instantly share code, notes, and snippets.

@xschildw
Created April 22, 2021 16:04
Show Gist options
  • Select an option

  • Save xschildw/daa1d2c17cd45ff3d3ac7f9afc0cbdfc to your computer and use it in GitHub Desktop.

Select an option

Save xschildw/daa1d2c17cd45ff3d3ac7f9afc0cbdfc to your computer and use it in GitHub Desktop.
cloudsearchindexcheck
import logging
import boto3
def requires_indexing(client, domain_name):
req_indexing = False
response = client.describe_domains(DomainNames=[domain_name])
if (response != None and response['DomainStatusList'] != None):
domain_status_list = response['DomainStatusList']
if (len(domain_status_list) == 1):
domain_status = domain_status_list[0]
req_indexing = domain_status["RequiresIndexDocuments"]
else:
raise ValueError("Domain not found.")
else:
raise RuntimeError("No response or invalid response")
return req_indexing
def get_domain_name(client):
response = client.describe_domains()
if (response != None and response["DomainStatusList"] != None):
domain_status_list = response["DomainStatusList"]
num_domains = len(domain_status_list)
if num_domains < 1:
raise ValueError("No CloudSearch domain found.")
elif num_domains < 2:
return domain_status_list[0]["DomainName"]
else:
domain_names = [ds["DomainName"] for ds in domain_status_list]
domain_names.sort()
return domain_names[-2]
else:
raise RuntimeError("No response or invalid response")
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
def lambda_handler(event, context):
session = boto3.Session()
client = session.client("cloudsearch")
domain_name = get_domain_name(client)
indexing = requires_indexing(client, domain_name)
if indexing:
logger.error("CloudSearch index waiting for indexing...")
else:
logger.debug("CloudSearch index OK.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment