-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
51 lines (46 loc) · 1.06 KB
/
list.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
package main
import (
"context"
"fmt"
"sort"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/lambda"
"github.com/spf13/cobra"
)
var listCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List functions",
RunE: func(c *cobra.Command, args []string) error {
fns, err := listFunctions()
if err != nil {
return err
}
for _, f := range fns {
fmt.Println(f)
}
return nil
},
}
// listFunctions lists all lambdafy functions.
func listFunctions() ([]string, error) {
fns := []string{}
ctx := context.Background()
acfg, err := awsconfig.LoadDefaultConfig(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load aws config: %s", err)
}
lambdaCl := lambda.NewFromConfig(acfg)
listPages := lambda.NewListFunctionsPaginator(lambdaCl, &lambda.ListFunctionsInput{})
for listPages.HasMorePages() {
p, err := listPages.NextPage(ctx)
if err != nil {
return nil, err
}
for _, f := range p.Functions {
fns = append(fns, *f.FunctionName)
}
}
sort.Strings(fns)
return fns, nil
}