# FunctionEventType

The type of events that a CloudFront function can be invoked in response to.

- Source: [`aws-cloudfront/lib/function.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts#L261)

## Example

```ts
// Add a cloudfront Function to a Distribution
const cfFunction = new cloudfront.Function(this, 'Function', {
  code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
  runtime: cloudfront.FunctionRuntime.JS_2_0,
});

declare const s3Bucket: s3.Bucket;
new cloudfront.Distribution(this, 'distro', {
  defaultBehavior: {
    origin: new origins.S3Origin(s3Bucket),
    functionAssociations: [{
      function: cfFunction,
      eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
    }],
  },
});
```

## Members

| Member | Description |
| --- | --- |
| `VIEWER_REQUEST` | The viewer-request specifies the incoming request. |
| `VIEWER_RESPONSE` | The viewer-response specifies the outgoing response. |

## Referenced by

- [`FunctionAssociation`](/v2/docs/aws-cdk-lib.aws_cloudfront.FunctionAssociation).eventType
