def main()

in scripts/elasticsearch-generate-data.py [0:0]


def main(endpoint):
    if 'AWS_REGION' not in os.environ:
        print("The AWS_REGION environment variable has not been set.")
        sys.exit(1)
    
    region = os.environ['AWS_REGION']
    
    service = 'es'
    credentials = boto3.Session().get_credentials()
    awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)
    
    fake = Faker()
    
    es = Elasticsearch(
        hosts = [{'host': endpoint, 'port': 443}],
        http_auth = awsauth,
        use_ssl = True,
        verify_certs = True,
        connection_class = RequestsHttpConnection
    )
    
    while True:
        document = fake.profile()
        
        try:
            result = es.index(index="people", doc_type="_doc", body=document)
            print("Indexed with ID '%s'" % result['_id'])
            time.sleep(0.25)

        except ConnectionTimeout as e:
            print("Connection to the ES cluster timed out: %s" % str(e))
            time.sleep(2)
        
        except Exception as e:
            print("Unexpected exception caught: %s" % str(e))
            time.sleep(2)