1. Packages
  2. AWS
  3. API Docs
  4. wafv2
  5. WebAclAssociation
Viewing docs for AWS v5.43.0 (Older version)
published on Tuesday, Mar 10, 2026 by Pulumi
aws logo
Viewing docs for AWS v5.43.0 (Older version)
published on Tuesday, Mar 10, 2026 by Pulumi

    Creates a WAFv2 Web ACL Association.

    NOTE on associating a WAFv2 Web ACL with a Cloudfront distribution: Do not use this resource to associate a WAFv2 Web ACL with a Cloudfront Distribution. The AWS API call backing this resource notes that you should use the web_acl_id property on the cloudfront_distribution instead.

    Example Usage

    using System.Collections.Generic;
    using System.Linq;
    using System.Security.Cryptography;
    using System.Text;
    using System.Text.Json;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    	private static string ComputeSHA1(string input) {
    		return BitConverter.ToString(
    			SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(input))
    		).Replace("-","").ToLowerInvariant());
    	}
    
    return await Deployment.RunAsync(() => 
    {
        var exampleRestApi = new Aws.ApiGateway.RestApi("exampleRestApi", new()
        {
            Body = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["openapi"] = "3.0.1",
                ["info"] = new Dictionary<string, object?>
                {
                    ["title"] = "example",
                    ["version"] = "1.0",
                },
                ["paths"] = new Dictionary<string, object?>
                {
                    ["/path1"] = new Dictionary<string, object?>
                    {
                        ["get"] = new Dictionary<string, object?>
                        {
                            ["x-amazon-apigateway-integration"] = new Dictionary<string, object?>
                            {
                                ["httpMethod"] = "GET",
                                ["payloadFormatVersion"] = "1.0",
                                ["type"] = "HTTP_PROXY",
                                ["uri"] = "https://ip-ranges.amazonaws.com/ip-ranges.json",
                            },
                        },
                    },
                },
            }),
        });
    
        var exampleDeployment = new Aws.ApiGateway.Deployment("exampleDeployment", new()
        {
            RestApi = exampleRestApi.Id,
            Triggers = 
            {
                { "redeployment", exampleRestApi.Body.Apply(body => JsonSerializer.Serialize(body)).Apply(toJSON => ComputeSHA1(toJSON)) },
            },
        });
    
        var exampleStage = new Aws.ApiGateway.Stage("exampleStage", new()
        {
            Deployment = exampleDeployment.Id,
            RestApi = exampleRestApi.Id,
            StageName = "example",
        });
    
        var exampleWebAcl = new Aws.WafV2.WebAcl("exampleWebAcl", new()
        {
            Scope = "REGIONAL",
            DefaultAction = new Aws.WafV2.Inputs.WebAclDefaultActionArgs
            {
                Allow = null,
            },
            VisibilityConfig = new Aws.WafV2.Inputs.WebAclVisibilityConfigArgs
            {
                CloudwatchMetricsEnabled = false,
                MetricName = "friendly-metric-name",
                SampledRequestsEnabled = false,
            },
        });
    
        var exampleWebAclAssociation = new Aws.WafV2.WebAclAssociation("exampleWebAclAssociation", new()
        {
            ResourceArn = exampleStage.Arn,
            WebAclArn = exampleWebAcl.Arn,
        });
    
    });
    
    package main
    
    import (
    	"crypto/sha1"
    	"encoding/json"
    	"fmt"
    
    	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/apigateway"
    	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/wafv2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func sha1Hash(input string) string {
    	hash := sha1.Sum([]byte(input))
    	return hex.EncodeToString(hash[:])
    }
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"openapi": "3.0.1",
    			"info": map[string]interface{}{
    				"title":   "example",
    				"version": "1.0",
    			},
    			"paths": map[string]interface{}{
    				"/path1": map[string]interface{}{
    					"get": map[string]interface{}{
    						"x-amazon-apigateway-integration": map[string]interface{}{
    							"httpMethod":           "GET",
    							"payloadFormatVersion": "1.0",
    							"type":                 "HTTP_PROXY",
    							"uri":                  "https://ip-ranges.amazonaws.com/ip-ranges.json",
    						},
    					},
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		exampleRestApi, err := apigateway.NewRestApi(ctx, "exampleRestApi", &apigateway.RestApiArgs{
    			Body: pulumi.String(json0),
    		})
    		if err != nil {
    			return err
    		}
    		exampleDeployment, err := apigateway.NewDeployment(ctx, "exampleDeployment", &apigateway.DeploymentArgs{
    			RestApi: exampleRestApi.ID(),
    			Triggers: pulumi.StringMap{
    				"redeployment": exampleRestApi.Body.ApplyT(func(body *string) (pulumi.String, error) {
    					var _zero pulumi.String
    					tmpJSON1, err := json.Marshal(body)
    					if err != nil {
    						return _zero, err
    					}
    					json1 := string(tmpJSON1)
    					return pulumi.String(json1), nil
    				}).(pulumi.StringOutput).ApplyT(func(toJSON string) (pulumi.String, error) {
    					return pulumi.String(sha1Hash(toJSON)), nil
    				}).(pulumi.StringOutput),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		exampleStage, err := apigateway.NewStage(ctx, "exampleStage", &apigateway.StageArgs{
    			Deployment: exampleDeployment.ID(),
    			RestApi:    exampleRestApi.ID(),
    			StageName:  pulumi.String("example"),
    		})
    		if err != nil {
    			return err
    		}
    		exampleWebAcl, err := wafv2.NewWebAcl(ctx, "exampleWebAcl", &wafv2.WebAclArgs{
    			Scope: pulumi.String("REGIONAL"),
    			DefaultAction: &wafv2.WebAclDefaultActionArgs{
    				Allow: nil,
    			},
    			VisibilityConfig: &wafv2.WebAclVisibilityConfigArgs{
    				CloudwatchMetricsEnabled: pulumi.Bool(false),
    				MetricName:               pulumi.String("friendly-metric-name"),
    				SampledRequestsEnabled:   pulumi.Bool(false),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = wafv2.NewWebAclAssociation(ctx, "exampleWebAclAssociation", &wafv2.WebAclAssociationArgs{
    			ResourceArn: exampleStage.Arn,
    			WebAclArn:   exampleWebAcl.Arn,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.apigateway.RestApi;
    import com.pulumi.aws.apigateway.RestApiArgs;
    import com.pulumi.aws.apigateway.Deployment;
    import com.pulumi.aws.apigateway.DeploymentArgs;
    import com.pulumi.aws.apigateway.Stage;
    import com.pulumi.aws.apigateway.StageArgs;
    import com.pulumi.aws.wafv2.WebAcl;
    import com.pulumi.aws.wafv2.WebAclArgs;
    import com.pulumi.aws.wafv2.inputs.WebAclDefaultActionArgs;
    import com.pulumi.aws.wafv2.inputs.WebAclDefaultActionAllowArgs;
    import com.pulumi.aws.wafv2.inputs.WebAclVisibilityConfigArgs;
    import com.pulumi.aws.wafv2.WebAclAssociation;
    import com.pulumi.aws.wafv2.WebAclAssociationArgs;
    import static com.pulumi.codegen.internal.Serialization.*;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var exampleRestApi = new RestApi("exampleRestApi", RestApiArgs.builder()        
                .body(serializeJson(
                    jsonObject(
                        jsonProperty("openapi", "3.0.1"),
                        jsonProperty("info", jsonObject(
                            jsonProperty("title", "example"),
                            jsonProperty("version", "1.0")
                        )),
                        jsonProperty("paths", jsonObject(
                            jsonProperty("/path1", jsonObject(
                                jsonProperty("get", jsonObject(
                                    jsonProperty("x-amazon-apigateway-integration", jsonObject(
                                        jsonProperty("httpMethod", "GET"),
                                        jsonProperty("payloadFormatVersion", "1.0"),
                                        jsonProperty("type", "HTTP_PROXY"),
                                        jsonProperty("uri", "https://ip-ranges.amazonaws.com/ip-ranges.json")
                                    ))
                                ))
                            ))
                        ))
                    )))
                .build());
    
            var exampleDeployment = new Deployment("exampleDeployment", DeploymentArgs.builder()        
                .restApi(exampleRestApi.id())
                .triggers(Map.of("redeployment", exampleRestApi.body().applyValue(body -> serializeJson(
                    body)).applyValue(toJSON -> computeSHA1(toJSON))))
                .build());
    
            var exampleStage = new Stage("exampleStage", StageArgs.builder()        
                .deployment(exampleDeployment.id())
                .restApi(exampleRestApi.id())
                .stageName("example")
                .build());
    
            var exampleWebAcl = new WebAcl("exampleWebAcl", WebAclArgs.builder()        
                .scope("REGIONAL")
                .defaultAction(WebAclDefaultActionArgs.builder()
                    .allow()
                    .build())
                .visibilityConfig(WebAclVisibilityConfigArgs.builder()
                    .cloudwatchMetricsEnabled(false)
                    .metricName("friendly-metric-name")
                    .sampledRequestsEnabled(false)
                    .build())
                .build());
    
            var exampleWebAclAssociation = new WebAclAssociation("exampleWebAclAssociation", WebAclAssociationArgs.builder()        
                .resourceArn(exampleStage.arn())
                .webAclArn(exampleWebAcl.arn())
                .build());
    
        }
    }
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as crypto from "crypto";
    
    const exampleRestApi = new aws.apigateway.RestApi("exampleRestApi", {body: JSON.stringify({
        openapi: "3.0.1",
        info: {
            title: "example",
            version: "1.0",
        },
        paths: {
            "/path1": {
                get: {
                    "x-amazon-apigateway-integration": {
                        httpMethod: "GET",
                        payloadFormatVersion: "1.0",
                        type: "HTTP_PROXY",
                        uri: "https://ip-ranges.amazonaws.com/ip-ranges.json",
                    },
                },
            },
        },
    })});
    const exampleDeployment = new aws.apigateway.Deployment("exampleDeployment", {
        restApi: exampleRestApi.id,
        triggers: {
            redeployment: exampleRestApi.body.apply(body => JSON.stringify(body)).apply(toJSON => crypto.createHash('sha1').update(toJSON).digest('hex')),
        },
    });
    const exampleStage = new aws.apigateway.Stage("exampleStage", {
        deployment: exampleDeployment.id,
        restApi: exampleRestApi.id,
        stageName: "example",
    });
    const exampleWebAcl = new aws.wafv2.WebAcl("exampleWebAcl", {
        scope: "REGIONAL",
        defaultAction: {
            allow: {},
        },
        visibilityConfig: {
            cloudwatchMetricsEnabled: false,
            metricName: "friendly-metric-name",
            sampledRequestsEnabled: false,
        },
    });
    const exampleWebAclAssociation = new aws.wafv2.WebAclAssociation("exampleWebAclAssociation", {
        resourceArn: exampleStage.arn,
        webAclArn: exampleWebAcl.arn,
    });
    
    import pulumi
    import hashlib
    import json
    import pulumi_aws as aws
    
    example_rest_api = aws.apigateway.RestApi("exampleRestApi", body=json.dumps({
        "openapi": "3.0.1",
        "info": {
            "title": "example",
            "version": "1.0",
        },
        "paths": {
            "/path1": {
                "get": {
                    "x-amazon-apigateway-integration": {
                        "httpMethod": "GET",
                        "payloadFormatVersion": "1.0",
                        "type": "HTTP_PROXY",
                        "uri": "https://ip-ranges.amazonaws.com/ip-ranges.json",
                    },
                },
            },
        },
    }))
    example_deployment = aws.apigateway.Deployment("exampleDeployment",
        rest_api=example_rest_api.id,
        triggers={
            "redeployment": example_rest_api.body.apply(lambda body: json.dumps(body)).apply(lambda to_json: hashlib.sha1(to_json.encode()).hexdigest()),
        })
    example_stage = aws.apigateway.Stage("exampleStage",
        deployment=example_deployment.id,
        rest_api=example_rest_api.id,
        stage_name="example")
    example_web_acl = aws.wafv2.WebAcl("exampleWebAcl",
        scope="REGIONAL",
        default_action=aws.wafv2.WebAclDefaultActionArgs(
            allow=aws.wafv2.WebAclDefaultActionAllowArgs(),
        ),
        visibility_config=aws.wafv2.WebAclVisibilityConfigArgs(
            cloudwatch_metrics_enabled=False,
            metric_name="friendly-metric-name",
            sampled_requests_enabled=False,
        ))
    example_web_acl_association = aws.wafv2.WebAclAssociation("exampleWebAclAssociation",
        resource_arn=example_stage.arn,
        web_acl_arn=example_web_acl.arn)
    

    Example coming soon!

    Create WebAclAssociation Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new WebAclAssociation(name: string, args: WebAclAssociationArgs, opts?: CustomResourceOptions);
    @overload
    def WebAclAssociation(resource_name: str,
                          args: WebAclAssociationArgs,
                          opts: Optional[ResourceOptions] = None)
    
    @overload
    def WebAclAssociation(resource_name: str,
                          opts: Optional[ResourceOptions] = None,
                          resource_arn: Optional[str] = None,
                          web_acl_arn: Optional[str] = None)
    func NewWebAclAssociation(ctx *Context, name string, args WebAclAssociationArgs, opts ...ResourceOption) (*WebAclAssociation, error)
    public WebAclAssociation(string name, WebAclAssociationArgs args, CustomResourceOptions? opts = null)
    public WebAclAssociation(String name, WebAclAssociationArgs args)
    public WebAclAssociation(String name, WebAclAssociationArgs args, CustomResourceOptions options)
    
    type: aws:wafv2:WebAclAssociation
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args WebAclAssociationArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args WebAclAssociationArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args WebAclAssociationArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args WebAclAssociationArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args WebAclAssociationArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var awsWebAclAssociationResource = new Aws.WafV2.WebAclAssociation("awsWebAclAssociationResource", new()
    {
        ResourceArn = "string",
        WebAclArn = "string",
    });
    
    example, err := wafv2.NewWebAclAssociation(ctx, "awsWebAclAssociationResource", &wafv2.WebAclAssociationArgs{
    	ResourceArn: pulumi.String("string"),
    	WebAclArn:   pulumi.String("string"),
    })
    
    var awsWebAclAssociationResource = new com.pulumi.aws.wafv2.WebAclAssociation("awsWebAclAssociationResource", com.pulumi.aws.wafv2.WebAclAssociationArgs.builder()
        .resourceArn("string")
        .webAclArn("string")
        .build());
    
    aws_web_acl_association_resource = aws.wafv2.WebAclAssociation("awsWebAclAssociationResource",
        resource_arn="string",
        web_acl_arn="string")
    
    const awsWebAclAssociationResource = new aws.wafv2.WebAclAssociation("awsWebAclAssociationResource", {
        resourceArn: "string",
        webAclArn: "string",
    });
    
    type: aws:wafv2:WebAclAssociation
    properties:
        resourceArn: string
        webAclArn: string
    

    WebAclAssociation Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The WebAclAssociation resource accepts the following input properties:

    ResourceArn string
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    WebAclArn string
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    ResourceArn string
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    WebAclArn string
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    resourceArn String
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    webAclArn String
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    resourceArn string
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    webAclArn string
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    resource_arn str
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    web_acl_arn str
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    resourceArn String
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    webAclArn String
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the WebAclAssociation resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing WebAclAssociation Resource

    Get an existing WebAclAssociation resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: WebAclAssociationState, opts?: CustomResourceOptions): WebAclAssociation
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            resource_arn: Optional[str] = None,
            web_acl_arn: Optional[str] = None) -> WebAclAssociation
    func GetWebAclAssociation(ctx *Context, name string, id IDInput, state *WebAclAssociationState, opts ...ResourceOption) (*WebAclAssociation, error)
    public static WebAclAssociation Get(string name, Input<string> id, WebAclAssociationState? state, CustomResourceOptions? opts = null)
    public static WebAclAssociation get(String name, Output<String> id, WebAclAssociationState state, CustomResourceOptions options)
    resources:  _:    type: aws:wafv2:WebAclAssociation    get:      id: ${id}
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    ResourceArn string
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    WebAclArn string
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    ResourceArn string
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    WebAclArn string
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    resourceArn String
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    webAclArn String
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    resourceArn string
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    webAclArn string
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    resource_arn str
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    web_acl_arn str
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.
    resourceArn String
    The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool.
    webAclArn String
    The Amazon Resource Name (ARN) of the Web ACL that you want to associate with the resource.

    Import

    WAFv2 Web ACL Association can be imported using WEB_ACL_ARN,RESOURCE_ARN e.g.,

     $ pulumi import aws:wafv2/webAclAssociation:WebAclAssociation example arn:aws:wafv2:...7ce849ea,arn:aws:apigateway:...ages/name
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo
    Viewing docs for AWS v5.43.0 (Older version)
    published on Tuesday, Mar 10, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.