Skip to content

Commit

Permalink
add WAIT_SECONDS
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwara committed Oct 11, 2021
1 parent 12efddc commit 1ff8452
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ This function is supposed to be called by ASG lifecycle hook.
## Install

```console
docker pull ghcr.io/kayac/asg-lifecycle-hook-ec2:v0.0.1
docker pull ghcr.io/kayac/asg-lifecycle-hook-ec2:v0.0.3
```

[Release packages]()
[Release packages](https://github.com/kayac/asg-lifecycle-hook-ec2/releases)

## Configuration

All configuration parameters are defined in environment variables.

- `WAIT_SECONDS`: Seconds until complete the lifecycle action after the instance deregistered from load balancers.

## LICENSE

Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"fmt"
"log"
"os"
"strconv"
"strings"
"time"
_ "time/tzdata"

"github.com/aws/aws-lambda-go/events"
Expand Down Expand Up @@ -82,6 +84,14 @@ func handler(ctx context.Context, event *events.AutoScalingEvent) error {
if err := drainInstance(sess, asgSvc, asgName, instanceID); err != nil {
return err
}
if s := os.Getenv("WAIT_SECONDS"); s != "" {
if n, err := strconv.ParseInt(s, 10, 64); err == nil {
log.Printf("[info] waiting %d seconds", n)
time.Sleep(time.Duration(n) * time.Second)
} else {
log.Printf("[error] invalid WAIT_SECONDS: %s, %s", s, err)
}
}
if err := complate(asgSvc, event); err != nil {
return err
}
Expand Down

0 comments on commit 1ff8452

Please sign in to comment.