Skip to content

Commit 48ee1f0

Browse files
author
Marco Franceschi
committed
feat: Added aws_lambda_event_invoke_config for RT
1 parent 9afbfb0 commit 48ee1f0

4 files changed

Lines changed: 87 additions & 8 deletions

File tree

src/services/lambda/data.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import Lambda, {
1111
ReservedConcurrentExecutions,
1212
GetPolicyResponse,
1313
ListEventSourceMappingsResponse,
14-
EventSourceMappingConfiguration
14+
EventSourceMappingConfiguration,
15+
ListFunctionEventInvokeConfigsResponse,
16+
FunctionEventInvokeConfig
1517
} from 'aws-sdk/clients/lambda'
1618
import { AWSError } from 'aws-sdk/lib/error'
1719
import { Config } from 'aws-sdk/lib/config'
@@ -38,6 +40,7 @@ export interface RawAwsLambdaFunction extends FunctionConfiguration {
3840
RevisionId?: string
3941
}
4042
EventSourceMappings?: EventSourceMappingConfiguration[]
43+
EventInvokeConfigs?: FunctionEventInvokeConfig[]
4144
}
4245

4346
const listFunctionsForRegion = async ({
@@ -185,6 +188,29 @@ const getEventSourceMappings = async (lambda: Lambda, arn: string): Promise<Even
185188
}
186189
})
187190

