AWS Classic

v4.30.0 published on Tuesday, Nov 30, 2021 by Pulumi

Function

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.IO;
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var test = new Aws.CloudFront.Function("test", new Aws.CloudFront.FunctionArgs
        {
            Runtime = "cloudfront-js-1.0",
            Comment = "my function",
            Publish = true,
            Code = File.ReadAllText($"{path.Module}/function.js"),
        });
    }

}
package main

import (
	"fmt"
	"io/ioutil"

	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/cloudfront"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func readFileOrPanic(path string) pulumi.StringPtrInput {
	data, err := ioutil.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%v", path.Module, "/function.js")),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
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 * 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`),
});

Create a 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)
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.

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.
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.
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.
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.
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.

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 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.

Look up an 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)
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.

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.
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.
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.
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.
status str
Status of the function. Can be UNPUBLISHED, UNASSOCIATED or ASSOCIATED.

Import

CloudFront Functions can be imported using the name, e.g.,

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

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.