# FunctionAssociation

Represents a CloudFront function and event type when using CF Functions.

The type of the `AddBehaviorOptions.functionAssociations` property.

- 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#L278)
- Type last changed: v2.224.0 · 13 Nov 2025

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_cloudfront as cloudfront } from 'aws-cdk-lib';
import { aws_cloudfront as interfaces_cloudfront } from 'aws-cdk-lib/interfaces';

declare const functionRef: interfaces_cloudfront.IFunctionRef;
const functionAssociation: cloudfront.FunctionAssociation = {
  eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
  function: functionRef,
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_cloudfront as cloudfront
from aws_cdk.interfaces import aws_cloudfront as interfaces_cloudfront

# function_ref: interfaces_cloudfront.IFunctionRef

function_association = cloudfront.FunctionAssociation(
    event_type=cloudfront.FunctionEventType.VIEWER_REQUEST,
    function=function_ref
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.cloudfront.*;
import software.amazon.awscdk.interfaces.cloudfront.*;

IFunctionRef functionRef;

FunctionAssociation functionAssociation = FunctionAssociation.builder()
        .eventType(FunctionEventType.VIEWER_REQUEST)
        .function(functionRef)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.CloudFront;
using Amazon.CDK.Interfaces.CloudFront;

IFunctionRef functionRef;

var functionAssociation = new FunctionAssociation {
    EventType = FunctionEventType.VIEWER_REQUEST,
    Function = functionRef
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var functionRef IFunctionRef

functionAssociation := &FunctionAssociation{
	EventType: awscdk.Aws_cloudfront.FunctionEventType_VIEWER_REQUEST,
	Function: functionRef,
}
```

## Properties

- `eventType`: [FunctionEventType](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.FunctionEventType.html) (required) — The type of event which should invoke the function.

- `function`: [IFunctionRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.IFunctionRef.html) (required) — The CloudFront function that will be invoked.
