Skip to content
GitHubXDiscord

WebACLAssociation

The WebACLAssociation resource allows you to associate a WebACL with a specified resource in AWS WAFRegional. This is essential for protecting your web applications from common web exploits and vulnerabilities. For more information, refer to the AWS WAFRegional WebACLAssociations documentation.

Create a basic WebACLAssociation with the required properties.

import AWS from "alchemy/aws/control";
const webACLAssociation = await AWS.WAFRegional.WebACLAssociation("basicWebACLAssociation", {
ResourceArn: "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188",
WebACLId: "waf-12345678",
adopt: true // Optional: Adopt existing resource if it already exists
});

Configure a WebACLAssociation with additional properties for enhanced management.

import AWS from "alchemy/aws/control";
const advancedWebACLAssociation = await AWS.WAFRegional.WebACLAssociation("advancedWebACLAssociation", {
ResourceArn: "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0",
WebACLId: "waf-87654321",
adopt: true // Optional: Adopt existing resource if it already exists
});

This example demonstrates how to update an existing WebACLAssociation by changing the associated WebACL.

import AWS from "alchemy/aws/control";
const updatedWebACLAssociation = await AWS.WAFRegional.WebACLAssociation("updateWebACLAssociation", {
ResourceArn: "arn:aws:s3:::my-bucket",
WebACLId: "waf-23456789",
adopt: false // Optional: Do not adopt existing resource
});

This example shows how to associate a WebACL with an API Gateway.

import AWS from "alchemy/aws/control";
const apiGatewayWebACLAssociation = await AWS.WAFRegional.WebACLAssociation("apiGatewayWebACLAssociation", {
ResourceArn: "arn:aws:apigateway:us-west-2::/restapis/abcdef1234/resources/xyz",
WebACLId: "waf-34567890",
adopt: true // Optional: Adopt existing resource if it already exists
});