1. Packages
  2. AWS Classic
  3. API Docs
  4. cloudfront
  5. Function

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.12.2 published on Wednesday, Nov 29, 2023 by Pulumi

aws.cloudfront.Function

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.12.2 published on Wednesday, Nov 29, 2023 by Pulumi

    Provides a CloudFront Function resource. With CloudFront Functions in Amazon CloudFront, you can write lightweight functions in JavaScript for high-scale, latency-sensitive CDN customizations.

    See CloudFront Functions

    NOTE: You cannot delete a function if it’s associated with a cache behavior. First, update your distributions to remove the function association from all cache behaviors, then delete the function.

    Example Usage

    Basic Example

    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var test = new Aws.CloudFront.Function("test", new()
        {
            Runtime = "cloudfront-js-1.0",
            Comment = "my function",
            Publish = true,
            Code = File.ReadAllText($"{path.Module}/function.js"),
        });
    
    });
    
    package main
    
    import (
    	"fmt"
    	"os"
    
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudfront"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func readFileOrPanic(path string) pulumi.StringPtrInput {
    	data, err := os.ReadFile(path)
    	if err != nil {
    		panic(err.Error())
    	}
    	return pulumi.String(string(data))
    }
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := cloudfront.NewFunction(ctx, "test", &cloudfront.FunctionArgs{
    			Runtime: pulumi.String("cloudfront-js-1.0"),
    			Comment: pulumi.String("my function"),
    			Publish: pulumi.Bool(true),
    			Code:    readFileOrPanic(fmt.Sprintf("%v/function.js", path.Module)),
    		})
    		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.cloudfront.Function;
    import com.pulumi.aws.cloudfront.FunctionArgs;
    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 test = new Function("test", FunctionArgs.builder()        
                .runtime("cloudfront-js-1.0")
                .comment("my function")
                .publish(true)
                .code(Files.readString(Paths.get(String.format("%s/function.js", path.module()))))
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_aws as aws
    
    test = aws.cloudfront.Function("test",
        runtime="cloudfront-js-1.0",
        comment="my function",
        publish=True,
        code=(lambda path: open(path).read())(f"{path['module']}/function.js"))
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as fs from "fs";
    
    const test = new aws.cloudfront.Function("test", {
        runtime: "cloudfront-js-1.0",
        comment: "my function",
        publish: true,
        code: fs.readFileSync(`${path.module}/function.js`),
    });
    
    resources:
      test:
        type: aws:cloudfront:Function
        properties:
          runtime: cloudfront-js-1.0
          comment: my function
          publish: true
          code:
            fn::readFile: ${path.module}/function.js
    

    Create Function Resource

    new Function(name: string, args: FunctionArgs, opts?: CustomResourceOptions);
    @overload
    def Function(resource_name: str,
                 opts: Optional[ResourceOptions] = None,
                 code: Optional[str] = None,
                 comment: Optional[str] = None,
                 name: Optional[str] = None,
                 publish: Optional[bool] = None,
                 runtime: Optional[str] = None)
    @overload
    def Function(resource_name: str,
                 args: FunctionArgs,
                 opts: Optional[ResourceOptions] = None)
    func NewFunction(ctx *Context, name string, args FunctionArgs, opts ...ResourceOption) (*Function, error)
    public Function(string name, FunctionArgs args, CustomResourceOptions? opts = null)
    public Function(String name, FunctionArgs args)
    public Function(String name, FunctionArgs args, CustomResourceOptions options)
    
    type: aws:cloudfront:Function
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args FunctionArgs
    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 FunctionArgs
    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 FunctionArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args FunctionArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args FunctionArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Function Resource Properties

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

    Inputs

    The Function resource accepts the following input properties:

    Code string

    Source code of the function

    Runtime string

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    Comment string

    Comment.

    Name string

    Unique name for your CloudFront Function.

    Publish bool

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    Code string

    Source code of the function

    Runtime string

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    Comment string

    Comment.

    Name string

    Unique name for your CloudFront Function.

    Publish bool

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    code String

    Source code of the function

    runtime String

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    comment String

    Comment.

    name String

    Unique name for your CloudFront Function.

    publish Boolean

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    code string

    Source code of the function

    runtime string

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    comment string

    Comment.

    name string

    Unique name for your CloudFront Function.

    publish boolean

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    code str

    Source code of the function

    runtime str

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    comment str

    Comment.

    name str

    Unique name for your CloudFront Function.

    publish bool

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    code String

    Source code of the function

    runtime String

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    comment String

    Comment.

    name String

    Unique name for your CloudFront Function.

    publish Boolean

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    Outputs

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

    Arn string

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    Etag string

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    Id string

    The provider-assigned unique ID for this managed resource.

    LiveStageEtag string

    ETag hash of any LIVE stage of the function.

    Status string

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    Arn string

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    Etag string

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    Id string

    The provider-assigned unique ID for this managed resource.

    LiveStageEtag string

    ETag hash of any LIVE stage of the function.

    Status string

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    arn String

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    etag String

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    id String

    The provider-assigned unique ID for this managed resource.

    liveStageEtag String

    ETag hash of any LIVE stage of the function.

    status String

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    arn string

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    etag string

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    id string

    The provider-assigned unique ID for this managed resource.

    liveStageEtag string

    ETag hash of any LIVE stage of the function.

    status string

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    arn str

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    etag str

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    id str

    The provider-assigned unique ID for this managed resource.

    live_stage_etag str

    ETag hash of any LIVE stage of the function.

    status str

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    arn String

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    etag String

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    id String

    The provider-assigned unique ID for this managed resource.

    liveStageEtag String

    ETag hash of any LIVE stage of the function.

    status String

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    Look up Existing Function Resource

    Get an existing Function 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?: FunctionState, opts?: CustomResourceOptions): Function
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            arn: Optional[str] = None,
            code: Optional[str] = None,
            comment: Optional[str] = None,
            etag: Optional[str] = None,
            live_stage_etag: Optional[str] = None,
            name: Optional[str] = None,
            publish: Optional[bool] = None,
            runtime: Optional[str] = None,
            status: Optional[str] = None) -> Function
    func GetFunction(ctx *Context, name string, id IDInput, state *FunctionState, opts ...ResourceOption) (*Function, error)
    public static Function Get(string name, Input<string> id, FunctionState? state, CustomResourceOptions? opts = null)
    public static Function get(String name, Output<String> id, FunctionState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    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:
    Arn string

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    Code string

    Source code of the function

    Comment string

    Comment.

    Etag string

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    LiveStageEtag string

    ETag hash of any LIVE stage of the function.

    Name string

    Unique name for your CloudFront Function.

    Publish bool

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    Runtime string

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    Status string

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    Arn string

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    Code string

    Source code of the function

    Comment string

    Comment.

    Etag string

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    LiveStageEtag string

    ETag hash of any LIVE stage of the function.

    Name string

    Unique name for your CloudFront Function.

    Publish bool

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    Runtime string

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    Status string

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    arn String

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    code String

    Source code of the function

    comment String

    Comment.

    etag String

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    liveStageEtag String

    ETag hash of any LIVE stage of the function.

    name String

    Unique name for your CloudFront Function.

    publish Boolean

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    runtime String

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    status String

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    arn string

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    code string

    Source code of the function

    comment string

    Comment.

    etag string

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    liveStageEtag string

    ETag hash of any LIVE stage of the function.

    name string

    Unique name for your CloudFront Function.

    publish boolean

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    runtime string

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    status string

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    arn str

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    code str

    Source code of the function

    comment str

    Comment.

    etag str

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    live_stage_etag str

    ETag hash of any LIVE stage of the function.

    name str

    Unique name for your CloudFront Function.

    publish bool

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    runtime str

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    status str

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    arn String

    Amazon Resource Name (ARN) identifying your CloudFront Function.

    code String

    Source code of the function

    comment String

    Comment.

    etag String

    ETag hash of the function. This is the value for the DEVELOPMENT stage of the function.

    liveStageEtag String

    ETag hash of any LIVE stage of the function.

    name String

    Unique name for your CloudFront Function.

    publish Boolean

    Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

    runtime String

    Identifier of the function's runtime. Currently only cloudfront-js-1.0 is valid.

    The following arguments are optional:

    status String

    Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

    Import

    Using pulumi import, import CloudFront Functions using the name. For example:

     $ pulumi import aws:cloudfront/function:Function test my_test_function
    

    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

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.12.2 published on Wednesday, Nov 29, 2023 by Pulumi