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 11[ ![ 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 -->
22[ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-70-orange.svg?style=flat-square )] ( #contributors- )
3+
34<!-- ALL-CONTRIBUTORS-BADGE:END -->
45
56Deploy [ 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`
3738
3839``` yaml
3940plugins :
40- - serverless-appsync-plugin
41+ - serverless-appsync-plugin
4142` ` `
4243
4344Add the following config to the custom section of ` serverless.yml` and update it accordingly to your needs
@@ -262,6 +263,7 @@ custom:
262263 xrayEnabled : true # Bool, Optional. Enable X-Ray. disabled by default.
263264 wafConfig :
264265 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.
265267 name : AppSyncWaf
266268 defaultAction : Allow # or Block. Defaults to Allow
267269 description : ' My AppSync Waf rules'
Original file line number Diff line number Diff line change @@ -1449,6 +1449,23 @@ Object {
14491449}
14501450` ;
14511451
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+
14521469exports [` 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."` ;
14531470
14541471exports [` 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', () => {
21142114 expect ( tags [ 0 ] . Key ) . toBe ( 'testKey' ) ;
21152115 expect ( tags [ 0 ] . Value ) . toBe ( 'testValue' ) ;
21162116 } ) ;
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+ } ) ;
21172128} ) ;
Original file line number Diff line number Diff line change @@ -1434,10 +1434,23 @@ class ServerlessAppsyncPlugin {
14341434 return { } ;
14351435 }
14361436
1437- const Name = wafConfig . name || `${ apiConfig . name } Waf` ;
14381437 const apiLogicalId = this . getLogicalId ( apiConfig , RESOURCE_API ) ;
1439- const wafLogicalId = this . getLogicalId ( apiConfig , RESOURCE_WAF ) ;
14401438 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 ) ;
14411454 const defaultAction = wafConfig . defaultAction || 'Allow' ;
14421455
14431456 return {
You can’t perform that action at this time.
0 commit comments