Engineering

Feature Spotlight: Streamlining Post-Deployment with Aptible's After-Success and After-Failure Hooks

Mario de la Ossa

Engineering

SHARE

SHARE

SHARE

Aptible has expanded its deployment capabilities with new after-success and after-failure hooks, providing developers with more control over what happens after key deployment operations. Whether you're deploying, restarting, configuring, or scaling, these hooks allow you to automate custom tasks based on the success or failure of these operations.


These hooks are added to your .aptible.yml file, and they run after specific operations like deploy, restart, configure, and scale. The success hooks trigger when the operation is confirmed to be successful, such as after your Release Containers are up and healthy. Conversely, the failure hooks run when an operation fails and needs to be rolled back. These hooks are executed in an isolated, ephemeral container directly on your container image, which gives you the full power you need to automate tasks.

Practical Use Cases    

Notifying Teams After a Successful Deployment

If you want to notify your team once a deployment succeeds, you can use the after_deploy_success hook. For example, you could send a Slack notification with a simple one-liner using curl:    

after_deploy_success:
  - curl -d "text=Deploy successful!" -d "channel=CHANID" -H "Authorization: Bearer YOURTOKEN" -X POST https://slack.com/api/chat.postMessage

Cleaning Up Resources After a Failed Restart

To automate the cleanup of resources or alerting relevant teams after a restart failure, use the after_restart_failure hook, feeding it any command your image understands, be it a bash script, python, ruby, or anything else you've added to your image:

after_restart_failure:
  - ./scripts/cleanup-resources.py

Perhaps a PagerDuty notification?

Custom Scaling Logic

If you have specific logic that should run after a successful scaling operation, the after_scale_success hook can automate this:

after_scale_success:
  - ./scripts/custom-scale-logic.sh

Updating Your Hooks

To integrate these hooks into your deployment process, simply add them to your .aptible.yml file. The hooks will take effect the next time you initiate a deploy. This allows you to continuously refine and automate your deployment workflows, ensuring that your operations are both resilient and efficient.


Aptible’s after-success and after-failure hooks give you powerful tools to automate and customize your app management. By leveraging these hooks, you can ensure your application responds dynamically to the outcomes of critical operations, reducing manual overhead and improving reliability. Whether it's sending a Slack notification, cleaning up resources, or executing custom scripts, these hooks make your deployments more adaptable and efficient.


Build Your Product.
Not Product Infra.

Build Your Product.
Not Product Infra.

Build Your Product.
Not Product Infra.

Build Your Product.
Not Product Infra.

548 Market St #75826 San Francisco, CA 94104

© 2024. All rights reserved. Privacy Policy

548 Market St #75826 San Francisco, CA 94104

© 2024. All rights reserved. Privacy Policy

548 Market St #75826 San Francisco, CA 94104

© 2024. All rights reserved. Privacy Policy

548 Market St #75826 San Francisco, CA 94104

© 2024. All rights reserved. Privacy Policy