1+ import { generateUniqueId } from '@cloudgraph/sdk'
12import isEmpty from 'lodash/isEmpty'
23import t from '../../properties/translations'
3- import { AwsLambda } from '../../types/generated'
4+ import { AwsLambda , AwsLambdaEventInvokeConfig , AwsLambdaEventSourceMappings , AwsLambdaLayerVersion } from '../../types/generated'
45import { formatTagsFromMap , formatIamJsonPolicy } from '../../utils/format'
56import { RawAwsLambdaFunction } from './data'
7+ import { EventSourceMappingConfiguration , FunctionEventInvokeConfig , Layer } from 'aws-sdk/clients/lambda'
68
79/**
810 * Lambda
@@ -33,6 +35,9 @@ export default ({
3335 reservedConcurrentExecutions : rawReservedConcurrentExecutions ,
3436 VpcConfig : vpcConfig ,
3537 PolicyData : { Policy : policy = '' , RevisionId : policyRevisionId = '' } ,
38+ EventSourceMappings : eventSourceMappings = [ ] ,
39+ EventInvokeConfigs : eventInvokeConfigs = [ ] ,
40+ Layers : layers = [ ]
3641 } = rawData
3742 const environmentVariables = [ ]
3843 const secretNames = [ t . pass , t . secret , t . private , t . cert ]
@@ -68,10 +73,120 @@ export default ({
6873 securityGroupIds : vpcConfig ?. SecurityGroupIds ,
6974 }
7075
76+ const formatEventSourceMappings = (
77+ eventSourceMappings ?: EventSourceMappingConfiguration [ ]
78+ ) : AwsLambdaEventSourceMappings [ ] => {
79+ return (
80+ eventSourceMappings ?. map ( e => ( {
81+ id : generateUniqueId ( {
82+ arn,
83+ ...e ,
84+ } ) ,
85+ uuid : e . UUID ,
86+ startingPosition : e . StartingPosition ,
87+ batchSize : e . BatchSize ,
88+ maximumBatchingWindowInSeconds : e . MaximumBatchingWindowInSeconds ,
89+ parallelizationFactor : e . ParallelizationFactor ,
90+ eventSourceArn : e . EventSourceArn ,
91+ filterCriteria : e . FilterCriteria ?. Filters ?. map ( f => f . Pattern ) || [ ] ,
92+ functionArn : e . FunctionArn ,
93+ lastModified : e . LastModified ?. toISOString ( ) ,
94+ lastProcessingResult : e . LastProcessingResult ,
95+ state : e . State ,
96+ stateTransitionReason : e . StateTransitionReason ,
97+ destinationConfig : {
98+ id : generateUniqueId ( {
99+ arn,
100+ ...e . DestinationConfig ,
101+
102+ } ) ,
103+ OnSuccess : e . DestinationConfig ?. OnSuccess ?. Destination ,
104+ OnFailure : e . DestinationConfig ?. OnFailure ?. Destination
105+
106+ } ,
107+ topics : e . Topics ,
108+ queues : e . Queues ,
109+ maximumRecordAgeInSeconds : e . MaximumRecordAgeInSeconds ,
110+ bisectBatchOnFunctionError : e . BisectBatchOnFunctionError ,
111+ maximumRetryAttempts : e . MaximumRetryAttempts ,
112+ tumblingWindowInSeconds : e . TumblingWindowInSeconds ,
113+ functionResponseTypes : e . FunctionResponseTypes ,
114+ amazonManagedKafkaEventSourceConfig : {
115+ id : generateUniqueId ( {
116+ arn,
117+ ...e . AmazonManagedKafkaEventSourceConfig
118+ } ) ,
119+ consumerGroupId : e . AmazonManagedKafkaEventSourceConfig ?. ConsumerGroupId
120+ } ,
121+ selfManagedKafkaEventSourceConfig : {
122+ id : generateUniqueId ( {
123+ arn,
124+ ...e . SelfManagedKafkaEventSourceConfig
125+ } ) ,
126+ consumerGroupId : e . SelfManagedKafkaEventSourceConfig ?. ConsumerGroupId
127+ }
128+ } ) ) || [ ]
129+ )
130+ }
131+
132+ const formatEventInvokeConfigs = (
133+ eventInvokeConfigs ?: FunctionEventInvokeConfig [ ]
134+ ) : AwsLambdaEventInvokeConfig [ ] => {
135+ return (
136+ eventInvokeConfigs ?. map ( e => ( {
137+ id : generateUniqueId ( {
138+ arn,
139+ ...e ,
140+ } ) ,
141+ lastModified : e . LastModified ?. toISOString ( ) ,
142+ functionArn : e . FunctionArn ,
143+ maximumRetryAttempts : e . MaximumRetryAttempts ,
144+ maximumEventAgeInSeconds : e . MaximumEventAgeInSeconds ,
145+ destinationConfig : {
146+ id : generateUniqueId ( {
147+ arn,
148+ ...e . DestinationConfig ,
149+
150+ } ) ,
151+ OnSuccess : e . DestinationConfig ?. OnSuccess ?. Destination ,
152+ OnFailure : e . DestinationConfig ?. OnFailure ?. Destination
153+ }
154+ } ) ) || [ ]
155+ )
156+ }
157+
158+ const formatLayers = (
159+ layers ?: Layer [ ]
160+ ) : AwsLambdaLayerVersion [ ] => {
161+ return (
162+ layers ?. map ( l => {
163+ const arnParts = l . Arn ?. split ( ':' )
164+ // get layer name from arn:aws:lambda:_REGION_:_ACCOUNT_ID_:layer:_LAYER_NAME_:_LAYER_VERSION_
165+ const layerName = arnParts [ arnParts . length - 2 ]
166+ return ( {
167+ id : generateUniqueId ( {
168+ arn,
169+ ...l ,
170+ } ) ,
171+ arn : l . Arn ,
172+ name : layerName ,
173+ codeSize : l . CodeSize ,
174+ signingProfileVersionArn : l . SigningProfileVersionArn ,
175+ signingJobArn : l . SigningJobArn ,
176+ } )
177+ } ) || [ ]
178+ )
179+ }
180+
181+ const functionName = arn . split ( ':' ) . pop ( )
182+ const functionPolicy = formatIamJsonPolicy ( policy )
183+ const policyStatementIds = functionPolicy ?. statement ?. map ( s => s . sid ) ?? [ ]
184+
71185 return {
72186 accountId : account ,
73187 arn,
74188 region,
189+ name : functionName ,
75190 description,
76191 handler,
77192 id : arn ,
@@ -88,7 +203,11 @@ export default ({
88203 vpcConfig : formattedVpcConfig ,
89204 policyRevisionId,
90205 rawPolicy : policy ,
91- policy : formatIamJsonPolicy ( policy ) ,
206+ policy : functionPolicy ,
207+ policyStatementIds,
92208 tags : formatTagsFromMap ( Tags ) ,
209+ eventSourceMappings : formatEventSourceMappings ( eventSourceMappings ) ,
210+ eventInvokeConfigs : formatEventInvokeConfigs ( eventInvokeConfigs ) ,
211+ layers : formatLayers ( layers )
93212 }
94213}
0 commit comments