-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathupdateAutoscaling.go
58 lines (49 loc) · 1.76 KB
/
updateAutoscaling.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/applicationautoscaling"
"fmt"
)
var awsRegion = "us-west-2"
var readDimension = "dynamodb:table:ReadCapacityUnits"
var resourceID = fmt.Sprintf("%s%s", "table/", tableName)
var roleARN = "PUT_YOUR_ROLE_ARN_HERE"
var tableName = "Music"
var writeDimension = "dynamodb:table:WriteCapacityUnits"
func getSession() (*session.Session) {
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
// Provide SDK Config options, such as Region and Endpoint
Config: aws.Config{
Region: aws.String(awsRegion),
},
}))
return sess
}
func registerScalableTarget(
autoscalingClient *applicationautoscaling.ApplicationAutoScaling,
dimension string,
) {
input := &applicationautoscaling.RegisterScalableTargetInput{
MaxCapacity: aws.Int64(500),
MinCapacity: aws.Int64(1),
ResourceId: aws.String(resourceID),
RoleARN: aws.String(roleARN),
ScalableDimension: aws.String(dimension),
ServiceNamespace: aws.String("dynamodb"),
}
autoscalingClient.RegisterScalableTarget(input)
}
func registerAutoscaling() {
autoscalingClient := applicationautoscaling.New(getSession())
registerScalableTarget(autoscalingClient, readDimension)
fmt.Println("Read scalable target registered ...")
registerScalableTarget(autoscalingClient, writeDimension)
fmt.Println("Write scalable target registered ...")
}
func main() {
fmt.Println("Updating autoscaling settings ...")
registerAutoscaling()
fmt.Println("Finished ...")
}