Anantha BM , first of all, thanks for giving this article a read and finding it useful :)
Secondly, that’s a good question.
So, I haven’t faced any such kind of situation in my experience but I believe if such thing occurs, this solution would work :-
So, you can setup Amazon SNS topics for Elastic Beanstalk environment notifications.
So, whenever a “certain” event happens in the Elastic Beanstalk environment, it can be configured to send a message to an Amazon SNS topic created by engineers and hence, its subscribers.
(By the way, this “certain” event can be any event associated with the health change. For example, in our situation, as soon as status of the environment goes to unhealthy)
Then, you can setup a Lambda function as one of the subscribers of that Amazon SNS topic.
Now, that lambda function can contain a piece code which when run, will call the Travis API V3 with rightful request body to rebuild the repository and then, send a mail to a person or a team saying “Guys, the Elastic Beanstalk environment build failed, So, travis CI is rebuilding the code now”.
TL;DR
- Set the Elasticbeanstalk environment notifications to create an SNS topic which will be triggered whenever the Elasticbeanstalk environment health status changes to UNHEALTHY.
- Create a lambda function which when run, will call the Travis API V3 with rightful request body to rebuild the repository and then, send a mail to a person or a team saying “Guys, the Elastic Beanstalk environment build failed, So, travis CI is rebuilding the code now”.
- Set that Lambda function as one of the subscribers of that SNS topic.
So, finally, this would happen…
Elastic Beanstalk environment status changes to unhealthy -> It calls the SNS topic -> Lambda function, which is a subscriber of this SNS topic, gets triggered and runs the code in it, which rebuilds the code on Travis CI and sends mail to the developers -> Travis CI rebuilds the code and deploys it again on Elastic Beanstalk environment. Meanwhile, the developers get notified about this situation from the mail they receive from the Lambda function.
By the way, if you ONLY want to send the mail to someone whenever the event happens, it’s not necessary to setup a lambda function because Elastic Beanstalk has support for directly sending mails whenever any event happens.
But still I explained here in regards with using a Lambda function because with Lambda function you can do anything apart from just sending mails if the health status of the elastic beanstalk environment changes like, in this situation, calling Travis APIv3 to rebuild the code as well.
Hope that was clear :)