amazon-cognitoaws-cdkamazon-wafaws-userpools

How to add WAF to my cognito UserPool with cdk


I can't find examples or documentation about how to use cdk to attach a waf to a cognito userpool.


Solution

  • There is no API in Cognito Userpool. You will need to create CfnWebACLAssociation and provide the Userpool ARN for the resource ARN.

    https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_wafv2.CfnWebACLAssociation.html#resourcearn

    import { aws_wafv2 as wafv2 } from 'aws-cdk-lib';
    const cfnWebACLAssociation = new wafv2.CfnWebACLAssociation(this, 'MyCfnWebACLAssociation', {
      resourceArn: 'arn: *partition* :cognito-idp: *region* : *account-id* :userpool/ *user-pool-id*',
      webAclArn: 'webAclArn',
    });