Skip to content

Commit e4a5d58

Browse files
authored
Merge pull request #2 from serverless-operations/allowdeploy
Add validStages feature
2 parents 1485816 + 5d6a2d8 commit e4a5d58

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
```

index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)