File: lambda-event-source-mapping.go

package info (click to toggle)
aws-nuke 2.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,852 kB
  • sloc: makefile: 17; sh: 1
file content (61 lines) | stat: -rw-r--r-- 1,410 bytes parent folder | download
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
package resources

import (
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/lambda"
	"github.com/rebuy-de/aws-nuke/pkg/types"
)

type LambdaEventSourceMapping struct {
	svc     *lambda.Lambda
	mapping *lambda.EventSourceMappingConfiguration
}

func init() {
	register("LambdaEventSourceMapping", ListLambdaEventSourceMapping)
}

func ListLambdaEventSourceMapping(sess *session.Session) ([]Resource, error) {
	svc := lambda.New(sess)
	resources := []Resource{}

	params := &lambda.ListEventSourceMappingsInput{}
	for {
		resp, err := svc.ListEventSourceMappings(params)
		if err != nil {
			return nil, err
		}

		for _, mapping := range resp.EventSourceMappings {
			resources = append(resources, &LambdaEventSourceMapping{
				svc:     svc,
				mapping: mapping,
			})
		}

		if resp.NextMarker == nil {
			break
		}

		params.Marker = resp.NextMarker
	}

	return resources, nil
}

func (m *LambdaEventSourceMapping) Remove() error {
	_, err := m.svc.DeleteEventSourceMapping(&lambda.DeleteEventSourceMappingInput{
		UUID: m.mapping.UUID,
	})

	return err
}

func (m *LambdaEventSourceMapping) Properties() types.Properties {
	properties := types.NewProperties()
	properties.Set("UUID", m.mapping.UUID)
	properties.Set("EventSourceArn", m.mapping.EventSourceArn)
	properties.Set("FunctionArn", m.mapping.FunctionArn)
	properties.Set("State", m.mapping.State)
	return properties
}