-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_reader.go
More file actions
69 lines (61 loc) · 2.42 KB
/
Copy pathtest_reader.go
File metadata and controls
69 lines (61 loc) · 2.42 KB
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
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"reflect"
// "strings"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/aws"
// "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
// "github.com/aws/aws-sdk-go/aws/requests"
"github.com/aws/aws-sdk-go/aws/session"
)
type stringInDynArray struct {
value string
}
func (s *stringInDynArray) SetValue(value string) {
s.value = value
}
func (s stringInDynArray) Value() string {
return s.value
}
func main() {
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-west-1"),
Credentials: credentials.NewSharedCredentials("", ""),
})
ecsClient := ecs.New(sess)
// first list services
res, err := ecsClient.ListServices(&ecs.ListServicesInput{
Cluster: aws.String("default"),
})
// Declare a new list to store service names
s := []stringInDynArray{}
for _, item := range res.ServiceArns {
//s = append(s, stringInDynArray{strings.Split(*item, "/")[1]})
s = append(s, stringInDynArray{*item})
}
awsStringSlice := make([]*string, 0)
for _, item := range s {
awsStringSlice = append(awsStringSlice, aws.String(item.Value()))
}
fmt.Printf("aws string slice is %s", awsStringSlice)
// s now is a list containing all services from faas cluster
fmt.Printf("list services result is %s, error is %s", res.ServiceArns, err)
// describe services
descServicesInput := &ecs.DescribeServicesInput {
Services: awsStringSlice,
}
descServicesResult, descServicesErr := ecsClient.DescribeServices(descServicesInput)
fmt.Printf("Desribe services result: %s, error: %s", descServicesResult, descServicesErr)
desiredCount := descServicesResult.Services[0].DesiredCount
taskDefinitionName := descServicesResult.Services[1].TaskDefinition
serviceName := descServicesResult.Services[0].ServiceName
// get task definition
taskDefinitionInput := &ecs.DescribeTaskDefinitionInput {
TaskDefinition: aws.String(*taskDefinitionName),
}
result, errrr := ecsClient.DescribeTaskDefinition(taskDefinitionInput)
image := result.TaskDefinition.ContainerDefinitions[0].Image
fmt.Printf("\nDescribe Task Definition result: %s, error: %s, image: %s, serviceName: %s, \n Desired count : %s", result, errrr, *image, *serviceName, uint64(*desiredCount))
}