File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -32,3 +32,13 @@ Run deploy
3232` ` `
3333$ serverless deploy
3434```
35+
36+ You can specify additional configurations a ` lambdaEdgePreExistingCloudFront ` value in the custom section of your serverless.yml file.
37+ A ` validStages ` value allows you to specify valid stage names for deploy Lambda@Edge.
38+
39+ ``` yaml
40+ lambdaEdgePreExistingCloudFront :
41+ validStages :
42+ - staging
43+ - production
44+ ` ` `
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class ServerlessLambdaEdgePreExistingCloudFront {
1515 const functionObj = this . serverless . service . getFunction ( functionName )
1616 if ( functionObj . events ) {
1717 functionObj . events . forEach ( async ( event ) => {
18- if ( event . preExistingCloudFront ) {
18+ if ( event . preExistingCloudFront && this . checkAllowedDeployStage ( ) ) {
1919 const functionArn = await this . getlatestVersionLambdaArn ( functionObj . name )
2020 const config = await this . provider . request ( 'CloudFront' , 'getDistribution' , {
2121 Id : event . preExistingCloudFront . distributionId
@@ -53,6 +53,23 @@ class ServerlessLambdaEdgePreExistingCloudFront {
5353 }
5454 }
5555
56+ checkAllowedDeployStage ( ) {
57+ if (
58+ this . serverless . service . custom &&
59+ this . serverless . service . custom . lambdaEdgePreExistingCloudFront &&
60+ this . serverless . service . custom . lambdaEdgePreExistingCloudFront . validStages
61+ ) {
62+ if (
63+ this . serverless . service . custom . lambdaEdgePreExistingCloudFront . validStages . indexOf (
64+ this . stage
65+ ) < 0
66+ ) {
67+ return false
68+ }
69+ }
70+ return true
71+ }
72+
5673 async associateNonDefaultCacheBehaviors ( cacheBehaviors , event , functionName , functionArn ) {
5774 for ( let i = 0 ; i < cacheBehaviors . Items . length ; i ++ ) {
5875 if ( event . preExistingCloudFront . pathPattern === cacheBehaviors . Items [ i ] . PathPattern ) {
You can’t perform that action at this time.
0 commit comments