# FunctionProps

Properties for creating a CloudFront Function.

Used as props by: [Function](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.Function.html)

- Source: [`aws-cloudfront/lib/function.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts#L118)
- Type last changed: v2.275.0 · 26 Oct 2026

## Example

TypeScript:

```ts
const store = new cloudfront.KeyValueStore(this, 'KeyValueStore');
new cloudfront.Function(this, 'Function', {
  code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
  // Note that JS_2_0 must be used for Key Value Store support
  runtime: cloudfront.FunctionRuntime.JS_2_0,
  keyValueStore: store,
});
```

Python:

```python
store = cloudfront.KeyValueStore(self, "KeyValueStore")
cloudfront.Function(self, "Function",
    code=cloudfront.FunctionCode.from_inline("function handler(event) { return event.request }"),
    # Note that JS_2_0 must be used for Key Value Store support
    runtime=cloudfront.FunctionRuntime.JS_2_0,
    key_value_store=store
)
```

Java:

```java
KeyValueStore store = new KeyValueStore(this, "KeyValueStore");
Function.Builder.create(this, "Function")
        .code(FunctionCode.fromInline("function handler(event) { return event.request }"))
        // Note that JS_2_0 must be used for Key Value Store support
        .runtime(FunctionRuntime.JS_2_0)
        .keyValueStore(store)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var store = new KeyValueStore(this, "KeyValueStore");
new Function(this, "Function", new FunctionProps {
    Code = FunctionCode.FromInline("function handler(event) { return event.request }"),
    // Note that JS_2_0 must be used for Key Value Store support
    Runtime = FunctionRuntime.JS_2_0,
    KeyValueStore = store
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
store := cloudfront.NewKeyValueStore(this, jsii.String("KeyValueStore"))
cloudfront.NewFunction(this, jsii.String("Function"), &FunctionProps{
	Code: cloudfront.FunctionCode_FromInline(jsii.String("function handler(event) { return event.request }")),
	// Note that JS_2_0 must be used for Key Value Store support
	Runtime: cloudfront.FunctionRuntime_JS_2_0(),
	KeyValueStore: store,
})
```

## Properties

- `autoPublish`: boolean = true — A flag that determines whether to automatically publish the function to the LIVE stage when it’s created.

- `code`: [FunctionCode](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.FunctionCode.html) (required) — The source code of the function.

- `comment`: string — A comment to describe the function.

  **Default:** same as `functionName`

- `functionName`: string — A name to identify the function.

  **Default:** generated from the `id`

- `keyValueStore`: [IKeyValueStoreRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.IKeyValueStoreRef.html) — The Key Value Store to associate with this function.

  **Default:** no key value store is associated

  In order to associate a Key Value Store, the `runtime` must be
  `cloudfront-js-2.0` or newer.

- `runtime`: [FunctionRuntime](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.FunctionRuntime.html) — The runtime environment for the function.

  **Default:** FunctionRuntime.JS_2_0 if `keyValueStore` is specified or the `@aws-cdk/aws-cloudfront:defaultFunctionRuntimeV2_0` feature flag is enabled; otherwise, FunctionRuntime.JS_1_0.
