Skip to content

Commit 922a9dc

Browse files
authored
feat(appsync): add OpenSearch domain data source (#16529)
Deprecate `ElasticsearchDataSource` and introduce `OpenSearchDataSource` as a replacement. closes #16528 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a9e286e commit 922a9dc

9 files changed

+554
-26
lines changed

packages/@aws-cdk/aws-appsync/README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,19 @@ httpDs.createResolver({
240240
});
241241
```
242242

243-
### Elasticsearch
243+
### Amazon OpenSearch Service
244244

245-
AppSync has builtin support for Elasticsearch from domains that are provisioned
246-
through your AWS account. You can use AppSync resolvers to perform GraphQL operations
247-
such as queries, mutations, and subscriptions.
245+
AppSync has builtin support for Amazon OpenSearch Service (successor to Amazon
246+
Elasticsearch Service) from domains that are provisioned through your AWS account. You can
247+
use AppSync resolvers to perform GraphQL operations such as queries, mutations, and
248+
subscriptions.
248249

249250
```ts
250-
import * as es from '@aws-cdk/aws-elasticsearch';
251+
import * as opensearch from '@aws-cdk/aws-opensearchservice';
251252

252253
const user = new iam.User(this, 'User');
253-
const domain = new es.Domain(this, 'Domain', {
254-
version: es.ElasticsearchVersion.V7_1,
254+
const domain = new opensearch.Domain(this, 'Domain', {
255+
version: opensearch.EngineVersion.OPENSEARCH_1_1,
255256
removalPolicy: RemovalPolicy.DESTROY,
256257
fineGrainedAccessControl: { masterUserArn: user.userArn },
257258
encryptionAtRest: { enabled: true },
@@ -260,7 +261,7 @@ const domain = new es.Domain(this, 'Domain', {
260261
});
261262

262263
declare const api: appsync.GraphqlApi;
263-
const ds = api.addElasticsearchDataSource('ds', domain);
264+
const ds = api.addOpenSearchDataSource('ds', domain);
264265

265266
ds.createResolver({
266267
typeName: 'Query',

packages/@aws-cdk/aws-appsync/lib/data-source.ts

+44-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ITable } from '@aws-cdk/aws-dynamodb';
2-
import { IDomain } from '@aws-cdk/aws-elasticsearch';
2+
import { IDomain as IElasticsearchDomain } from '@aws-cdk/aws-elasticsearch';
33
import { Grant, IGrantable, IPrincipal, IRole, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
44
import { IFunction } from '@aws-cdk/aws-lambda';
5+
import { IDomain as IOpenSearchDomain } from '@aws-cdk/aws-opensearchservice';
56
import { IServerlessCluster } from '@aws-cdk/aws-rds';
67
import { ISecret } from '@aws-cdk/aws-secretsmanager';
78
import { IResolvable, Lazy, Stack } from '@aws-cdk/core';
@@ -64,11 +65,18 @@ export interface ExtendedDataSourceProps {
6465
*/
6566
readonly dynamoDbConfig?: CfnDataSource.DynamoDBConfigProperty | IResolvable;
6667
/**
67-
* configuration for Elasticsearch Datasource
68+
* configuration for Elasticsearch data source
6869
*
70+
* @deprecated - use `openSearchConfig`
6971
* @default - No config
7072
*/
7173
readonly elasticsearchConfig?: CfnDataSource.ElasticsearchConfigProperty | IResolvable;
74+
/**
75+
* configuration for OpenSearch data source
76+
*
77+
* @default - No config
78+
*/
79+
readonly openSearchServiceConfig?: CfnDataSource.OpenSearchServiceConfigProperty | IResolvable;
7280
/**
7381
* configuration for HTTP Datasource
7482
*
@@ -370,17 +378,21 @@ export class RdsDataSource extends BackedDataSource {
370378
}
371379

372380
/**
373-
* Properities for the Elasticsearch Data Source
381+
* Properties for the Elasticsearch Data Source
382+
*
383+
* @deprecated - use `OpenSearchDataSourceProps` with `OpenSearchDataSource`
374384
*/
375385
export interface ElasticsearchDataSourceProps extends BackedDataSourceProps {
376386
/**
377387
* The elasticsearch domain containing the endpoint for the data source
378388
*/
379-
readonly domain: IDomain;
389+
readonly domain: IElasticsearchDomain;
380390
}
381391

382392
/**
383393
* An Appsync datasource backed by Elasticsearch
394+
*
395+
* @deprecated - use `OpenSearchDataSource`
384396
*/
385397
export class ElasticsearchDataSource extends BackedDataSource {
386398
constructor(scope: Construct, id: string, props: ElasticsearchDataSourceProps) {
@@ -394,4 +406,31 @@ export class ElasticsearchDataSource extends BackedDataSource {
394406

395407
props.domain.grantReadWrite(this);
396408
}
397-
}
409+
}
410+
411+
/**
412+
* Properties for the OpenSearch Data Source
413+
*/
414+
export interface OpenSearchDataSourceProps extends BackedDataSourceProps {
415+
/**
416+
* The OpenSearch domain containing the endpoint for the data source
417+
*/
418+
readonly domain: IOpenSearchDomain;
419+
}
420+
421+
/**
422+
* An Appsync datasource backed by OpenSearch
423+
*/
424+
export class OpenSearchDataSource extends BackedDataSource {
425+
constructor(scope: Construct, id: string, props: OpenSearchDataSourceProps) {
426+
super(scope, id, props, {
427+
type: 'AMAZON_OPENSEARCH_SERVICE',
428+
openSearchServiceConfig: {
429+
awsRegion: props.domain.stack.region,
430+
endpoint: `https://${props.domain.domainEndpoint}`,
431+
},
432+
});
433+
434+
props.domain.grantReadWrite(this);
435+
}
436+
}

packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts

+33-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ITable } from '@aws-cdk/aws-dynamodb';
2-
import { IDomain } from '@aws-cdk/aws-elasticsearch';
2+
import { IDomain as IElasticsearchDomain } from '@aws-cdk/aws-elasticsearch';
33
import { IFunction } from '@aws-cdk/aws-lambda';
4+
import { IDomain as IOpenSearchDomain } from '@aws-cdk/aws-opensearchservice';
45
import { IServerlessCluster } from '@aws-cdk/aws-rds';
56
import { ISecret } from '@aws-cdk/aws-secretsmanager';
67
import { CfnResource, IResource, Resource } from '@aws-cdk/core';
7-
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, RdsDataSource, AwsIamConfig, ElasticsearchDataSource } from './data-source';
8+
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, RdsDataSource, AwsIamConfig, ElasticsearchDataSource, OpenSearchDataSource } from './data-source';
89
import { Resolver, ExtendedResolverProps } from './resolver';
910

1011
/**
@@ -114,11 +115,21 @@ export interface IGraphqlApi extends IResource {
114115
/**
115116
* add a new elasticsearch data source to this API
116117
*
118+
* @deprecated - use `addOpenSearchDataSource`
117119
* @param id The data source's id
118120
* @param domain The elasticsearch domain for this data source
119121
* @param options The optional configuration for this data source
120122
*/
121-
addElasticsearchDataSource(id: string, domain: IDomain, options?: DataSourceOptions): ElasticsearchDataSource;
123+
addElasticsearchDataSource(id: string, domain: IElasticsearchDomain, options?: DataSourceOptions): ElasticsearchDataSource;
124+
125+
/**
126+
* Add a new OpenSearch data source to this API
127+
*
128+
* @param id The data source's id
129+
* @param domain The OpenSearch domain for this data source
130+
* @param options The optional configuration for this data source
131+
*/
132+
addOpenSearchDataSource(id: string, domain: IOpenSearchDomain, options?: DataSourceOptions): OpenSearchDataSource;
122133

123134
/**
124135
* creates a new resolver for this datasource and API using the given properties
@@ -241,11 +252,12 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
241252
/**
242253
* add a new elasticsearch data source to this API
243254
*
255+
* @deprecated - use `addOpenSearchDataSource`
244256
* @param id The data source's id
245257
* @param domain The elasticsearch domain for this data source
246258
* @param options The optional configuration for this data source
247259
*/
248-
public addElasticsearchDataSource(id: string, domain: IDomain, options?: DataSourceOptions): ElasticsearchDataSource {
260+
public addElasticsearchDataSource(id: string, domain: IElasticsearchDomain, options?: DataSourceOptions): ElasticsearchDataSource {
249261
return new ElasticsearchDataSource(this, id, {
250262
api: this,
251263
name: options?.name,
@@ -254,6 +266,22 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
254266
});
255267
}
256268

269+
/**
270+
* add a new OpenSearch data source to this API
271+
*
272+
* @param id The data source's id
273+
* @param domain The OpenSearch domain for this data source
274+
* @param options The optional configuration for this data source
275+
*/
276+
public addOpenSearchDataSource(id: string, domain: IOpenSearchDomain, options?: DataSourceOptions): OpenSearchDataSource {
277+
return new OpenSearchDataSource(this, id, {
278+
api: this,
279+
name: options?.name,
280+
description: options?.description,
281+
domain,
282+
});
283+
}
284+
257285
/**
258286
* creates a new resolver for this datasource and API using the given properties
259287
*/
@@ -273,4 +301,4 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
273301
construct;
274302
return false;
275303
}
276-
}
304+
}

packages/@aws-cdk/aws-appsync/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"@aws-cdk/aws-elasticsearch": "0.0.0",
9696
"@aws-cdk/aws-iam": "0.0.0",
9797
"@aws-cdk/aws-lambda": "0.0.0",
98+
"@aws-cdk/aws-opensearchservice": "0.0.0",
9899
"@aws-cdk/aws-rds": "0.0.0",
99100
"@aws-cdk/aws-s3-assets": "0.0.0",
100101
"@aws-cdk/aws-secretsmanager": "0.0.0",
@@ -109,6 +110,7 @@
109110
"@aws-cdk/aws-elasticsearch": "0.0.0",
110111
"@aws-cdk/aws-iam": "0.0.0",
111112
"@aws-cdk/aws-lambda": "0.0.0",
113+
"@aws-cdk/aws-opensearchservice": "0.0.0",
112114
"@aws-cdk/aws-rds": "0.0.0",
113115
"@aws-cdk/aws-s3-assets": "0.0.0",
114116
"@aws-cdk/aws-secretsmanager": "0.0.0",

packages/@aws-cdk/aws-appsync/test/appsync-elasticsearch.test.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
22
import { Template } from '@aws-cdk/assertions';
33
import * as es from '@aws-cdk/aws-elasticsearch';
4+
import { testDeprecated } from '@aws-cdk/cdk-build-tools';
45
import * as cdk from '@aws-cdk/core';
56
import * as appsync from '../lib';
67

@@ -20,7 +21,7 @@ beforeEach(() => {
2021
});
2122

2223
describe('Elasticsearch Data Source Configuration', () => {
23-
test('Elasticsearch configure properly', () => {
24+
testDeprecated('Elasticsearch configure properly', () => {
2425
// WHEN
2526
api.addElasticsearchDataSource('ds', domain);
2627

@@ -51,7 +52,7 @@ describe('Elasticsearch Data Source Configuration', () => {
5152
});
5253
});
5354

54-
test('Elastic search configuration contains fully qualified url', () => {
55+
testDeprecated('Elastic search configuration contains fully qualified url', () => {
5556
// WHEN
5657
api.addElasticsearchDataSource('ds', domain);
5758

@@ -67,7 +68,7 @@ describe('Elasticsearch Data Source Configuration', () => {
6768
});
6869
});
6970

70-
test('default configuration produces name identical to the id', () => {
71+
testDeprecated('default configuration produces name identical to the id', () => {
7172
// WHEN
7273
api.addElasticsearchDataSource('ds', domain);
7374

@@ -78,7 +79,7 @@ describe('Elasticsearch Data Source Configuration', () => {
7879
});
7980
});
8081

81-
test('appsync configures name correctly', () => {
82+
testDeprecated('appsync configures name correctly', () => {
8283
// WHEN
8384
api.addElasticsearchDataSource('ds', domain, {
8485
name: 'custom',
@@ -91,7 +92,7 @@ describe('Elasticsearch Data Source Configuration', () => {
9192
});
9293
});
9394

94-
test('appsync configures name and description correctly', () => {
95+
testDeprecated('appsync configures name and description correctly', () => {
9596
// WHEN
9697
api.addElasticsearchDataSource('ds', domain, {
9798
name: 'custom',
@@ -106,7 +107,7 @@ describe('Elasticsearch Data Source Configuration', () => {
106107
});
107108
});
108109

109-
test('appsync errors when creating multiple elasticsearch data sources with no configuration', () => {
110+
testDeprecated('appsync errors when creating multiple elasticsearch data sources with no configuration', () => {
110111
// WHEN
111112
const when = () => {
112113
api.addElasticsearchDataSource('ds', domain);
@@ -119,7 +120,7 @@ describe('Elasticsearch Data Source Configuration', () => {
119120
});
120121

121122
describe('adding elasticsearch data source from imported api', () => {
122-
test('imported api can add ElasticsearchDataSource from id', () => {
123+
testDeprecated('imported api can add ElasticsearchDataSource from id', () => {
123124
// WHEN
124125
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
125126
graphqlApiId: api.apiId,
@@ -133,7 +134,7 @@ describe('adding elasticsearch data source from imported api', () => {
133134
});
134135
});
135136

136-
test('imported api can add ElasticsearchDataSource from attributes', () => {
137+
testDeprecated('imported api can add ElasticsearchDataSource from attributes', () => {
137138
// WHEN
138139
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
139140
graphqlApiId: api.apiId,

0 commit comments

Comments
 (0)