MCPcopy Create free account
hub / github.com/BishopFox/cloudfox / CachedLambdaListFunctions

Function CachedLambdaListFunctions

aws/sdk/lambda.go:27–74  ·  view source on GitHub ↗

create a CachedLambdaListFunctions function that accepts a lambda client, account id, region. Make sure it uses go-cache and handles the region option and pagination

(client LambdaClientInterface, accountID string, region string)

Source from the content-addressed store, hash-verified

25
26// create a CachedLambdaListFunctions function that accepts a lambda client, account id, region. Make sure it uses go-cache and handles the region option and pagination
27func CachedLambdaListFunctions(client LambdaClientInterface, accountID string, region string) ([]lambdaTypes.FunctionConfiguration, error) {
28 var PaginationControl *string
29 var functions []lambdaTypes.FunctionConfiguration
30 cacheKey := fmt.Sprintf("%s-lambda-ListFunctions-%s", accountID, region)
31 cached, found := internal.Cache.Get(cacheKey)
32 if found {
33 sharedLogger.WithFields(logrus.Fields{
34 "api": "lambda:ListFunctions",
35 "account": accountID,
36 "region": region,
37 "cache": "hit",
38 }).Info("AWS API call")
39 return cached.([]lambdaTypes.FunctionConfiguration), nil
40 }
41 sharedLogger.WithFields(logrus.Fields{
42 "api": "lambda:ListFunctions",
43 "account": accountID,
44 "region": region,
45 "cache": "miss",
46 }).Info("AWS API call")
47
48 for {
49 ListFunctions, err := client.ListFunctions(
50 context.TODO(),
51 &lambda.ListFunctionsInput{
52 Marker: PaginationControl,
53 },
54 func(o *lambda.Options) {
55 o.Region = region
56 },
57 )
58
59 if err != nil {
60 return functions, err
61 }
62
63 functions = append(functions, ListFunctions.Functions...)
64
65 //pagination
66 if ListFunctions.NextMarker == nil {
67 break
68 }
69 PaginationControl = ListFunctions.NextMarker
70 }
71 internal.Cache.Set(cacheKey, functions, cache.DefaultExpiration)
72
73 return functions, nil
74}
75
76type customGetFuntionURLOutput struct {
77 // The type of authentication that your function URL uses. Set to AWS_IAM if you

Calls 2

InfoMethod · 0.80
ListFunctionsMethod · 0.65

Tested by

no test coverage detected