How to programmatically provision/deprovision a worker role instance?

Category: azure development


Surender Bishnoi on Wed, 15 Jan 2014 13:58:38


We have a web service deployed in azure and one of the worker role is prone to security attack. So what we are looking for is that once a worker role instance serves a customer request (there wont be many at a time), we want to purge it and deploy a fresh instance of the same worker role (without service downtime). COGS is not a concern for us. 

We have looked into the reimage option but it doesn't seems to cleanup everything. 

What we want to achieve is: We have a web role and a worker role. The worker role serves only one request. So when a request comes to service (web role) it provisions a new worker role asynchronously (since it may take some time) and forwards the request to existing worker role. Once the worker role has served the request we want to delete it. This way we want to keep some worker role instance (let's say N) ready to accept N request at a time.

Please suggest whats the best way to achieve this using azure management APIs or other means.

We are open to have another worker role that manages this whole stuff of provisioning/deprovisioning of another type of worker role instances based on the number of request being received from customers at a time.




Igor Papirov on Wed, 15 Jan 2014 14:24:30

There is an API to change instance count of workers in a Role.  However, there is no way to programmatically de-provision a specific instance.  Typically, when decreasing instance count, the last instance will get de-provisioned.

Can you find a way to get reimage to work for you - perhaps perform a manual clean up of certain things?

Surender Bishnoi on Tue, 21 Jan 2014 10:57:53

Thanks Igor.

We have tried reimage option and it works.

There is a way to de-provision a particular instance, see here

We can use the azure library for autoscaling the number of role instances. 

Here is a nice reference for this.

Jambor yao on Wed, 22 Jan 2014 02:31:51

Hi Surender,
Thank you for sharing your solutions and experience here. It will be very beneficial for other community members who have similar questions. If you have any difficulty in future programming, we welcome you to post in forums again.
Best Regards