# AppSyncOpenSearchDataSource

An Appsync datasource backed by OpenSearch.

Extends: [Construct](/cdk/api/v2/docs/constructs.Construct.html) › [AppSyncBaseDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncBaseDataSource.html) › [AppSyncBackedDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncBackedDataSource.html) › AppSyncOpenSearchDataSource
Implements: [IGrantable](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IGrantable.html), [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html), [IDependable](/cdk/api/v2/docs/constructs.IDependable.html)

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

## Example

TypeScript:

```ts
import * as opensearch from 'aws-cdk-lib/aws-opensearchservice';

const domain = new opensearch.Domain(this, 'Domain', {
  version: opensearch.EngineVersion.OPENSEARCH_2_17,
  encryptionAtRest: {
    enabled: true,
  },
  nodeToNodeEncryption: true,
  enforceHttps: true,
  capacity: {
    multiAzWithStandbyEnabled: false,
  },
  ebs: {
    enabled: true,
    volumeSize: 10,
  },
});
const api = new appsync.EventApi(this, 'EventApiOpenSearch', {
  apiName: 'OpenSearchEventApi',
});

const dataSource = api.addOpenSearchDataSource('opensearchds', domain);
```

Python:

```python
import aws_cdk.aws_opensearchservice as opensearch

domain = opensearch.Domain(self, "Domain",
    version=opensearch.EngineVersion.OPENSEARCH_2_17,
    encryption_at_rest=opensearch.EncryptionAtRestOptions(
        enabled=True
    ),
    node_to_node_encryption=True,
    enforce_https=True,
    capacity=opensearch.CapacityConfig(
        multi_az_with_standby_enabled=False
    ),
    ebs=opensearch.EbsOptions(
        enabled=True,
        volume_size=10
    )
)
api = appsync.EventApi(self, "EventApiOpenSearch",
    api_name="OpenSearchEventApi"
)

data_source = api.add_open_search_data_source("opensearchds", domain)
```

Java:

```java
import software.amazon.awscdk.services.opensearchservice.*;

Domain domain = Domain.Builder.create(this, "Domain")
        .version(EngineVersion.OPENSEARCH_2_17)
        .encryptionAtRest(EncryptionAtRestOptions.builder()
                .enabled(true)
                .build())
        .nodeToNodeEncryption(true)
        .enforceHttps(true)
        .capacity(CapacityConfig.builder()
                .multiAzWithStandbyEnabled(false)
                .build())
        .ebs(EbsOptions.builder()
                .enabled(true)
                .volumeSize(10)
                .build())
        .build();
EventApi api = EventApi.Builder.create(this, "EventApiOpenSearch")
        .apiName("OpenSearchEventApi")
        .build();

AppSyncOpenSearchDataSource dataSource = api.addOpenSearchDataSource("opensearchds", domain);
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.OpenSearchService;

var domain = new Domain(this, "Domain", new DomainProps {
    Version = EngineVersion.OPENSEARCH_2_17,
    EncryptionAtRest = new EncryptionAtRestOptions {
        Enabled = true
    },
    NodeToNodeEncryption = true,
    EnforceHttps = true,
    Capacity = new CapacityConfig {
        MultiAzWithStandbyEnabled = false
    },
    Ebs = new EbsOptions {
        Enabled = true,
        VolumeSize = 10
    }
});
var api = new EventApi(this, "EventApiOpenSearch", new EventApiProps {
    ApiName = "OpenSearchEventApi"
});

var dataSource = api.AddOpenSearchDataSource("opensearchds", domain);
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

domain := opensearch.NewDomain(this, jsii.String("Domain"), &DomainProps{
	Version: opensearch.EngineVersion_OPENSEARCH_2_17(),
	EncryptionAtRest: &EncryptionAtRestOptions{
		Enabled: jsii.Boolean(true),
	},
	NodeToNodeEncryption: jsii.Boolean(true),
	EnforceHttps: jsii.Boolean(true),
	Capacity: &CapacityConfig{
		MultiAzWithStandbyEnabled: jsii.Boolean(false),
	},
	Ebs: &EbsOptions{
		Enabled: jsii.Boolean(true),
		VolumeSize: jsii.Number(10),
	},
})
api := appsync.NewEventApi(this, jsii.String("EventApiOpenSearch"), &EventApiProps{
	ApiName: jsii.String("OpenSearchEventApi"),
})

dataSource := api.AddOpenSearchDataSource(jsii.String("opensearchds"), domain)
```

## Initializer

TypeScript:

```ts
new AppSyncOpenSearchDataSource(scope: Construct, id: string, props: AppSyncOpenSearchDataSourceProps)
```

Python:

```python
AppSyncOpenSearchDataSource(scope: Construct, id: str, props: AppSyncOpenSearchDataSourceProps)
```

Java:

```java
new AppSyncOpenSearchDataSource(Construct scope, String id, AppSyncOpenSearchDataSourceProps props)
```

C# / .NET:

```csharp
new AppSyncOpenSearchDataSource(Construct scope, string id, AppSyncOpenSearchDataSourceProps props)
```

Golang:

```go
NewAppSyncOpenSearchDataSource(Scope Construct, Id *string, Props AppSyncOpenSearchDataSourceProps)
```

## Construct Props

- `api`: [IApiRef](/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.

- `domain`: [IDomain](/cdk/api/v2/docs/aws-cdk-lib.aws_opensearchservice.IDomain.html) (required) — The OpenSearch domain containing the endpoint for 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](/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

## Properties

- `grantPrincipal`: [IPrincipal](/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](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `resource`: [CfnDataSource](/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
