/
lambda_types.go
64 lines (51 loc) · 1.52 KB
/
lambda_types.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
package resources
import (
"context"
awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/lambda/lambdaiface"
"github.com/gruntwork-io/cloud-nuke/config"
"github.com/gruntwork-io/go-commons/errors"
)
type LambdaFunctions struct {
BaseAwsResource
Client lambdaiface.LambdaAPI
Region string
LambdaFunctionNames []string
}
func (lf *LambdaFunctions) Init(session *session.Session) {
lf.Client = lambda.New(session)
}
func (lf *LambdaFunctions) ResourceName() string {
return "lambda"
}
// ResourceIdentifiers - The names of the lambda functions
func (lf *LambdaFunctions) ResourceIdentifiers() []string {
return lf.LambdaFunctionNames
}
func (lf *LambdaFunctions) MaxBatchSize() int {
// Tentative batch size to ensure AWS doesn't throttle
return 49
}
func (lf *LambdaFunctions) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) {
identifiers, err := lf.getAll(c, configObj)
if err != nil {
return nil, err
}
lf.LambdaFunctionNames = awsgo.StringValueSlice(identifiers)
return lf.LambdaFunctionNames, nil
}
// Nuke - nuke 'em all!!!
func (lf *LambdaFunctions) Nuke(identifiers []string) error {
if err := lf.nukeAll(awsgo.StringSlice(identifiers)); err != nil {
return errors.WithStackTrace(err)
}
return nil
}
type LambdaDeleteError struct {
name string
}
func (e LambdaDeleteError) Error() string {
return "Lambda Function:" + e.name + "was not deleted"
}