forked from ekristen/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda-functions.go
92 lines (68 loc) · 1.89 KB
/
lambda-functions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package resources
import (
"context"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
const LambdaFunctionResource = "LambdaFunction"
func init() {
registry.Register(®istry.Registration{
Name: LambdaFunctionResource,
Scope: nuke.Account,
Lister: &LambdaFunctionLister{},
})
}
type LambdaFunctionLister struct{}
func (l *LambdaFunctionLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := lambda.New(opts.Session)
functions := make([]*lambda.FunctionConfiguration, 0)
params := &lambda.ListFunctionsInput{}
err := svc.ListFunctionsPages(params, func(page *lambda.ListFunctionsOutput, lastPage bool) bool {
functions = append(functions, page.Functions...)
return true
})
if err != nil {
return nil, err
}
resources := make([]resource.Resource, 0)
for _, function := range functions {
tags, err := svc.ListTags(&lambda.ListTagsInput{
Resource: function.FunctionArn,
})
if err != nil {
continue
}
resources = append(resources, &LambdaFunction{
svc: svc,
functionName: function.FunctionName,
tags: tags.Tags,
})
}
return resources, nil
}
type LambdaFunction struct {
svc *lambda.Lambda
functionName *string
tags map[string]*string
}
func (f *LambdaFunction) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", f.functionName)
for key, val := range f.tags {
properties.SetTag(&key, val)
}
return properties
}
func (f *LambdaFunction) Remove(_ context.Context) error {
_, err := f.svc.DeleteFunction(&lambda.DeleteFunctionInput{
FunctionName: f.functionName,
})
return err
}
func (f *LambdaFunction) String() string {
return *f.functionName
}