191+
const getEventInvokeConfigs = async (lambda: Lambda, name: string): Promise<FunctionEventInvokeConfig[]> =>
192+
new Promise(resolve => {
193+
try {
194+
lambda.listFunctionEventInvokeConfigs(
195+
{ FunctionName: name },
196+
(err: AWSError, data: ListFunctionEventInvokeConfigsResponse) => {
197+
if (err) {
198+
errorLog.generateAwsErrorLog({
199+
functionName: 'lambda:listFunctionEventInvokeConfigs',
200+
err,
201+
})
202+
resolve([])
203+
}
204+
const { FunctionEventInvokeConfigs = [] } = data || {}
205+
206+
resolve(FunctionEventInvokeConfigs)
207+
}
208+
)
209+
} catch (error) {
210+
resolve([])
211+
}
212+
})
213+
188214
export default async ({
189215
regions,
190216
config,
@@ -225,7 +251,7 @@ export default async ({
225251
logger.debug(lt.fetchedLambdas(lambdaData.length))
226252

227253
// get all tags and policy for each Lambda
228-
lambdaData.map(({ FunctionArn: arn, region }, idx) => {
254+
lambdaData.map(({ FunctionArn: arn, region, FunctionName: name }, idx) => {
229255
const lambda = new Lambda({ ...config, region, endpoint })
230256
const additionalMetadataPromise = new Promise<void>(async resolveData => {
231257
const envTags: TagMap = await getResourceTags(lambda, arn)
@@ -234,6 +260,8 @@ export default async ({
234260
lambdaData[idx].PolicyData = policy
235261
const eventSourceMappings = await getEventSourceMappings(lambda, arn)
236262
lambdaData[idx].EventSourceMappings = eventSourceMappings
263+
const eventInvokeConfigs = await getEventInvokeConfigs(lambda, name)
264+
lambdaData[idx].EventInvokeConfigs = eventInvokeConfigs
237265
resolveData()
238266
})
239267
tagsPromises.push(additionalMetadataPromise)

src/services/lambda/format.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { generateUniqueId } from '@cloudgraph/sdk'
22
import isEmpty from 'lodash/isEmpty'
33
import t from '../../properties/translations'
4-
import { AwsLambda, AwsLambdaEventSourceMappings } from '../../types/generated'
4+
import { AwsLambda, AwsLambdaEventInvokeConfig, AwsLambdaEventSourceMappings } from '../../types/generated'
55
import { formatTagsFromMap, formatIamJsonPolicy } from '../../utils/format'
66
import { RawAwsLambdaFunction } from './data'
7-
import { EventSourceMappingConfiguration } from 'aws-sdk/clients/lambda'
7+
import { EventSourceMappingConfiguration, FunctionEventInvokeConfig } from 'aws-sdk/clients/lambda'
88

99
/**
1010
* Lambda
@@ -35,7 +35,8 @@ export default ({
3535
reservedConcurrentExecutions: rawReservedConcurrentExecutions,
3636
VpcConfig: vpcConfig,
3737
PolicyData: { Policy: policy = '', RevisionId: policyRevisionId = '' },
38-
EventSourceMappings: eventSourceMappings = []
38+
EventSourceMappings: eventSourceMappings = [],
39+
EventInvokeConfigs: eventInvokeConfigs = []
3940
} = rawData
4041
const environmentVariables = []
4142
const secretNames = [t.pass, t.secret, t.private, t.cert]
@@ -127,6 +128,32 @@ export default ({
127128
)
128129
}
129130

131+
const formatEventInvokeConfigs = (
132+
eventInvokeConfigs?: FunctionEventInvokeConfig[]
133+
): AwsLambdaEventInvokeConfig[] => {
134+
return (
135+
eventInvokeConfigs?.map(e => ({
136+
id: generateUniqueId({
137+
arn,
138+
...e,
139+
}),
140+
lastModified: e.LastModified?.toISOString(),
141+
functionArn: e.FunctionArn,
142+
maximumRetryAttempts: e.MaximumRetryAttempts,
143+
maximumEventAgeInSeconds: e.MaximumEventAgeInSeconds,
144+
destinationConfig: {
145+
id: generateUniqueId({
146+
arn,
147+
...e.DestinationConfig,
148+
149+
}),
150+
OnSuccess: e.DestinationConfig?.OnSuccess?.Destination,
151+
OnFailure: e.DestinationConfig?.OnFailure?.Destination
152+
}
153+
})) || []
154+
)
155+
}
156+
130157
return {
131158
accountId: account,
132159
arn,
@@ -149,6 +176,7 @@ export default ({
149176
rawPolicy: policy,
150177
policy: formatIamJsonPolicy(policy),
151178
tags: formatTagsFromMap(Tags),
152-
eventSourceMappings: formatEventSourceMappings(eventSourceMappings)
179+
eventSourceMappings: formatEventSourceMappings(eventSourceMappings),
180+
eventInvokeConfigs: formatEventInvokeConfigs(eventInvokeConfigs)
153181
}
154182
}

src/services/lambda/schema.graphql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ type awsLambdaDestinationConfig
3030
OnFailure: String @search(by: [hash, regexp])
3131
}
3232

33+
type awsLambdaEventInvokeConfig
34+
@generate(
35+
query: { get: false, query: true, aggregate: false }
36+
mutation: { add: false, delete: false }
37+
subscription: false
38+
) {
39+
id: String! @id
40+
lastModified: DateTime @search(by: [day])
41+
functionArn: String @search(by: [hash, regexp])
42+
maximumRetryAttempts: Int
43+
maximumEventAgeInSeconds: Int
44+
destinationConfig: awsLambdaDestinationConfig
45+
}
46+
3347
type awsLambdaEventSourceMappings
3448
@generate(
3549
query: { get: false, query: true, aggregate: false }
@@ -80,6 +94,7 @@ type awsLambda implements awsBaseService @key(fields: "arn") {
8094
rawPolicy: String @search(by: [hash, regexp])
8195
policy: awsIamJSONPolicy
8296
eventSourceMappings: [awsLambdaEventSourceMappings]
97+
eventInvokeConfigs: [awsLambdaEventInvokeConfig]
8398
tags: [awsRawTag]
8499
kms: [awsKms] @hasInverse(field: lambda)
85100
securityGroups: [awsSecurityGroup] @hasInverse(field: lambda)

src/types/generated.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,6 +3410,7 @@ export type AwsLambda = AwsBaseService & {
34103410
cognitoUserPools?: Maybe<Array<Maybe<AwsCognitoUserPool>>>;
34113411
description?: Maybe<Scalars['String']>;
34123412
environmentVariables?: Maybe<Array<Maybe<AwsLambdaEnvironmentVariable>>>;
3413+
eventInvokeConfigs?: Maybe<Array<Maybe<AwsLambdaEventInvokeConfig>>>;
34133414
eventSourceMappings?: Maybe<Array<Maybe<AwsLambdaEventSourceMappings>>>;
34143415
handler?: Maybe<Scalars['String']>;
34153416
iamRole?: Maybe<Array<Maybe<AwsIamRole>>>;
@@ -3447,6 +3448,15 @@ export type AwsLambdaEnvironmentVariable = {
34473448
value?: Maybe<Scalars['String']>;
34483449
};
34493450

3451+
export type AwsLambdaEventInvokeConfig = {
3452+
destinationConfig?: Maybe<AwsLambdaDestinationConfig>;
3453+
functionArn?: Maybe<Scalars['String']>;
3454+
id: Scalars['String'];
3455+
lastModified?: Maybe<Scalars['DateTime']>;
3456+
maximumEventAgeInSeconds?: Maybe<Scalars['Int']>;
3457+
maximumRetryAttempts?: Maybe<Scalars['Int']>;
3458+
};
3459+
34503460
export type AwsLambdaEventSourceConfig = {
34513461
consumerGroupId?: Maybe<Scalars['String']>;
34523462
id: Scalars['String'];
@@ -3469,9 +3479,7 @@ export type AwsLambdaEventSourceMappings = {
34693479
maximumRetryAttempts?: Maybe<Scalars['Int']>;
34703480
parallelizationFactor?: Maybe<Scalars['Int']>;
34713481
queues?: Maybe<Array<Maybe<Scalars['String']>>>;
3472-
selfManagedEventSource?: Maybe<Array<Maybe<Scalars['String']>>>;
34733482
selfManagedKafkaEventSourceConfig?: Maybe<AwsLambdaEventSourceConfig>;
3474-
sourceAccessConfigurations?: Maybe<Array<Maybe<AwsLambdaSourceAccessConfiguration>>>;
34753483
startingPosition?: Maybe<Scalars['String']>;
34763484
state?: Maybe<Scalars['String']>;
34773485
stateTransitionReason?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)