-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamodb.go
32 lines (30 loc) · 1.04 KB
/
dynamodb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package pubghealth
import (
"context"
"time"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/aws"
"github.com/heptiolabs/healthcheck"
"github.com/pkg/errors"
)
// DynamoTableStatusCheck verifies that the table passed in exists and is in the Active state, ready to be used.
func DynamoTableStatusCheck(client *dynamodb.DynamoDB, tableName string, timeout time.Duration, frequency time.Duration) healthcheck.Check {
checkFunc := func() error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
input := &dynamodb.DescribeTableInput{
TableName: aws.String(tableName),
}
out, err := client.DescribeTableWithContext(ctx, input)
if err != nil {
return err
}
tableStatus := *out.Table.TableStatus
if tableStatus != dynamodb.GlobalTableStatusActive &&
tableStatus != dynamodb.GlobalTableStatusUpdating {
return errors.Errorf("Dynamo table '%s' exists but is not ready, status: %s", tableName, tableStatus)
}
return nil
}
return healthcheck.Async(checkFunc, frequency)
}