Skip to content

Commit 122d723

Browse files
authored
chore(elasticsearch): deprecate all APIs except ElasticsearchVersion (#19296)
Closes #16530. Depends on #16529. This PR deprecates all APIs in `elasticsearch` in favor of the `opensearchservice` module. However, it does not deprecate `elasticsearch` as a module, since there are rules in place that disallow stable modules (like `cloudformation-include`) from depending on deprecated modules. See #19392. > `ElasticsearchVersion` was not deprecated due to a quirk in how the module is imported. It looks like, on import, the static properties `public static readonly V7_10 = ElasticsearchVersion.of('7.10');` actually tries to make the api call `of()`, which is deprecated. So imports fail with a message about using the deprecated api `ElasticsearchVersion.of()`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3866213 commit 122d723

File tree

6 files changed

+440
-244
lines changed

6 files changed

+440
-244
lines changed
Lines changed: 119 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,154 @@
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';
4+
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
55
import * as cdk from '@aws-cdk/core';
66
import * as appsync from '../lib';
77

88
// GLOBAL GIVEN
99
let stack: cdk.Stack;
1010
let api: appsync.GraphqlApi;
1111
let domain: es.Domain;
12-
beforeEach(() => {
13-
stack = new cdk.Stack();
14-
api = new appsync.GraphqlApi(stack, 'baseApi', {
15-
name: 'api',
16-
schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')),
17-
});
18-
domain = new es.Domain(stack, 'EsDomain', {
19-
version: es.ElasticsearchVersion.V7_10,
20-
});
21-
});
22-
23-
describe('Elasticsearch Data Source Configuration', () => {
24-
testDeprecated('Elasticsearch configure properly', () => {
25-
// WHEN
26-
api.addElasticsearchDataSource('ds', domain);
27-
28-
// THEN
29-
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
30-
PolicyDocument: {
31-
Version: '2012-10-17',
32-
Statement: [{
33-
Action: [
34-
'es:ESHttpGet',
35-
'es:ESHttpHead',
36-
'es:ESHttpDelete',
37-
'es:ESHttpPost',
38-
'es:ESHttpPut',
39-
'es:ESHttpPatch',
40-
],
41-
Effect: 'Allow',
42-
Resource: [{
43-
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'],
44-
},
45-
{
46-
'Fn::Join': ['', [{
47-
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'],
48-
}, '/*']],
49-
}],
50-
}],
51-
},
12+
13+
describeDeprecated('Appsync Elasticsearch integration', () => {
14+
beforeEach(() => {
15+
stack = new cdk.Stack();
16+
api = new appsync.GraphqlApi(stack, 'baseApi', {
17+
name: 'api',
18+
schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')),
19+
});
20+
domain = new es.Domain(stack, 'EsDomain', {
21+
version: es.ElasticsearchVersion.V7_10,
5222
});
5323
});
5424

55-
testDeprecated('Elastic search configuration contains fully qualified url', () => {
56-
// WHEN
57-
api.addElasticsearchDataSource('ds', domain);
58-
59-
// THEN
60-
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
61-
ElasticsearchConfig: {
62-
Endpoint: {
63-
'Fn::Join': ['', ['https://', {
64-
'Fn::GetAtt': ['EsDomain1213C634', 'DomainEndpoint'],
65-
}]],
25+
describe('Elasticsearch Data Source Configuration', () => {
26+
test('Elasticsearch configure properly', () => {
27+
// WHEN
28+
api.addElasticsearchDataSource('ds', domain);
29+
30+
// THEN
31+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
32+
PolicyDocument: {
33+
Version: '2012-10-17',
34+
Statement: [{
35+
Action: [
36+
'es:ESHttpGet',
37+
'es:ESHttpHead',
38+
'es:ESHttpDelete',
39+
'es:ESHttpPost',
40+
'es:ESHttpPut',
41+
'es:ESHttpPatch',
42+
],
43+
Effect: 'Allow',
44+
Resource: [{
45+
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'],
46+
},
47+
{
48+
'Fn::Join': ['', [{
49+
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'],
50+
}, '/*']],
51+
}],
52+
}],
6653
},
67-
},
54+
});
6855
});
69-
});
7056

71-
testDeprecated('default configuration produces name identical to the id', () => {
72-
// WHEN
73-
api.addElasticsearchDataSource('ds', domain);
57+
test('Elastic search configuration contains fully qualified url', () => {
58+
// WHEN
59+
api.addElasticsearchDataSource('ds', domain);
7460

75-
// THEN
76-
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
77-
Type: 'AMAZON_ELASTICSEARCH',
78-
Name: 'ds',
61+
// THEN
62+
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
63+
ElasticsearchConfig: {
64+
Endpoint: {
65+
'Fn::Join': ['', ['https://', {
66+
'Fn::GetAtt': ['EsDomain1213C634', 'DomainEndpoint'],
67+
}]],
68+
},
69+
},
70+
});
7971
});
80-
});
8172

82-
testDeprecated('appsync configures name correctly', () => {
83-
// WHEN
84-
api.addElasticsearchDataSource('ds', domain, {
85-
name: 'custom',
86-
});
73+
test('default configuration produces name identical to the id', () => {
74+
// WHEN
75+
api.addElasticsearchDataSource('ds', domain);
8776

88-
// THEN
89-
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
90-
Type: 'AMAZON_ELASTICSEARCH',
91-
Name: 'custom',
77+
// THEN
78+
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
79+
Type: 'AMAZON_ELASTICSEARCH',
80+
Name: 'ds',
81+
});
9282
});
93-
});
9483

95-
testDeprecated('appsync configures name and description correctly', () => {
96-
// WHEN
97-
api.addElasticsearchDataSource('ds', domain, {
98-
name: 'custom',
99-
description: 'custom description',
84+
test('appsync configures name correctly', () => {
85+
// WHEN
86+
api.addElasticsearchDataSource('ds', domain, {
87+
name: 'custom',
88+
});
89+
90+
// THEN
91+
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
92+
Type: 'AMAZON_ELASTICSEARCH',
93+
Name: 'custom',
94+
});
10095
});
10196

102-
// THEN
103-
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
104-
Type: 'AMAZON_ELASTICSEARCH',
105-
Name: 'custom',
106-
Description: 'custom description',
97+
test('appsync configures name and description correctly', () => {
98+
// WHEN
99+
api.addElasticsearchDataSource('ds', domain, {
100+
name: 'custom',
101+
description: 'custom description',
102+
});
103+
104+
// THEN
105+
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
106+
Type: 'AMAZON_ELASTICSEARCH',
107+
Name: 'custom',
108+
Description: 'custom description',
109+
});
107110
});
108-
});
109111

110-
testDeprecated('appsync errors when creating multiple elasticsearch data sources with no configuration', () => {
111-
// WHEN
112-
const when = () => {
113-
api.addElasticsearchDataSource('ds', domain);
114-
api.addElasticsearchDataSource('ds', domain);
115-
};
116-
117-
// THEN
118-
expect(when).toThrow('There is already a Construct with name \'ds\' in GraphqlApi [baseApi]');
119-
});
120-
});
121-
122-
describe('adding elasticsearch data source from imported api', () => {
123-
testDeprecated('imported api can add ElasticsearchDataSource from id', () => {
124-
// WHEN
125-
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
126-
graphqlApiId: api.apiId,
127-
});
128-
importedApi.addElasticsearchDataSource('ds', domain);
112+
test('appsync errors when creating multiple elasticsearch data sources with no configuration', () => {
113+
// WHEN
114+
const when = () => {
115+
api.addElasticsearchDataSource('ds', domain);
116+
api.addElasticsearchDataSource('ds', domain);
117+
};
129118

130-
// THEN
131-
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
132-
Type: 'AMAZON_ELASTICSEARCH',
133-
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] },
119+
// THEN
120+
expect(when).toThrow('There is already a Construct with name \'ds\' in GraphqlApi [baseApi]');
134121
});
135122
});
136123

