diff --git a/providers/aws/aws.go b/providers/aws/aws.go index 701d741f3..ecf1e862e 100644 --- a/providers/aws/aws.go +++ b/providers/aws/aws.go @@ -39,6 +39,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { ec2.Instances, ec2.ElasticIps, lambda.Functions, + lambda.EventSourceMappings, ec2.Acls, ec2.Subnets, ec2.SecurityGroups, diff --git a/providers/aws/lambda/eventsourcemappings.go b/providers/aws/lambda/eventsourcemappings.go new file mode 100644 index 000000000..fa961ed80 --- /dev/null +++ b/providers/aws/lambda/eventsourcemappings.go @@ -0,0 +1,68 @@ +package lambda + +import ( + "context" + "fmt" + "strings" + "time" + + log "github.com/sirupsen/logrus" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/tailwarden/komiser/models" + "github.com/tailwarden/komiser/providers" +) + +func EventSourceMappings(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { + resources := make([]models.Resource, 0) + lambdaClient := lambda.NewFromConfig(*client.AWSClient) + mappingsPerPage := aws.Int32(50) + params := &lambda.ListEventSourceMappingsInput{ + MaxItems: mappingsPerPage, + } + + paginator := lambda.NewListEventSourceMappingsPaginator(lambdaClient, params, func(options *lambda.ListEventSourceMappingsPaginatorOptions) { + options.Limit = *mappingsPerPage + }) + + for paginator.HasMorePages() { + + output, err := paginator.NextPage(ctx) + if err != nil { + log.Errorf("ERROR: Error occurred while retrieving EventSourceMappings page: %v", err) + return resources, err + } + + for _, mapping := range output.EventSourceMappings { + + lambdaNameSplit := strings.Split(*mapping.FunctionArn, ":") + lambdaName := lambdaNameSplit[len(lambdaNameSplit)-1] + + resources = append(resources, models.Resource{ + Provider: "AWS", + Account: client.Name, + Service: "EventSourceMapping", + ResourceId: *mapping.UUID, + Region: client.AWSClient.Region, + Name: *mapping.UUID, + Cost: 0.0, + Metadata: map[string]string{ + "lambda": *mapping.FunctionArn, + "source": *mapping.EventSourceArn, + }, + FetchedAt: time.Now(), + Link: fmt.Sprintf("https://%s.console.aws.amazon.com/lambda/home?region=%s#/functions/%s", client.AWSClient.Region, client.AWSClient.Region, lambdaName), + }) + } + } + + log.WithFields(log.Fields{ + "provider": "AWS", + "account": client.Name, + "region": client.AWSClient.Region, + "service": "EventSourceMapping", + "resources": len(resources), + }).Info("Fetched resources") + return resources, nil +} \ No newline at end of file