Cloudfront,ALB and API Gateway with Automated WAF
Project description
AWS WAF Solution
This CDK Construct modify and rebuild from Cloudfront with Automated WAF.
The solution use CDK construct to automatically deploy a set of AWS WAF rules design to filter common web-based attacks.Users can select from preconfigured protective features that define the rules included in an AWS WAF web access control list (web ACL). After the solution deploys, AWS WAF begins inspecting web requests to the user’s existing Amazon CloudFront distributions、Application Load Balancers、API Gateway, and blocks them when applicable.
What is difference
- The project is CDK Construct which is handy to integrate into your existing CDK project.
- Support count mode for testing WAF rule, see API.md.
- Support Application Load Balancers and API Gateway (The origin repository doesn't support ALB any more in next release, see issue )
- AWS Shield Advance is optional (The origin repository enforce to enable it)
Construct Props
Ref API Reference
CloudFront Usage
# Example automatically generated. See https://github.com/aws/jsii/issues/826
env_uSEast1 = {
"region": "us-east-1",
"account": process.env.CDK_DEFAULT_ACCOUNT
}
cdk.Stack(app, "TestStackAutomatedWafForCloudFront", env=env_uSEast1)
AutomatedWaf(stack_test1, "AutomatedWaf",
waf2_scope=Waf2ScopeOption.CLOUDFRONT,
resource_naming_prefix="CloudFront_ApiGW",
error_threshold=55,
request_threshold=300,
block_period=60,
log_level=LogLevel.DEBUG
)
Notice the WAF region must be us-east-1
for CloudFront.
After deploying, it need to do two things on AWS Management Console.
1. Attach Cloudfront to WAF.
Click add AWS Resources
Select existing CloudFront Distribution.
2. Set S3 bucket on CloudFront standand logging
Find S3 bucket name on CloudFormation output
Set CloudFront standard logging on CloudFront Settings
:warning: Log Prefix must be AWSLogs/
Application Load Balancers Usage
# Example automatically generated. See https://github.com/aws/jsii/issues/826
env = {
"region": process.env.CDK_DEFAULT_REGION,
"account": process.env.CDK_DEFAULT_ACCOUNT
}
cdk.Stack(app, "TestStackAutomatedWafForALB", env=env)
alb_arn = f"arn:aws:elasticloadbalancing:{cdk.Aws.REGION}:{cdk.Aws.ACCOUNT_ID}:loadbalancer/app/ApiNe-Alb16-2VIC9075YQEZ/db92cdc88d2e7c9d"
AutomatedWaf(stack_test2, "AutomatedWaf",
waf2_scope=Waf2ScopeOption.REGIONAL,
associated_resource_arn=alb_arn,
resource_naming_prefix="Alb_Api",
error_threshold=50,
request_threshold=300,
block_period=60,
log_level=LogLevel.DEBUG
)
After deploying, follow these steps on AWS Management Console. See below:
Find S3 bucket name on CloudFormation output
Click Edit Attributes
on Basic Configuration of Load Balancers
Enable Access logs and input S3 bucket
API Gateway Usage
# Example automatically generated. See https://github.com/aws/jsii/issues/826
env = {
"region": process.env.CDK_DEFAULT_REGION,
"account": process.env.CDK_DEFAULT_ACCOUNT
}
cdk.Stack(app, "TestStackAutomatedWafForApiGW", env=env)
#
# Ref Stage arn in https://docs.aws.amazon.com/apigateway/latest/developerguide/arn-format-reference.html
#
rest_api_arn = f"arn:aws:apigateway:{cdk.Aws.REGION}::/restapis/0j90w09yf9/stages/prod"
AutomatedWaf(stack_test3, "AutomatedWaf",
waf2_scope=Waf2ScopeOption.REGIONAL,
associated_resource_arn=rest_api_arn,
resource_naming_prefix="ApiGW",
error_threshold=50,
request_threshold=300,
block_period=60,
log_level=LogLevel.DEBUG
)
Troubleshooting
If deployment error, the cloudFormation Error event like this
Received response status [FAILED] from custom resource. Message returned: 'HttpFloodLambdaLogParser' (RequestId: b4e08ea2-fe0a-46f8-98aa-6f96d4558579)
If any custom resource deploy error like above, delete the stack and redeploy it that will pass.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ikala-cloud.aws-waf-solution-1.0.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 022ab0c121e1bab647579b00a7e212363cf388f877267e571dd56548c5a1a416 |
|
MD5 | a34a9479dc42aa6b71ec06be49f35442 |
|
BLAKE2b-256 | bf297001cd4796d092201aedac745163a1e8e0a76858d11eaad1b15ee1dd82ab |
Hashes for ikala_cloud.aws_waf_solution-1.0.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0b620cdade30324e74fc27f653f10f7fad614bd7ea38765bfc36e43b584dcbc |
|
MD5 | 9ccf0270b079a4f25b4a51b337867c06 |
|
BLAKE2b-256 | 936152ae346945464200cd996626c90e1aea98b1fdc90b708c09f14569bb6846 |