Skip to content

Commit 2a0359d

Browse files
committed
Adds optional waf field for setting up Web Application Firewall on Cloudfront
1 parent 3e3a8c2 commit 2a0359d

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ custom:
4444
apiCloudFront:
4545
domain: my-custom-domain.com
4646
certificate: arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444
47+
waf: 00000000-0000-0000-0000-000000000000
4748
logging:
4849
bucket: my-bucket.s3.amazonaws.com
4950
prefix: my-prefix

index.js

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ServerlessApiCloudFrontPlugin {
5959
this.prepareOrigins(distributionConfig);
6060
this.prepareComment(distributionConfig);
6161
this.prepareCertificate(distributionConfig);
62+
this.prepareWaf(distributionConfig);
6263
}
6364

6465
prepareLogging(distributionConfig) {
@@ -107,6 +108,16 @@ class ServerlessApiCloudFrontPlugin {
107108
}
108109
}
109110

111+
prepareWaf(distributionConfig) {
112+
const waf = this.getConfig('waf', null);
113+
114+
if (waf !== null) {
115+
distributionConfig.WebACLId = waf;
116+
} else {
117+
delete distributionConfig.WebACLId;
118+
}
119+
}
120+
110121
getConfig(field, defaultValue) {
111122
return _.get(this.serverless, `service.custom.apiCloudFront.${field}`, defaultValue)
112123
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-api-cloudfront",
3-
"version": "0.9.1",
3+
"version": "0.9.2",
44
"engines": {
55
"node": ">=4.0"
66
},

resources.yml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Resources:
5454
IncludeCookies: 'false'
5555
Bucket: ''
5656
Prefix: ''
57+
WebACLId: waf-id
5758

5859
Outputs:
5960
ApiDistribution:

0 commit comments

Comments
 (0)