Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/550 lambda eventsourcemapping #1040

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
ec2.Instances,
ec2.ElasticIps,
lambda.Functions,
lambda.EventSourceMappings,
ec2.Acls,
ec2.Subnets,
ec2.SecurityGroups,
Expand Down
57 changes: 57 additions & 0 deletions providers/aws/lambda/eventsourcemappings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package lambda

import (
"context"
"fmt"
"strings"
"time"

log "github.com/sirupsen/logrus"

"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) {
var config lambda.ListEventSourceMappingsInput
resources := make([]models.Resource, 0)
lambdaClient := lambda.NewFromConfig(*client.AWSClient)

result, err := lambdaClient.ListEventSourceMappings(context.Background(), &config)
Azanul marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Errorf("ERROR: Failed to fetch EventSourceMappings: %v", err)
return resources, err
}

for _, mapping := range result.EventSourceMappings {
Azanul marked this conversation as resolved.
Show resolved Hide resolved

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep the anr field here instead of UUID, we do that most of the places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik, eventsourcemapping doesn't really have an arn, it has a UUID. That's because it's essentially an intermediary between the source (eg. SQS or Kinesis) and the lambda function. I can access the source ARN and lambda ARN though.

I've checked the above in the go sdk docs as well, if you find something different let me know and I'll make those changes.

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
}
Loading