Orz
Orz

Reputation: 615

Using CodeDeploy ValidateService Hook with Python Application

I have an heavy app hosted on AWS. I use CodeDeploy & Code Pipeline (updating from github) to update the servers when a new release is ready (currently running 6 ec2 instances on production environment).

I've setup the codedeploy to operate one-by-one and also defined a 300 seconds connection draining on the load balancer.

Still, my application is heavy (it loads large dictionary pickle files from the disk to the memory), the process of firing up takes about ~60 seconds. In those 60 seconds CodeDeploy marks the process of deployment to an instance as completed, causing it to join back as a healthy instance to the load balancer - this might cause errors to users trying to reach the application.

I thought about using the ValidateService hook, but i'm not sure how to in my case..

Any ideas on how to wait for a full load and readyness of the application before proceeding to the next instance?

This is my current AppSpec.yml version: 0.0 os: linux files: - source: /deployment destination: /deployment - source: /webserver/src destination: /vagrant/webserver/src permissions: - object: /deployment pattern: "**" owner: root mode: 644 type: - directory - object: /webserver/src owner: root mode: 644 except: [/webserver/src/dictionaries] type: - directory hooks: ApplicationStop: - location: /deployment/aws_application_stop.sh BeforeInstall: - location: /deployment/aws_before_install.sh AfterInstall: - location: /deployment/aws_after_install.sh ApplicationStart: - location: /deployment/aws_application_start.sh

Upvotes: 1

Views: 2443

Answers (1)

Rodrigo Murillo
Rodrigo Murillo

Reputation: 13638

I would loop in the ValidateService hook, checking for the condition you expect, OR just sleep for 60 seconds, assuming that is the normal initialization time.

The ValidateService hook should do just that: make sure the service is fully running before continuing/finalizing the deployment. That depends on your app of course. But consider a loop that pulls a specially designed page EG http://localhost/service-ready. In that URL, test and confirm anything and everything appropriate for your service. Return a -Pending- string if the service is not yet validated. Return a -OK- when everything is 100%

Perhaps loop that 10-20 times with a 10 second sleep, and exit when it returns -OK- then throw an error if the service never validates.

Upvotes: 2

Related Questions