@@ -11,11 +11,21 @@ class ServerlessLambdaEdgePreExistingCloudFront {
11
11
12
12
this . hooks = {
13
13
'after:aws:deploy:finalize:cleanup' : async ( ) => {
14
- this . serverless . service . getAllFunctions ( ) . forEach ( async ( functionName ) => {
15
- const functionObj = this . serverless . service . getFunction ( functionName )
16
- if ( functionObj . events ) {
17
- functionObj . events . forEach ( async ( event ) => {
18
- if ( event . preExistingCloudFront && this . checkAllowedDeployStage ( ) ) {
14
+ await this . serverless . service
15
+ . getAllFunctions ( )
16
+ . filter ( ( functionName ) => {
17
+ const functionObj = this . serverless . service . getFunction ( functionName )
18
+ return functionObj . events
19
+ } )
20
+ . reduce ( ( promiseOutput , functionName ) => {
21
+ return promiseOutput . then ( async ( ) => {
22
+ const functionObj = this . serverless . service . getFunction ( functionName )
23
+ const events = functionObj . events . filter (
24
+ ( event ) => event . preExistingCloudFront && this . checkAllowedDeployStage ( )
25
+ )
26
+
27
+ for ( let idx = 0 ; idx < events . length ; idx += 1 ) {
28
+ const event = events [ idx ]
19
29
const functionArn = await this . getlatestVersionLambdaArn ( functionObj . name )
20
30
const config = await this . provider . request ( 'CloudFront' , 'getDistribution' , {
21
31
Id : event . preExistingCloudFront . distributionId
@@ -37,18 +47,18 @@ class ServerlessLambdaEdgePreExistingCloudFront {
37
47
)
38
48
}
39
49
40
- this . provider . request ( 'CloudFront' , 'updateDistribution' , {
50
+ this . serverless . cli . consoleLog (
51
+ `${ functionArn } is associating to ${ event . preExistingCloudFront . distributionId } CloudFront Distribution. waiting for deployed status.`
52
+ )
53
+
54
+ await this . provider . request ( 'CloudFront' , 'updateDistribution' , {
41
55
Id : event . preExistingCloudFront . distributionId ,
42
56
IfMatch : config . ETag ,
43
57
DistributionConfig : config . DistributionConfig
44
58
} )
45
- this . serverless . cli . consoleLog (
46
- `${ functionArn } is associating to ${ event . preExistingCloudFront . distributionId } CloudFront Distribution. waiting for deployed status.`
47
- )
48
59
}
49
60
} )
50
- }
51
- } )
61
+ } , Promise . resolve ( ) )
52
62
}
53
63
}
54
64
}
0 commit comments