1. Registry
  2. Packages
  3. AWS
  4. API Docs
  5. lambdaweb
  6. ResourcePolicy
Viewing docs for AWS v7.55.0
published on Friday, Nov 13, 2026 by Pulumi
aws logo aws logo
Viewing docs for AWS v7.55.0
published on Friday, Nov 13, 2026 by Pulumi

    Manages a resource-based policy for an AWS Lambda Web function. A resource policy attaches an IAM policy document directly to the function ARN, letting you grant or restrict who may reach the function’s endpoints. A common use is locking a function down so that only a specific CloudFront distribution (or another trusted principal) can invoke it, keeping the raw endpoint domain from being reachable directly.

    Note: A resource policy attaches to the parent web function only. Endpoint and revision ARNs (.../endpoint/<name>, .../revision/<id>) are not accepted.

    Example Usage

    Basic Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const example = new aws.lambdaweb.ResourcePolicy("example", {
        resourceArn: exampleAwsLambdawebFunction.arn,
        policy: JSON.stringify({
            Version: "2012-10-17",
            Statement: [{
                Sid: "AllowCloudFront",
                Effect: "Allow",
                Principal: {
                    Service: "cloudfront.amazonaws.com",
                },
                Action: "lambda:InvokeWebFunctionEndpoint",
                Resource: exampleAwsLambdawebFunctionEndpoint.arn,
                Condition: {
                    StringEquals: {
                        "aws:SourceArn": exampleAwsCloudfrontDistribution.arn,
                    },
                },
            }],
        }),
    });
    
    import pulumi
    import json
    import pulumi_aws as aws
    
    example = aws.lambdaweb.ResourcePolicy("example",
        resource_arn=example_aws_lambdaweb_function["arn"],
        policy=json.dumps({
            "Version": "2012-10-17",
            "Statement": [{
                "Sid": "AllowCloudFront",
                "Effect": "Allow",
                "Principal": {
                    "Service": "cloudfront.amazonaws.com",
                },
                "Action": "lambda:InvokeWebFunctionEndpoint",
                "Resource": example_aws_lambdaweb_function_endpoint["arn"],
                "Condition": {
                    "StringEquals": {
                        "aws:SourceArn": example_aws_cloudfront_distribution["arn"],
                    },
                },
            }],
        }))
    
    package main
    
    import (
    	"encoding/json"
    
    	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/lambdaweb"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"Version": "2012-10-17",
    			"Statement": []map[string]interface{}{
    				map[string]interface{}{
    					"Sid":    "AllowCloudFront",
    					"Effect": "Allow",
    					"Principal": map[string]string{
    						"Service": "cloudfront.amazonaws.com",
    					},
    					"Action":   "lambda:InvokeWebFunctionEndpoint",
    					"Resource": exampleAwsLambdawebFunctionEndpoint.Arn,
    					"Condition": map[string]map[string]interface{}{
    						"StringEquals": map[string]interface{}{
    							"aws:SourceArn": exampleAwsCloudfrontDistribution.Arn,
    						},
    					},
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		_, err = lambdaweb.NewResourcePolicy(ctx, "example", &lambdaweb.ResourcePolicyArgs{
    			ResourceArn: pulumi.Any(exampleAwsLambdawebFunction.Arn),
    			Policy:      pulumi.String(json0),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var example = new Aws.LambdaWeb.ResourcePolicy("example", new()
        {
            ResourceArn = exampleAwsLambdawebFunction.Arn,
            Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["Version"] = "2012-10-17",
                ["Statement"] = new[]
                {
                    new Dictionary<string, object?>
                    {
                        ["Sid"] = "AllowCloudFront",
                        ["Effect"] = "Allow",
                        ["Principal"] = new Dictionary<string, object?>
                        {
                            ["Service"] = "cloudfront.amazonaws.com",
                        },
                        ["Action"] = "lambda:InvokeWebFunctionEndpoint",
                        ["Resource"] = exampleAwsLambdawebFunctionEndpoint.Arn,
                        ["Condition"] = new Dictionary<string, object?>
                        {
                            ["StringEquals"] = new Dictionary<string, object?>
                            {
                                ["aws:SourceArn"] = exampleAwsCloudfrontDistribution.Arn,
                            },
                        },
                    },
                },
            }),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.lambdaweb.ResourcePolicy;
    import com.pulumi.aws.lambdaweb.ResourcePolicyArgs;
    import static com.pulumi.codegen.internal.Serialization.*;
    import java.util.ArrayList;
    import java.util.Arrays;
    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 example = new ResourcePolicy("example", ResourcePolicyArgs.builder()
                .resourceArn(exampleAwsLambdawebFunction.get("arn"))
                .policy(serializeJson(
                    jsonObject(
                        jsonProperty("Version", "2012-10-17"),
                        jsonProperty("Statement", jsonArray(jsonObject(
                            jsonProperty("Sid", "AllowCloudFront"),
                            jsonProperty("Effect", "Allow"),
                            jsonProperty("Principal", jsonObject(
                                jsonProperty("Service", "cloudfront.amazonaws.com")
                            )),
                            jsonProperty("Action", "lambda:InvokeWebFunctionEndpoint"),
                            jsonProperty("Resource", exampleAwsLambdawebFunctionEndpoint.get("arn")),
                            jsonProperty("Condition", jsonObject(
                                jsonProperty("StringEquals", jsonObject(
                                    jsonProperty("aws:SourceArn", exampleAwsCloudfrontDistribution.get("arn"))
                                ))
                            ))
                        )))
                    )))
                .build());
    
        }
    }
    
    resources:
      example:
        type: aws:lambdaweb:ResourcePolicy
        properties:
          resourceArn: ${exampleAwsLambdawebFunction.arn}
          policy:
            fn::toJSON:
              Version: 2012-10-17
              Statement:
                - Sid: AllowCloudFront
                  Effect: Allow
                  Principal:
                    Service: cloudfront.amazonaws.com
                  Action: lambda:InvokeWebFunctionEndpoint
                  Resource: ${exampleAwsLambdawebFunctionEndpoint.arn}
                  Condition:
                    StringEquals:
                      aws:SourceArn: ${exampleAwsCloudfrontDistribution.arn}
    
    terraform {
      required_providers {
        aws = {
          source = "pulumi/aws"
        }
      }
    }
    
    resource "aws_lambdaweb_resource_policy" "example" {
      lifecycle {
        create_before_destroy = true
      }
      resource_arn = exampleAwsLambdawebFunction.arn
      policy = jsonencode({
        "Version" = "2012-10-17"
        "Statement" = [{
          "Sid"    = "AllowCloudFront"
          "Effect" = "Allow"
          "Principal" = {
            "Service" = "cloudfront.amazonaws.com"
          }
          "Action"   = "lambda:InvokeWebFunctionEndpoint"
          "Resource" = exampleAwsLambdawebFunctionEndpoint.arn
          "Condition" = {
            "StringEquals" = {
              "aws:SourceArn" = exampleAwsCloudfrontDistribution.arn
            }
          }
        }]
      })
    }
    

    Create ResourcePolicy Resource

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

    Constructor syntax

    new ResourcePolicy(name: string, args: ResourcePolicyArgs, opts?: CustomResourceOptions);
    @overload
    def ResourcePolicy(resource_name: str,
                       args: ResourcePolicyArgs,
                       opts: Optional[ResourceOptions] = None)
    
    @overload
    def ResourcePolicy(resource_name: str,
                       opts: Optional[ResourceOptions] = None,
                       policy: Optional[str] = None,
                       resource_arn: Optional[str] = None,
                       region: Optional[str] = None)
    func NewResourcePolicy(ctx *Context, name string, args ResourcePolicyArgs, opts ...ResourceOption) (*ResourcePolicy, error)
    public ResourcePolicy(string name, ResourcePolicyArgs args, CustomResourceOptions? opts = null)
    public ResourcePolicy(String name, ResourcePolicyArgs args)
    public ResourcePolicy(String name, ResourcePolicyArgs args, CustomResourceOptions options)
    
    type: aws:lambdaweb:ResourcePolicy
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    resource "aws_lambdaweb_resource_policy" "name" {
        # resource properties
    }

    Parameters

    name string
    The unique name of the resource.
    args ResourcePolicyArgs
    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 ResourcePolicyArgs
    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 ResourcePolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args ResourcePolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args ResourcePolicyArgs
    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 exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy = new Aws.LambdaWeb.ResourcePolicy("exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy", new()
    {
        Policy = "string",
        ResourceArn = "string",
        Region = "string",
    });
    
    example, err := lambdaweb.NewResourcePolicy(ctx, "exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy", &lambdaweb.ResourcePolicyArgs{
    	Policy:      pulumi.String("string"),
    	ResourceArn: pulumi.String("string"),
    	Region:      pulumi.String("string"),
    })
    
    resource "aws_lambdaweb_resource_policy" "exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy" {
      lifecycle {
        create_before_destroy = true
      }
      policy       = "string"
      resource_arn = "string"
      region       = "string"
    }
    
    var exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy = new com.pulumi.aws.lambdaweb.ResourcePolicy("exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy", com.pulumi.aws.lambdaweb.ResourcePolicyArgs.builder()
        .policy("string")
        .resourceArn("string")
        .region("string")
        .build());
    
    exampleresource_policy_resource_resource_from_lambdawebresource_policy = aws.lambdaweb.ResourcePolicy("exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy",
        policy="string",
        resource_arn="string",
        region="string")
    
    const exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy = new aws.lambdaweb.ResourcePolicy("exampleresourcePolicyResourceResourceFromLambdawebresourcePolicy", {
        policy: "string",
        resourceArn: "string",
        region: "string",
    });
    
    type: aws:lambdaweb:ResourcePolicy
    properties:
        policy: string
        region: string
        resourceArn: string
    

    ResourcePolicy 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 ResourcePolicy resource accepts the following input properties:

    Policy string
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    ResourceArn string
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    Region string
    Region where this resource is managed. Defaults to the provider's configured region.
    Policy string
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    ResourceArn string
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    Region string
    Region where this resource is managed. Defaults to the provider's configured region.
    policy string
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    resource_arn string
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    region string
    Region where this resource is managed. Defaults to the provider's configured region.
    policy String
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    resourceArn String
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    region String
    Region where this resource is managed. Defaults to the provider's configured region.
    policy string
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    resourceArn string
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    region string
    Region where this resource is managed. Defaults to the provider's configured region.
    policy str
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    resource_arn str
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    region str
    Region where this resource is managed. Defaults to the provider's configured region.
    policy String
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    resourceArn String
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    region String
    Region where this resource is managed. Defaults to the provider's configured region.

    Outputs

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

    Id string
    The provider-assigned unique ID for this managed resource.
    RevisionId string
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    Id string
    The provider-assigned unique ID for this managed resource.
    RevisionId string
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    id string
    The provider-assigned unique ID for this managed resource.
    revision_id string
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    id String
    The provider-assigned unique ID for this managed resource.
    revisionId String
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    id string
    The provider-assigned unique ID for this managed resource.
    revisionId string
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    id str
    The provider-assigned unique ID for this managed resource.
    revision_id str
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    id String
    The provider-assigned unique ID for this managed resource.
    revisionId String
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.

    Look up Existing ResourcePolicy Resource

    Get an existing ResourcePolicy 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?: ResourcePolicyState, opts?: CustomResourceOptions): ResourcePolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            policy: Optional[str] = None,
            region: Optional[str] = None,
            resource_arn: Optional[str] = None,
            revision_id: Optional[str] = None) -> ResourcePolicy
    func GetResourcePolicy(ctx *Context, name string, id IDInput, state *ResourcePolicyState, opts ...ResourceOption) (*ResourcePolicy, error)
    public static ResourcePolicy Get(string name, Input<string> id, ResourcePolicyState? state, CustomResourceOptions? opts = null)
    public static ResourcePolicy get(String name, Output<String> id, ResourcePolicyState state, CustomResourceOptions options)
    resources:  existingResourcePolicy:    type: aws:lambdaweb:ResourcePolicy    get:      id: ${id}
    import {
      to = aws_lambdaweb_resource_policy.example
      id = "${id}"
    }
    
    name string
    The unique name of the resulting resource.
    id Input<ID>
    The unique provider ID of the resource to look up.
    state ResourcePolicyState
    Known property values the provider needs, along with the ID, to find the resource. Usually not required.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resulting resource.
    id str
    The unique provider ID of the resource to look up.
    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 resulting resource.
    id IDInput
    The unique provider ID of the resource to look up.
    state ResourcePolicyState
    Known property values the provider needs, along with the ID, to find the resource. Usually not required.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resulting resource.
    id Input<string>
    The unique provider ID of the resource to look up.
    state ResourcePolicyState
    Known property values the provider needs, along with the ID, to find the resource. Usually not required.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resulting resource.
    id Output<String>
    The unique provider ID of the resource to look up.
    state ResourcePolicyState
    Known property values the provider needs, along with the ID, to find the resource. Usually not required.
    options CustomResourceOptions
    Bag of options to control resource's behavior.
    The following state arguments are supported:
    Policy string
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    Region string
    Region where this resource is managed. Defaults to the provider's configured region.
    ResourceArn string
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    RevisionId string
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    Policy string
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    Region string
    Region where this resource is managed. Defaults to the provider's configured region.
    ResourceArn string
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    RevisionId string
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    policy string
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    region string
    Region where this resource is managed. Defaults to the provider's configured region.
    resource_arn string
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    revision_id string
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    policy String
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    region String
    Region where this resource is managed. Defaults to the provider's configured region.
    resourceArn String
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    revisionId String
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    policy string
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    region string
    Region where this resource is managed. Defaults to the provider's configured region.
    resourceArn string
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    revisionId string
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    policy str
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    region str
    Region where this resource is managed. Defaults to the provider's configured region.
    resource_arn str
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    revision_id str
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.
    policy String
    Resource-based IAM policy document as JSON. Terraform normalizes the document, so equivalent policies that differ only in key order or whitespace do not produce spurious diffs.
    region String
    Region where this resource is managed. Defaults to the provider's configured region.
    resourceArn String
    ARN of the Lambda Web function the policy is attached to. Must be a web function ARN (arn:aws:lambda:<region>:<account>:web-function/<name>). Changing this forces a new resource.
    revisionId String
    Opaque revision identifier for the policy. The service returns a new value on every write; it is used for optimistic concurrency on update and delete.

    Import

    Identity Schema

    Required

    • resourceArn (String) ARN of the Lambda Web function the policy is attached to.

    Using pulumi import, import a Lambda Web resource policy using the function resourceArn. For example:

    $ pulumi import aws:lambdaweb/resourcePolicy:ResourcePolicy example arn:aws:lambda:us-east-1:123456789012:web-function/example
    

    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 aws logo
    Viewing docs for AWS v7.55.0
    published on Friday, Nov 13, 2026 by Pulumi

      Try Pulumi Cloud free.
      Your team will thank you.

      Start free trial