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

Function CachedLambdaGetFunctionUrlConfig

aws/sdk/lambda.go:125–174  ·  view source on GitHub ↗

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

(client LambdaClientInterface, accountID string, region string, functionName string)

Source from the content-addressed store, hash-verified

123
124// create a CachedLambdaGetFunctionUrlConfig function that accepts a lambda client, account id, region, and function name. Make sure it uses go-cache and handles the region option
125func CachedLambdaGetFunctionUrlConfig(client LambdaClientInterface, accountID string, region string, functionName string) (customGetFuntionURLOutput, error) {
126 var functionUrlConfigOutput customGetFuntionURLOutput
127 cacheKey := fmt.Sprintf("%s-lambda-GetFunctionUrlConfig-%s-%s", accountID, region, functionName)
128 cached, found := internal.Cache.Get(cacheKey)
129 if found {
130 sharedLogger.WithFields(logrus.Fields{
131 "api": "lambda:GetFunctionUrlConfig",
132 "account": accountID,
133 "region": region,
134 "function": functionName,
135 "cache": "hit",
136 }).Info("AWS API call")
137 return cached.(customGetFuntionURLOutput), nil
138 }
139 sharedLogger.WithFields(logrus.Fields{
140 "api": "lambda:GetFunctionUrlConfig",
141 "account": accountID,
142 "region": region,
143 "function": functionName,
144 "cache": "miss",
145 }).Info("AWS API call")
146
147 GetFunctionUrlConfig, err := client.GetFunctionUrlConfig(
148 context.TODO(),
149 &lambda.GetFunctionUrlConfigInput{
150 FunctionName: &functionName,
151 },
152 func(o *lambda.Options) {
153 o.Region = region
154 },
155 )
156
157 if err != nil {
158 return functionUrlConfigOutput, err
159 }
160
161 functionUrlConfigOutput = customGetFuntionURLOutput{
162 AuthType: GetFunctionUrlConfig.AuthType,
163 CreationTime: GetFunctionUrlConfig.CreationTime,
164 FunctionArn: GetFunctionUrlConfig.FunctionArn,
165 FunctionUrl: GetFunctionUrlConfig.FunctionUrl,
166 LastModifiedTime: GetFunctionUrlConfig.LastModifiedTime,
167 Cors: GetFunctionUrlConfig.Cors,
168 InvokeMode: GetFunctionUrlConfig.InvokeMode,
169 }
170
171 internal.Cache.Set(cacheKey, functionUrlConfigOutput, cache.DefaultExpiration)
172
173 return functionUrlConfigOutput, nil
174}

Callers 1

Calls 2

InfoMethod · 0.80
GetFunctionUrlConfigMethod · 0.65

Tested by

no test coverage detected