137-
testDeprecated('imported api can add ElasticsearchDataSource from attributes', () => {
138-
// WHEN
139-
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
140-
graphqlApiId: api.apiId,
141-
graphqlApiArn: api.arn,
124+
describe('adding elasticsearch data source from imported api', () => {
125+
test('imported api can add ElasticsearchDataSource from id', () => {
126+
// WHEN
127+
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
128+
graphqlApiId: api.apiId,
129+
});
130+
importedApi.addElasticsearchDataSource('ds', domain);
131+
132+
// THEN
133+
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
134+
Type: 'AMAZON_ELASTICSEARCH',
135+
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] },
136+
});
142137
});
143-
importedApi.addElasticsearchDataSource('ds', domain);
144138

145-
// THEN
146-
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
147-
Type: 'AMAZON_ELASTICSEARCH',
148-
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] },
139+
test('imported api can add ElasticsearchDataSource from attributes', () => {
140+
// WHEN
141+
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
142+
graphqlApiId: api.apiId,
143+
graphqlApiArn: api.arn,
144+
});
145+
importedApi.addElasticsearchDataSource('ds', domain);
146+
147+
// THEN
148+
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
149+
Type: 'AMAZON_ELASTICSEARCH',
150+
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] },
151+
});
149152
});
150153
});
151154
});

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@
33

44
---
55

6-
Features | Stability
7-
-----------------------------------|----------------------------------------------------------------
8-
CFN Resources | ![Stable](https://img.shields.io/badge/stable-success.svg?style=for-the-badge)
9-
Higher level constructs for Domain | ![Stable](https://img.shields.io/badge/stable-success.svg?style=for-the-badge)
6+
![Deprecated](https://img.shields.io/badge/deprecated-critical.svg?style=for-the-badge)
107

11-
> **CFN Resources:** All classes with the `Cfn` prefix in this module ([CFN Resources]) are always
12-
> stable and safe to use.
13-
>
14-
> [CFN Resources]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_lib
15-
16-
<!-- -->
17-
18-
> **Stable:** Higher level constructs in this module that are marked stable will not undergo any
19-
> breaking changes. They will strictly follow the [Semantic Versioning](https://semver.org/) model.
8+
> This API may emit warnings. Backward compatibility is not guaranteed.
209
2110
---
2211

0 commit comments

Comments
 (0)