@@ -26,36 +26,39 @@ class ServerlessLambdaEdgePreExistingCloudFront {
26
26
27
27
for ( let idx = 0 ; idx < events . length ; idx += 1 ) {
28
28
const event = events [ idx ]
29
- const functionArn = await this . getlatestVersionLambdaArn ( functionObj . name )
30
- const config = await this . provider . request ( 'CloudFront' , 'getDistribution' , {
31
- Id : event . preExistingCloudFront . distributionId
32
- } )
33
29
34
- if ( event . preExistingCloudFront . pathPattern === '*' ) {
35
- config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations = await this . associateFunction (
36
- config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations ,
37
- event ,
38
- functionObj . name ,
39
- functionArn
40
- )
41
- } else {
42
- config . DistributionConfig . CacheBehaviors = await this . associateNonDefaultCacheBehaviors (
43
- config . DistributionConfig . CacheBehaviors ,
44
- event ,
45
- functionObj . name ,
46
- functionArn
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.`
47
54
)
55
+
56
+ await this . provider . request ( 'CloudFront' , 'updateDistribution' , {
57
+ Id : event . preExistingCloudFront . distributionId ,
58
+ IfMatch : config . ETag ,
59
+ DistributionConfig : config . DistributionConfig
60
+ } )
48
61
}
49
-
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' , {
55
- Id : event . preExistingCloudFront . distributionId ,
56
- IfMatch : config . ETag ,
57
- DistributionConfig : config . DistributionConfig
58
- } )
59
62
}
60
63
} )
61
64
} , Promise . resolve ( ) )
@@ -85,9 +88,10 @@ class ServerlessLambdaEdgePreExistingCloudFront {
85
88
distributionId : { type : 'string' } ,
86
89
eventType : { type : 'string' } ,
87
90
pathPattern : { type : 'string' } ,
88
- includeBody : { type : 'boolean' }
91
+ includeBody : { type : 'boolean' } ,
92
+ stage : { type : 'string' }
89
93
} ,
90
- required : [ 'distributionId' , 'eventType' , 'pathPattern' , 'includeBody' ]
94
+ required : [ 'distributionId' , 'eventType' , 'pathPattern' , 'includeBody' , 'stage' ]
91
95
} )
92
96
}
93
97
}
0 commit comments