# FunctionCode

Represents the function's source code.

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

## Example

```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,
});
```

## Initializer

```ts
new FunctionCode()
```

## Methods

- `fromFile(options: FileCodeOptions): FunctionCode // chainable` (static) — Code from external file for function.

  **Parameters**

  - `options` — the options for the external file.

  **Returns:** code object with contents from file.

- `fromInline(code: string): FunctionCode // chainable` (static) — Inline code for function.

  **Parameters**

  - `code` — The actual function code.

  **Returns:** code object with inline code.

- `render(): string` — renders the function code.
