@@ -27,38 +27,39 @@ class ServerlessLambdaEdgePreExistingCloudFront {
27
27
for ( let idx = 0 ; idx < events . length ; idx += 1 ) {
28
28
const event = events [ idx ]
29
29
30
- if ( event . preExistingCloudFront . stage == `${ serverless . service . provider . stage } ` ) {
31
- const functionArn = await this . getlatestVersionLambdaArn ( functionObj . name )
32
- const config = await this . provider . request ( 'CloudFront' , 'getDistribution' , {
33
- Id : event . preExistingCloudFront . distributionId
34
- } )
35
-
36
- if ( event . preExistingCloudFront . pathPattern === '*' ) {
37
- config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations = await this . associateFunction (
38
- config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations ,
39
- event ,
40
- functionObj . name ,
41
- functionArn
42
- )
43
- } else {
44
- config . DistributionConfig . CacheBehaviors = await this . associateNonDefaultCacheBehaviors (
45
- config . DistributionConfig . CacheBehaviors ,
46
- event ,
47
- functionObj . name ,
48
- functionArn
49
- )
50
- }
51
-
52
- this . serverless . cli . consoleLog (
53
- `${ functionArn } is associating to ${ event . preExistingCloudFront . distributionId } CloudFront Distribution. waiting for deployed status.`
30
+ if ( event . preExistingCloudFront . stage !== undefined &&
31
+ event . preExistingCloudFront . stage != `${ serverless . service . provider . stage } ` ) { continue }
32
+
33
+ const functionArn = await this . getlatestVersionLambdaArn ( functionObj . name )
34
+ const config = await this . provider . request ( 'CloudFront' , 'getDistribution' , {
35
+ Id : event . preExistingCloudFront . distributionId
36
+ } )
37
+
38
+ if ( event . preExistingCloudFront . pathPattern === '*' ) {
39
+ config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations = await this . associateFunction (
40
+ config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations ,
41
+ event ,
42
+ functionObj . name ,
43
+ functionArn
44
+ )
45
+ } else {
46
+ config . DistributionConfig . CacheBehaviors = await this . associateNonDefaultCacheBehaviors (
47
+ config . DistributionConfig . CacheBehaviors ,
48
+ event ,
49
+ functionObj . name ,
50
+ functionArn
54
51
)
55
-
56
- await this . provider . request ( 'CloudFront' , 'updateDistribution' , {
57
- Id : event . preExistingCloudFront . distributionId ,
58
- IfMatch : config . ETag ,
59
- DistributionConfig : config . DistributionConfig
60
- } )
61
52
}
53
+
54
+ this . serverless . cli . consoleLog (
55
+ `${ functionArn } is associating to ${ event . preExistingCloudFront . distributionId } CloudFront Distribution. waiting for deployed status.`
56
+ )
57
+
58
+ await this . provider . request ( 'CloudFront' , 'updateDistribution' , {
59
+ Id : event . preExistingCloudFront . distributionId ,
60
+ IfMatch : config . ETag ,
61
+ DistributionConfig : config . DistributionConfig
62
+ } )
62
63
}
63
64
} )
64
65
} , Promise . resolve ( ) )
@@ -88,10 +89,10 @@ class ServerlessLambdaEdgePreExistingCloudFront {
88
89
distributionId : { type : 'string' } ,
89
90
eventType : { type : 'string' } ,
90
91
pathPattern : { type : 'string' } ,
91
- includeBody : { type : 'boolean' } ,
92
+ includeBody : { type : 'boolean' } ,
92
93
stage : { type : 'string' }
93
94
} ,
94
- required : [ 'distributionId' , 'eventType' , 'pathPattern' , 'includeBody' , 'stage' ]
95
+ required : [ 'distributionId' , 'eventType' , 'pathPattern' , 'includeBody' ]
95
96
} )
96
97
}
97
98
}
0 commit comments