/
stepfunctions.go
47 lines (38 loc) · 1.28 KB
/
stepfunctions.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
/*
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
package stepfunctions
import (
"context"
"github.com/aws/aws-sdk-go-v2/service/sfn"
"github.com/aws/aws-sdk-go-v2/service/sfn/types"
"github.com/aws/aws-sdk-go-v2/aws"
)
type StepFunctions interface {
StartExecution(ctx context.Context, input *sfn.StartExecutionInput) (*sfn.StartExecutionOutput, error)
GetStateMachineExecutionCount(ctx context.Context, stateMachineArn string) (int, error)
}
type SFN struct {
Client *sfn.Client
}
// NewFromConfig creates a new aws StepFunctions client
func NewFromConfig(sdkConfig aws.Config) *SFN {
innerClient := sfn.NewFromConfig(sdkConfig)
return &SFN{
Client: innerClient,
}
}
func (stepFunctions SFN) StartExecution(ctx context.Context, input *sfn.StartExecutionInput) (*sfn.StartExecutionOutput, error) {
return stepFunctions.Client.StartExecution(ctx, input)
}
func (stepFunctions SFN) GetStateMachineExecutionCount(ctx context.Context, stateMachineArn string) (int, error) {
stateMachineExecutionsList, err := stepFunctions.Client.ListExecutions(ctx, &sfn.ListExecutionsInput{
StateMachineArn: &stateMachineArn,
StatusFilter: types.ExecutionStatusRunning,
})
if err != nil {
return 0, err
}
return len(stateMachineExecutionsList.Executions), nil
}