@@ -9,6 +9,7 @@ import Lambda, {
99 GetFunctionConcurrencyRequest ,
1010 GetFunctionConcurrencyResponse ,
1111 ReservedConcurrentExecutions ,
12+ GetPolicyResponse
1213} from 'aws-sdk/clients/lambda'
1314import { AWSError } from 'aws-sdk/lib/error'
1415import { Config } from 'aws-sdk/lib/config'
@@ -30,6 +31,10 @@ export interface RawAwsLambdaFunction extends FunctionConfiguration {
3031 Tags ?: TagMap
3132 region : string
3233 reservedConcurrentExecutions : ReservedConcurrentExecutions
34+ PolicyData ?: {
35+ Policy ?: string
36+ RevisionId ?: string
37+ }
3338}
3439
3540const listFunctionsForRegion = async ( {
@@ -132,6 +137,28 @@ const getResourceTags = async (lambda: Lambda, arn: string): Promise<TagMap> =>
132137 }
133138 } )
134139
140+ const getLambdaPolicy = async ( lambda : Lambda , arn : string ) : Promise < { Policy ?: string ; RevisionId ?: string } > =>
141+ new Promise ( resolve => {
142+ try {
143+ lambda . getPolicy (
144+ { FunctionName : arn } ,
145+ ( err : AWSError , data : GetPolicyResponse ) => {
146+ if ( err ) {
147+ errorLog . generateAwsErrorLog ( {
148+ functionName : 'lambda:getPolicy' ,
149+ err,
150+ } )
151+ resolve ( { } )
152+ }
153+ const { Policy = '' , RevisionId = '' } = data || { }
154+ resolve ( { Policy, RevisionId } )
155+ }
156+ )
157+ } catch ( error ) {
158+ resolve ( { } )
159+ }
160+ } )
161+
135162export default async ( {
136163 regions,
137164 config,
@@ -171,15 +198,17 @@ export default async ({
171198 await Promise . all ( regionPromises )
172199 logger . debug ( lt . fetchedLambdas ( lambdaData . length ) )
173200
174- // get all tags for each Lambda
201+ // get all tags and policy for each Lambda
175202 lambdaData . map ( ( { FunctionArn : arn , region } , idx ) => {
176203 const lambda = new Lambda ( { ...config , region, endpoint } )
177- const tagsPromise = new Promise < void > ( async resolveTags => {
204+ const tagsAndPolicyPromise = new Promise < void > ( async resolveData => {
178205 const envTags : TagMap = await getResourceTags ( lambda , arn )
179206 lambdaData [ idx ] . Tags = envTags
180- resolveTags ( )
207+ const policy = await getLambdaPolicy ( lambda , arn )
208+ lambdaData [ idx ] . PolicyData = policy
209+ resolveData ( )
181210 } )
182- tagsPromises . push ( tagsPromise )
211+ tagsPromises . push ( tagsAndPolicyPromise )
183212 } )
184213
185214 logger . debug ( lt . gettingLambdaTags )
0 commit comments