title: How to generate webhook when GCE instance shuts down?
body: <p>I have a system that adds dynamically created instances with ephemeral IP addresses to GCP cloud DNS when they start. However, I need to remove them from the DNS when they shutdown, whether through GCP's own APIs, or through some other method.</p>
  
  <p>The best I can figure now is:</p>
  
  <ol>
  <li>Poll the GCE API
  
  <ul>
  <li>Pros: Foolproof; pretty much guaranteed to work; doesn't require an endpoint for a webhook</li>
  <li>Cons: Resource scaling issues; could easily hit API request quotas if not written intelligently</li>
  </ul></li>
  <li>Use <a href="https://cloud.google.com/monitoring/api/resources" rel="nofollow noreferrer">API monitoring</a> through Stackdriver/StackMonitor and create a webhook notification
  
  <ul>
  <li>Pros: Only run code when needed; simple webhook implementation; no polling; no false positives</li>
  <li>Cons: Can't monitor for unexpected shutdowns (i.e. not an API call).</li>
  </ul></li>
  <li>Use <a href="https://cloud.google.com/monitoring/alerts/uptime-checks" rel="nofollow noreferrer">uptime monitoring</a> through Stackdriver/StackMonitor
  
  <ul>
  <li>Pros: Works for unexpected shutdowns</li>
  <li>Cons: Stackdriver will track many other unused metrics; requires at least 5 minutes before uptime notification is sent; based on CPU/Memory stats, which could mean that a machine is simply frozen or the logging executable has crashed and not that the machine is truly shutdown.</li>
  </ul></li>
  </ol>
  
  <p>Is there another way to do this?</p>