-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
Summary:
The webAclId property in the CDK cloudfront.Distribution construct is documented to accept an ID, but when associating an AWS WAFv2 Web ACL, it actually requires the full Amazon Resource Name (ARN) of the Web ACL to succeed. Passing only the ID results in a CloudFormation deployment failure with a misleading error.
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
Expected Behavior / Suggestions
- Ideal Solution: Since the property is named
webAclId, the CDK construct should internally handle whether an ID or an ARN is provided, mapping it to the correct format required by the underlying CloudFormation resource (which expects the ARN for WAFv2). - Alternative Solution (Documentation Fix): At minimum, the documentation for the
webAclIdproperty should be updated to clearly state that for WAFv2, the ARN must be provided.
Current Behavior
Issue
When attempting to associate an AWS WAFv2 Web ACL with a cloudfront.Distribution using the webAclId property, passing only the Web ACL ID (e.g., a1b2c3d4-5678-90ab-cdef-EXAMPLE11111) leads to a deployment failure with the following error:
Resource handler returned message: "Invalid request provided: Web ACL is not accessible by the requester." (RequestToken: ..., HandlerErrorCode: InvalidRequest)
The error is misleading as it suggests an IAM issue, but the underlying CloudFormation resource expects the full ARN for WAFv2 Web ACLs.
Reproduction Steps
Reproduction Steps
- Create an AWS WAFv2 Web ACL in the N. Virginia (
us-east-1) region with scopeCLOUDFRONT. - In a CDK stack, create a
cloudfront.Distribution. - Attempt to pass only the Web ACL ID (not the full ARN) to the
webAclIdproperty of theDistributionconstruct. - Deploy the stack using
cdk deploy.
Possible Solution
Workaround
The deployment succeeds when the full ARN of the WAFv2 Web ACL is provided instead of the ID:
// Example of a successful deployment using ARN
const webAclArn = 'arn:aws:wafv2:us-east-1:123456789012:global/webacl/MyWebACL/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111';
new cloudfront.Distribution(this, 'MyDistribution', {
// ... other properties
webAclId: webAclArn, // Passing the ARN works
});Additional Information/Context
What did I use to get this result?
- CDK CLI Version: (Please insert your CDK version, e.g.,
2.1033.0,) - AWS CDK Packages Used:
aws-cdk-lib/aws-cloudfront,aws-cdk-lib/aws-wafv2 - Language (A specific version of the language if applicable): TypeScript/Node.js
AWS CDK Library version (aws-cdk-lib)
2.231.0
AWS CDK CLI version
2.1033.0
Node.js Version
22.17.1
OS
mac
Language
TypeScript
Language Version
5.9.3
Other information
No response