# AppSyncBackedDataSource

Abstract AppSync datasource implementation.

Do not use directly but use subclasses for resource backed datasources

Extends: [Construct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Construct.html) › [AppSyncBaseDataSource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncBaseDataSource.html) › AppSyncBackedDataSource
Implements: [IGrantable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IGrantable.html), [IConstruct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IConstruct.html), [IDependable](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IDependable.html)
Superclass of: [AppSyncDynamoDbDataSource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncDynamoDbDataSource.html), [AppSyncEventBridgeDataSource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncEventBridgeDataSource.html), AppSyncHttpDataSource, AppSyncLambdaDataSource, AppSyncOpenSearchDataSource, AppSyncRdsDataSource

- Source: [`aws-appsync/lib/data-source-common.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-appsync/lib/data-source-common.ts#L220)
- Type last changed: v2.193.0 · 30 Apr 2025

## Example

TypeScript:

```ts
declare const api: appsync.EventApi;
declare const ddbDataSource: appsync.AppSyncDynamoDbDataSource;
declare const ebDataSource: appsync.AppSyncEventBridgeDataSource;

// DynamoDB data source for publish handler
api.addChannelNamespace('ddb-eb-ns', {
  code: appsync.Code.fromInline('/* event handler code here.*/'),
  publishHandlerConfig: {
    dataSource: ddbDataSource,
  },
  subscribeHandlerConfig: {
    dataSource: ebDataSource,
  },
});
```

Python:

```python
# api: appsync.EventApi
# ddb_data_source: appsync.AppSyncDynamoDbDataSource
# eb_data_source: appsync.AppSyncEventBridgeDataSource

# DynamoDB data source for publish handler
api.add_channel_namespace("ddb-eb-ns",
    code=appsync.Code.from_inline("/* event handler code here.*/"),
    publish_handler_config=appsync.HandlerConfig(
        data_source=ddb_data_source
    ),
    subscribe_handler_config=appsync.HandlerConfig(
        data_source=eb_data_source
    )
)
```

Java:

```java
EventApi api;
AppSyncDynamoDbDataSource ddbDataSource;
AppSyncEventBridgeDataSource ebDataSource;

// DynamoDB data source for publish handler
api.addChannelNamespace("ddb-eb-ns", ChannelNamespaceOptions.builder()
        .code(Code.fromInline("/* event handler code here.*/"))
        .publishHandlerConfig(HandlerConfig.builder()
                .dataSource(ddbDataSource)
                .build())
        .subscribeHandlerConfig(HandlerConfig.builder()
                .dataSource(ebDataSource)
                .build())
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
EventApi api;
AppSyncDynamoDbDataSource ddbDataSource;
AppSyncEventBridgeDataSource ebDataSource;

// DynamoDB data source for publish handler
api.AddChannelNamespace("ddb-eb-ns", new ChannelNamespaceOptions {
    Code = Code.FromInline("/* event handler code here.*/"),
    PublishHandlerConfig = new HandlerConfig {
        DataSource = ddbDataSource
    },
    SubscribeHandlerConfig = new HandlerConfig {
        DataSource = ebDataSource
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var api EventApi
var ddbDataSource AppSyncDynamoDbDataSource
var ebDataSource AppSyncEventBridgeDataSource

// DynamoDB data source for publish handler
api.AddChannelNamespace(jsii.String("ddb-eb-ns"), &ChannelNamespaceOptions{
	Code: appsync.Code_FromInline(jsii.String("/* event handler code here.*/")),
	PublishHandlerConfig: &HandlerConfig{
		DataSource: ddbDataSource,
	},
	SubscribeHandlerConfig: &HandlerConfig{
		DataSource: ebDataSource,
	},
})
```

## Initializer

TypeScript:

```ts
new AppSyncBackedDataSource(scope: Construct, id: string, props: AppSyncBackedDataSourceProps, extended: AppSyncExtendedDataSourceProps)
```

Python:

```python
AppSyncBackedDataSource(scope: Construct, id: str, props: AppSyncBackedDataSourceProps, extended: AppSyncExtendedDataSourceProps)
```

Java:

```java
new AppSyncBackedDataSource(Construct scope, String id, AppSyncBackedDataSourceProps props, AppSyncExtendedDataSourceProps extended)
```

C# / .NET:

```csharp
new AppSyncBackedDataSource(Construct scope, string id, AppSyncBackedDataSourceProps props, AppSyncExtendedDataSourceProps extended)
```

Golang:

```go
NewAppSyncBackedDataSource(Scope Construct, Id *string, Props AppSyncBackedDataSourceProps, Extended AppSyncExtendedDataSourceProps)
```

## Construct Props

- `api`: [IApiRef](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_appsync.IApiRef.html) (required) — The API to attach this data source to.

- `description`: string = None — The description of the data source.

- `name`: string — The name of the data source.

  **Default:** id of data source

  The only allowed pattern is: {[_A-Za-z][_0-9A-Za-z]*}.
  Any invalid characters will be automatically removed.

- `serviceRole`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM service role to be assumed by AppSync to interact with the data source.

  **Default:** Create a new role

## Construct Props

- `dynamoDbConfig`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.DynamoDBConfigProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.DynamoDBConfigProperty.html) — Configuration for DynamoDB Datasource.

  **Default:** No config

- `eventBridgeConfig`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.EventBridgeConfigProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.EventBridgeConfigProperty.html) — Configuration for EventBridge Datasource.

  **Default:** No config

- `httpConfig`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.HttpConfigProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.HttpConfigProperty.html) — Configuration for HTTP Datasource.

  **Default:** No config

- `lambdaConfig`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.LambdaConfigProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.LambdaConfigProperty.html) — Configuration for Lambda Datasource.

  **Default:** No config

- `openSearchServiceConfig`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.OpenSearchServiceConfigProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.OpenSearchServiceConfigProperty.html) — Configuration for OpenSearch data source.

  **Default:** No config

- `relationalDatabaseConfig`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.RelationalDatabaseConfigProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.RelationalDatabaseConfigProperty.html) — Configuration for RDS Datasource.

  **Default:** No config

- `type`: [AppSyncDataSourceType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncDataSourceType.html) (required) — The type of the AppSync datasource.

## Properties

- `grantPrincipal`: [IPrincipal](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) — The principal of the data source to be IGrantable.

- `name`: string — The name of the data source.

- `node`: [Node](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `resource`: [CfnDataSource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.html) — The underlying CFN data source resource.

## Methods

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
