/
stepfunction_statemachine.go
executable file
·52 lines (43 loc) · 1.3 KB
/
stepfunction_statemachine.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
package lister
import (
"fmt"
"github.com/aws/aws-sdk-go-v2/service/sfn"
"github.com/trek10inc/awsets/arn"
"github.com/trek10inc/awsets/context"
"github.com/trek10inc/awsets/resource"
)
type AWSStepFunctionStateMachine struct {
}
func init() {
i := AWSStepFunctionStateMachine{}
listers = append(listers, i)
}
func (l AWSStepFunctionStateMachine) Types() []resource.ResourceType {
return []resource.ResourceType{resource.StepFunctionStateMachine}
}
func (l AWSStepFunctionStateMachine) List(ctx context.AWSetsCtx) (*resource.Group, error) {
svc := sfn.NewFromConfig(ctx.AWSCfg)
rg := resource.NewGroup()
err := Paginator(func(nt *string) (*string, error) {
res, err := svc.ListStateMachines(ctx.Context, &sfn.ListStateMachinesInput{
MaxResults: 100,
NextToken: nt,
})
if err != nil {
return nil, err
}
for _, sm := range res.StateMachines {
res, err := svc.DescribeStateMachine(ctx.Context, &sfn.DescribeStateMachineInput{
StateMachineArn: sm.StateMachineArn,
})
if err != nil {
return nil, fmt.Errorf("failed to get state machine %s: %w", *sm.Name, err)
}
smArn := arn.ParseP(res.StateMachineArn)
r := resource.New(ctx, resource.StepFunctionStateMachine, smArn.ResourceId, sm.Name, res)
rg.AddResource(r)
}
return res.NextToken, nil
})
return rg, err
}