Skip to content
GitHubXDiscord

WebACL

The WebACL resource lets you manage AWS WAFRegional WebACLs for controlling access to your web applications.

Create a basic WebACL with required properties.

import AWS from "alchemy/aws/control";
const basicWebACL = await AWS.WAFRegional.WebACL("basicWebACL", {
name: "basic-web-acl",
metricName: "BasicWebACLMetric",
defaultAction: {
type: "ALLOW" // Default action to allow requests
}
});

Configure a WebACL with rules and an explicit default action.

const advancedWebACL = await AWS.WAFRegional.WebACL("advancedWebACL", {
name: "advanced-web-acl",
metricName: "AdvancedWebACLMetric",
defaultAction: {
type: "BLOCK" // Block requests by default
},
rules: [{
priority: 1,
ruleId: "exampleRuleId",
action: {
type: "ALLOW" // Allow requests matching the rule
},
type: "REGULAR"
}]
});

Demonstrate how to add multiple rules to a WebACL.

const multiRuleWebACL = await AWS.WAFRegional.WebACL("multiRuleWebACL", {
name: "multi-rule-web-acl",
metricName: "MultiRuleWebACLMetric",
defaultAction: {
type: "ALLOW"
},
rules: [
{
priority: 1,
ruleId: "exampleRuleId1",
action: {
type: "BLOCK"
},
type: "REGULAR"
},
{
priority: 2,
ruleId: "exampleRuleId2",
action: {
type: "ALLOW"
},
type: "REGULAR"
}
]
});

Use the adopt feature to manage an existing WebACL without failing if it already exists.

const adoptedWebACL = await AWS.WAFRegional.WebACL("adoptedWebACL", {
name: "adopted-web-acl",
metricName: "AdoptedWebACLMetric",
defaultAction: {
type: "ALLOW"
},
adopt: true // Adopt existing resource if it exists
});