This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlambda.go
65 lines (50 loc) · 1.89 KB
/
lambda.go
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
62
63
64
65
/******************************************************************************
Cloud Resource Counter
File: lambda.go
Summary: Provides a count of all Lambda functions.
******************************************************************************/
package main
import (
"github.com/aws/aws-sdk-go/service/lambda"
color "github.com/logrusorgru/aurora"
)
// LambdaFunctions retrieves the count of all lambda function
// either for all regions (allRegions is true) or the region
// associated with the session. This method gives status back
// to the user via the supplied ActivityMonitor instance.
func LambdaFunctions(sf ServiceFactory, am ActivityMonitor, allRegions bool) int {
// Indicate activity
am.StartAction("Retrieving Lambda function counts")
// Should we get the counts for all regions?
instanceCount := 0
if allRegions {
// Get the list of all enabled regions for this account
regionsSlice := GetEC2Regions(sf.GetEC2InstanceService(""), am)
// Loop through all of the regions
for _, regionName := range regionsSlice {
// Get the Lambda counts for a specific region
instanceCount += lambdaFunctionsForSingleRegion(sf.GetLambdaService(regionName), am)
}
} else {
// Get the Lambda counts for the region selected by this session
instanceCount = lambdaFunctionsForSingleRegion(sf.GetLambdaService(""), am)
}
// Indicate end of activity
am.EndAction("OK (%d)", color.Bold(instanceCount))
return instanceCount
}
func lambdaFunctionsForSingleRegion(ls *LambdaService, am ActivityMonitor) int {
// Construct our input to find all Lambda instances
input := &lambda.ListFunctionsInput{}
// Indicate activity
am.Message(".")
// Invoke our service
functionCounts := 0
err := ls.ListFunctions(input, func(page *lambda.ListFunctionsOutput, lastPage bool) bool {
functionCounts += len(page.Functions)
return true
})
// Check for error
am.CheckError(err)
return functionCounts
}