Adding Route53 health checks using the AWS CLI
July 12, 2019
July 12, 2019
AWS Route53 health checks are a good way to verify if you app is up and running. It can be used to ‘ping’ your application at a specific interface and rate you define and check if your application (or site) is running as it should.
Creating a healthcheck via the command line using the aws cli is relatvely straight forward:
healthCheckId=`aws route53 create-health-check –caller-reference $DATE –health-check-config \ Port=443,Type=”HTTPS_STR_MATCH”,ResourcePath=”/ROOT_OR_PATH”, \
SearchString=”TARGET_STATUS”,RequestInterval=30,FailureThreshold=3, \ MeasureLatency=true,Inverted=false,Disabled=false,EnableSNI=true,\
FullyQualifiedDomainName=FQDN –query ‘HealthCheck.Id’ –output text`
The output of this command will be the health check id. You will need to update FQDN with that of the site that you want to monitor as well as ROOT_OR_PATH. ROOT_OR_PATH would be a specific page or url that you have setup. For example, if you have a test page that runs verification steps on your API. If you are having that page return something, say it returns just text of TRUE or FALSE, you would put that in TARGET_STATUS.
Let’s say for example you want to monitor https://test.centralizedlogging.com/api/health_check. The health_check endpoint returns TRUE if the api checks pass and FALSE If doesn’t. The setup for the health check would this:
healthCheckId=`aws route53 create-health-check –caller-reference $DATE –health-check-config \ Port=443,Type=”HTTPS_STR_MATCH”,ResourcePath=”/api/health_check”, \
SearchString=”TRUE”,RequestInterval=30,FailureThreshold=3, \ MeasureLatency=true,Inverted=false,Disabled=false,EnableSNI=true,\
FullyQualifiedDomainName=https://test.centralizedlogging.com –query ‘HealthCheck.Id’ –output text`
If you’re wondering why we are using DATE for –caller-reference it is because we need to use a unique string to identify our request. Using the date and including the seconds in there allows us to do this.
One last thing. If you run this, you’ll notice that the Name tag is empty. If you want to set this, which I recommend because otherwise you won’t be able to identify what the health check is for aside from what is in the Description field, you will need to set the Name tag. To do this, you’ll need to run change-tags-for-resource and pass in the Health Check Id. This is why in the examples above, we have been saving it to a variable. It makes it easier to pass it in to the next command.
aws route53 change-tags-for-resource –resource-type healthcheck –resource-id $healthCheckId –add-tags Key=Name,Value=NAME Key=environment,Value=production
I always tend to set additional tags as well. At a minimum, just one called environment. This allows me to identify the resource for billing or anything else I might want to do.
Advanced Data Engineering Platform for Cleansing, Preprocessing and Analytics