Skip to content

Commit

Permalink
Attempt to notify the AutoScaling group as well
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Dwyer <Brian.Dwyer@broadridge.com>
  • Loading branch information
bdwyertech committed Jul 16, 2020
1 parent 0cbc556 commit 089a20d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/ec2"
)
Expand Down Expand Up @@ -121,6 +122,20 @@ func main() {
log.Fatal("Required tags were not present on EC2 Instance!")
}

if signalFailure {
// Also attempt to mark the instance as unhealthy in its respective ASG
_, err := autoscaling.New(sess).SetInstanceHealth(&autoscaling.SetInstanceHealthInput{
// Healthy/Unhealthy
HealthStatus: aws.String("Unhealthy"),
InstanceId: aws.String(instanceID),
ShouldRespectGracePeriod: aws.Bool(false),
})
if err != nil {
// Gracefully continue -- Might not have permissions, etc.
log.Warn(err)
}
}

cfclient := cloudformation.New(sess)

signal := &cloudformation.SignalResourceInput{
Expand All @@ -140,7 +155,7 @@ func main() {
waitUntilHealthy()
}

cfr, err := cfclient.SignalResource(signal)
_, err = cfclient.SignalResource(signal)
// Error Handling
// We don't want to have a non-zero exit code cause cloud-init unit failure during autoscaling operations
if err != nil {
Expand All @@ -156,8 +171,6 @@ func main() {
log.Fatal(err)
}()
}

log.Println("SignalResource Response:", cfr)
}

func waitUntilHealthy() {
Expand Down

0 comments on commit 089a20d

Please sign in to comment.