Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit d8bdc1d

Browse files
author
Florian Zeidler
authored
Merge pull request #23 from rebuy-de/extend-aws-nuke
Extend aws nuke for Lambda functions and IAM Policy Versions
2 parents fa463ae + 5bfe3e2 commit d8bdc1d

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

resources/iam-policies.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,25 @@ func (n *IamNuke) ListPolicies() ([]Resource, error) {
3030
}
3131

3232
func (e *IamPolicy) Remove() error {
33-
_, err := e.svc.DeletePolicy(&iam.DeletePolicyInput{
33+
resp, err := e.svc.ListPolicyVersions(&iam.ListPolicyVersionsInput{
34+
PolicyArn: &e.arn,
35+
})
36+
if err != nil {
37+
return err
38+
}
39+
for _, version := range resp.Versions {
40+
if !*version.IsDefaultVersion {
41+
_, err = e.svc.DeletePolicyVersion(&iam.DeletePolicyVersionInput{
42+
PolicyArn: &e.arn,
43+
VersionId: version.VersionId,
44+
})
45+
if err != nil {
46+
return err
47+
}
48+
49+
}
50+
}
51+
_, err = e.svc.DeletePolicy(&iam.DeletePolicyInput{
3452
PolicyArn: &e.arn,
3553
})
3654
if err != nil {

resources/lambda-functions.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package resources
2+
3+
import "github.com/aws/aws-sdk-go/service/lambda"
4+
5+
type LambdaFunction struct {
6+
svc *lambda.Lambda
7+
functionName *string
8+
}
9+
10+
func (n *LambdaNuke) ListFunctions() ([]Resource, error) {
11+
params := &lambda.ListFunctionsInput{}
12+
resp, err := n.Service.ListFunctions(params)
13+
if err != nil {
14+
return nil, err
15+
}
16+
17+
resources := make([]Resource, 0)
18+
for _, function := range resp.Functions {
19+
resources = append(resources, &LambdaFunction{
20+
svc: n.Service,
21+
functionName: function.FunctionName,
22+
})
23+
}
24+
25+
return resources, nil
26+
}
27+
28+
func (f *LambdaFunction) Remove() error {
29+
30+
_, err := f.svc.DeleteFunction(&lambda.DeleteFunctionInput{
31+
FunctionName: f.functionName,
32+
})
33+
34+
return err
35+
}
36+
37+
func (f *LambdaFunction) String() string {
38+
return *f.functionName
39+
}

resources/listers.go

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/aws/aws-sdk-go/service/elasticache"
1313
"github.com/aws/aws-sdk-go/service/elb"
1414
"github.com/aws/aws-sdk-go/service/iam"
15+
"github.com/aws/aws-sdk-go/service/lambda"
1516
"github.com/aws/aws-sdk-go/service/rds"
1617
"github.com/aws/aws-sdk-go/service/route53"
1718
"github.com/aws/aws-sdk-go/service/s3"
@@ -30,6 +31,7 @@ func GetListers(sess *session.Session) []ResourceLister {
3031
elasticache = ElasticacheNuke{elasticache.New(sess)}
3132
elb = ElbNuke{elb.New(sess)}
3233
iam = IamNuke{iam.New(sess)}
34+
lambda = LambdaNuke{lambda.New(sess)}
3335
rds = RDSNuke{rds.New(sess)}
3436
route53 = Route53Nuke{route53.New(sess)}
3537
s3 = S3Nuke{s3.New(sess)}
@@ -79,6 +81,7 @@ func GetListers(sess *session.Session) []ResourceLister {
7981
iam.ListUserGroupAttachements,
8082
iam.ListUserPolicyAttachements,
8183
iam.ListUsers,
84+
lambda.ListFunctions,
8285
rds.ListInstances,
8386
rds.ListParameterGroups,
8487
rds.ListSnapshots,

resources/types.go

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/aws/aws-sdk-go/service/elasticache"
1212
"github.com/aws/aws-sdk-go/service/elb"
1313
"github.com/aws/aws-sdk-go/service/iam"
14+
"github.com/aws/aws-sdk-go/service/lambda"
1415
"github.com/aws/aws-sdk-go/service/rds"
1516
"github.com/aws/aws-sdk-go/service/route53"
1617
"github.com/aws/aws-sdk-go/service/s3"
@@ -57,6 +58,10 @@ type IamNuke struct {
5758
Service *iam.IAM
5859
}
5960

61+
type LambdaNuke struct {
62+
Service *lambda.Lambda
63+
}
64+
6065
type RDSNuke struct {
6166
Service *rds.RDS
6267
}

0 commit comments

Comments
 (0)