def wake_aurora()

in aurora-serverless-s3-ingestion/cdk/lambda/DataIngest.py [0:0]


def wake_aurora():
    delay = 5
    max_attempts = 10

    attempt = 0
    while attempt < max_attempts:
        attempt += 1
        try:
            wake = rdsdata.execute_statement (
                resourceArn = my_resource_arn,
                secretArn = my_secret_arn,
                database = my_database,
                sql = 'select 1'
            )
            return
        except ClientError as ce:
            error_code = ce.response.get("Error").get('Code')
            error_msg = ce.response.get("Error").get('Message')
                # Aurora serverless is waking up
            if error_code == 'BadRequestException' and 'Communications link failure' in error_msg:
                time.sleep(delay)
            else:
                raise ce

        raise Exception('Waited for Aurora Serveless but still got errors')