File tree Expand file tree Collapse file tree 4 files changed +46
-3
lines changed Expand file tree Collapse file tree 4 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 1
1
[ ![ Tests] ( https://github.com/sid88in/serverless-appsync-plugin/workflows/Tests/badge.svg )] ( https://github.com/sid88in/serverless-appsync-plugin/actions?query=workflow%3ATests ) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
2
2
[ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-70-orange.svg?style=flat-square )] ( #contributors- )
3
+
3
4
<!-- ALL-CONTRIBUTORS-BADGE:END -->
4
5
5
6
Deploy [ AppSync] ( https://aws.amazon.com/appsync ) API's in minutes using this [ Serverless] ( https://www.serverless.com/ ) plugin.
@@ -37,7 +38,7 @@ Add `serverless-appsync-plugin` to the plugins section of `serverless.yml`
37
38
38
39
``` yaml
39
40
plugins :
40
- - serverless-appsync-plugin
41
+ - serverless-appsync-plugin
41
42
` ` `
42
43
43
44
Add the following config to the custom section of ` serverless.yml` and update it accordingly to your needs
@@ -262,6 +263,7 @@ custom:
262
263
xrayEnabled : true # Bool, Optional. Enable X-Ray. disabled by default.
263
264
wafConfig :
264
265
enabled : true
266
+ arn : ' arn:aws:waf-regional:{REGION}:{ACCOUNT_ID}:rule/{RULE_ID}' # The arn for your WAF. Remaining WAF config options are ignored if arn is provided.
265
267
name : AppSyncWaf
266
268
defaultAction : Allow # or Block. Defaults to Allow
267
269
description : ' My AppSync Waf rules'
Original file line number Diff line number Diff line change @@ -1449,6 +1449,23 @@ Object {
1449
1449
}
1450
1450
` ;
1451
1451
1452
+ exports [` WAF should generate the WAF association and not the config 1` ] = `
1453
+ Object {
1454
+ " GraphQlWafAssoc" : Object {
1455
+ " Properties" : Object {
1456
+ " ResourceArn" : Object {
1457
+ " Fn::GetAtt" : Array [
1458
+ " GraphQlApi" ,
1459
+ " Arn" ,
1460
+ ],
1461
+ },
1462
+ " WebACLArn" : " arn:aws:waf-regional:us-east-1:123456789012:rule/123-456-7890" ,
1463
+ },
1464
+ " Type" : " AWS::WAFv2::WebACLAssociation" ,
1465
+ },
1466
+ }
1467
+ ` ;
1468
+
1452
1469
exports [` api keys should fail with a date > 1 year 1` ] = ` "Api Key MyKey must be valid for a minimum of 1 day and a maximum of 365 days."` ;
1453
1470
1454
1471
exports [` api keys should fail with invalid duration 1` ] = ` "Could not parse foobar as a valid duration"` ;
Original file line number Diff line number Diff line change @@ -2114,4 +2114,15 @@ describe('WAF', () => {
2114
2114
expect ( tags [ 0 ] . Key ) . toBe ( 'testKey' ) ;
2115
2115
expect ( tags [ 0 ] . Value ) . toBe ( 'testValue' ) ;
2116
2116
} ) ;
2117
+
2118
+ it ( 'should generate the WAF association and not the config' , ( ) => {
2119
+ const apiConfig = {
2120
+ ...config ,
2121
+ wafConfig : {
2122
+ enabled : true ,
2123
+ arn : 'arn:aws:waf-regional:us-east-1:123456789012:rule/123-456-7890' ,
2124
+ } ,
2125
+ } ;
2126
+ expect ( plugin . getWafResources ( apiConfig ) ) . toMatchSnapshot ( ) ;
2127
+ } ) ;
2117
2128
} ) ;
Original file line number Diff line number Diff line change @@ -1434,10 +1434,23 @@ class ServerlessAppsyncPlugin {
1434
1434
return { } ;
1435
1435
}
1436
1436
1437
- const Name = wafConfig . name || `${ apiConfig . name } Waf` ;
1438
1437
const apiLogicalId = this . getLogicalId ( apiConfig , RESOURCE_API ) ;
1439
- const wafLogicalId = this . getLogicalId ( apiConfig , RESOURCE_WAF ) ;
1440
1438
const wafAssocLogicalId = this . getLogicalId ( apiConfig , RESOURCE_WAF_ASSOC ) ;
1439
+
1440
+ if ( wafConfig . arn ) {
1441
+ return {
1442
+ [ wafAssocLogicalId ] : {
1443
+ Type : 'AWS::WAFv2::WebACLAssociation' ,
1444
+ Properties : {
1445
+ ResourceArn : { 'Fn::GetAtt' : [ apiLogicalId , 'Arn' ] } ,
1446
+ WebACLArn : wafConfig . arn ,
1447
+ } ,
1448
+ } ,
1449
+ } ;
1450
+ }
1451
+
1452
+ const Name = wafConfig . name || `${ apiConfig . name } Waf` ;
1453
+ const wafLogicalId = this . getLogicalId ( apiConfig , RESOURCE_WAF ) ;
1441
1454
const defaultAction = wafConfig . defaultAction || 'Allow' ;
1442
1455
1443
1456
return {
You can’t perform that action at this time.
0 commit comments