# Code

Represents source code for an AppSync Function or Resolver.

Extends: Code
Superclass of: AssetCode, InlineCode

- Source: [`aws-appsync/lib/code.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-appsync/lib/code.ts#L26)
- Type last changed: v2.60.0 · 12 Jan 2023

## Example

```ts
declare const api: appsync.EventApi;
declare const lambdaDataSource: appsync.AppSyncLambdaDataSource;

// Lambda data source for publish handler
api.addChannelNamespace('lambda-ns', {
  code: appsync.Code.fromInline('/* event handler code here.*/'),
  publishHandlerConfig: {
    dataSource: lambdaDataSource,
  },
});

// Direct Lambda data source for publish handler
api.addChannelNamespace('lambda-direct-ns', {
  publishHandlerConfig: {
    dataSource: lambdaDataSource,
    direct: true,
  },
});

api.addChannelNamespace('lambda-direct-async-ns', {
  publishHandlerConfig: {
    dataSource: lambdaDataSource,
    direct: true,
    lambdaInvokeType: appsync.LambdaInvokeType.EVENT,
  },
});
```

## Initializer

```ts
new Code()
```

## Methods

- `bind(scope: Construct): CodeConfig` — Bind source code to an AppSync Function or resolver.

- `fromAsset(path: string, options?: AssetOptions): AssetCode` (static) — Loads the function code from a local disk path.

  **Parameters**

  - `path` — The path to the source code file.

- `fromInline(code: string): InlineCode` (static) — Inline code for AppSync function.

  **Parameters**

  - `code` — The actual handler code (the resulting zip file cannot exceed 4MB).

  **Returns:** `InlineCode` with inline code.
