Configure APIs to return HTTP 503 for backend maintenance

Is there a way to add configuration in Apigee to return HTTP 503 (Service Unavaialable) message for a set of/all API proxies if the backend server is down for a specific window for maintenance?

I have a not so great idea, using flow hooks to return HTTP 503 with appropriate response message. It will affect all API calls though. Is this a good way to do it? or is there a better way to achieve this?

Solved Solved
1 2 2,665
1 ACCEPTED SOLUTION

To avoid the "affects all proxies", You could use a SharedFlow + FlowCallout.

Within the FlowCallout, perform a KVM lookup, which returns a JSON, listing all the proxies which are in "maintenance mode".

Parse the JSON and then see if the _current_ proxy is listed .

If so, RaiseFault with 503.

Then, "putting a proxy into maintenance mode" involves updating the KVM entry.

Take care to use a reasonable cache ExpiryTimeInSecs on the KVM Get. Maybe 20 seconds or so.

<KeyValueMapOperations name='KVM-Get-stored_maint_mode' mapIdentifier='adminSettings'>
  <Scope>environment</Scope>
  <ExpiryTimeInSecs>20</ExpiryTimeInSecs>
  <Get assignTo='stored_maint_mode' index='1'>
    <Key>
      <Parameter>maint_mode</Parameter>
    </Key>
  </Get>
</KeyValueMapOperations>


View solution in original post

2 REPLIES 2

To avoid the "affects all proxies", You could use a SharedFlow + FlowCallout.

Within the FlowCallout, perform a KVM lookup, which returns a JSON, listing all the proxies which are in "maintenance mode".

Parse the JSON and then see if the _current_ proxy is listed .

If so, RaiseFault with 503.

Then, "putting a proxy into maintenance mode" involves updating the KVM entry.

Take care to use a reasonable cache ExpiryTimeInSecs on the KVM Get. Maybe 20 seconds or so.

<KeyValueMapOperations name='KVM-Get-stored_maint_mode' mapIdentifier='adminSettings'>
  <Scope>environment</Scope>
  <ExpiryTimeInSecs>20</ExpiryTimeInSecs>
  <Get assignTo='stored_maint_mode' index='1'>
    <Key>
      <Parameter>maint_mode</Parameter>
    </Key>
  </Get>
</KeyValueMapOperations>


@Dino-at-Google

Thanks. Appreciate the quick response.