Skip to content

Commit

Permalink
chore(elasticsearch): deprecate all APIs except ElasticsearchVersion (
Browse files Browse the repository at this point in the history
#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*
  • Loading branch information
kaizencc committed Mar 15, 2022
1 parent 3866213 commit 122d723
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 244 deletions.
235 changes: 119 additions & 116 deletions packages/@aws-cdk/aws-appsync/test/appsync-elasticsearch.test.ts
Original file line number Diff line number Diff line change
@@ -1,151 +1,154 @@
import * as path from 'path';
import { Template } from '@aws-cdk/assertions';
import * as es from '@aws-cdk/aws-elasticsearch';
import { testDeprecated } from '@aws-cdk/cdk-build-tools';
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
import * as cdk from '@aws-cdk/core';
import * as appsync from '../lib';

// GLOBAL GIVEN
let stack: cdk.Stack;
let api: appsync.GraphqlApi;
let domain: es.Domain;
beforeEach(() => {
stack = new cdk.Stack();
api = new appsync.GraphqlApi(stack, 'baseApi', {
name: 'api',
schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')),
});
domain = new es.Domain(stack, 'EsDomain', {
version: es.ElasticsearchVersion.V7_10,
});
});

describe('Elasticsearch Data Source Configuration', () => {
testDeprecated('Elasticsearch configure properly', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Version: '2012-10-17',
Statement: [{
Action: [
'es:ESHttpGet',
'es:ESHttpHead',
'es:ESHttpDelete',
'es:ESHttpPost',
'es:ESHttpPut',
'es:ESHttpPatch',
],
Effect: 'Allow',
Resource: [{
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'],
},
{
'Fn::Join': ['', [{
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'],
}, '/*']],
}],
}],
},

describeDeprecated('Appsync Elasticsearch integration', () => {
beforeEach(() => {
stack = new cdk.Stack();
api = new appsync.GraphqlApi(stack, 'baseApi', {
name: 'api',
schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')),
});
domain = new es.Domain(stack, 'EsDomain', {
version: es.ElasticsearchVersion.V7_10,
});
});

testDeprecated('Elastic search configuration contains fully qualified url', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
ElasticsearchConfig: {
Endpoint: {
'Fn::Join': ['', ['https://', {
'Fn::GetAtt': ['EsDomain1213C634', 'DomainEndpoint'],
}]],
describe('Elasticsearch Data Source Configuration', () => {
test('Elasticsearch configure properly', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Version: '2012-10-17',
Statement: [{
Action: [
'es:ESHttpGet',
'es:ESHttpHead',
'es:ESHttpDelete',
'es:ESHttpPost',
'es:ESHttpPut',
'es:ESHttpPatch',
],
Effect: 'Allow',
Resource: [{
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'],
},
{
'Fn::Join': ['', [{
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'],
}, '/*']],
}],
}],
},
},
});
});
});

testDeprecated('default configuration produces name identical to the id', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain);
test('Elastic search configuration contains fully qualified url', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
Name: 'ds',
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
ElasticsearchConfig: {
Endpoint: {
'Fn::Join': ['', ['https://', {
'Fn::GetAtt': ['EsDomain1213C634', 'DomainEndpoint'],
}]],
},
},
});
});
});

testDeprecated('appsync configures name correctly', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain, {
name: 'custom',
});
test('default configuration produces name identical to the id', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
Name: 'custom',
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
Name: 'ds',
});
});
});

testDeprecated('appsync configures name and description correctly', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain, {
name: 'custom',
description: 'custom description',
test('appsync configures name correctly', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain, {
name: 'custom',
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
Name: 'custom',
});
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
Name: 'custom',
Description: 'custom description',
test('appsync configures name and description correctly', () => {
// WHEN
api.addElasticsearchDataSource('ds', domain, {
name: 'custom',
description: 'custom description',
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
Name: 'custom',
Description: 'custom description',
});
});
});

testDeprecated('appsync errors when creating multiple elasticsearch data sources with no configuration', () => {
// WHEN
const when = () => {
api.addElasticsearchDataSource('ds', domain);
api.addElasticsearchDataSource('ds', domain);
};

// THEN
expect(when).toThrow('There is already a Construct with name \'ds\' in GraphqlApi [baseApi]');
});
});

describe('adding elasticsearch data source from imported api', () => {
testDeprecated('imported api can add ElasticsearchDataSource from id', () => {
// WHEN
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
graphqlApiId: api.apiId,
});
importedApi.addElasticsearchDataSource('ds', domain);
test('appsync errors when creating multiple elasticsearch data sources with no configuration', () => {
// WHEN
const when = () => {
api.addElasticsearchDataSource('ds', domain);
api.addElasticsearchDataSource('ds', domain);
};

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] },
// THEN
expect(when).toThrow('There is already a Construct with name \'ds\' in GraphqlApi [baseApi]');
});
});

testDeprecated('imported api can add ElasticsearchDataSource from attributes', () => {
// WHEN
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
graphqlApiId: api.apiId,
graphqlApiArn: api.arn,
describe('adding elasticsearch data source from imported api', () => {
test('imported api can add ElasticsearchDataSource from id', () => {
// WHEN
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
graphqlApiId: api.apiId,
});
importedApi.addElasticsearchDataSource('ds', domain);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] },
});
});
importedApi.addElasticsearchDataSource('ds', domain);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] },
test('imported api can add ElasticsearchDataSource from attributes', () => {
// WHEN
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', {
graphqlApiId: api.apiId,
graphqlApiArn: api.arn,
});
importedApi.addElasticsearchDataSource('ds', domain);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'AMAZON_ELASTICSEARCH',
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] },
});
});
});
});
15 changes: 2 additions & 13 deletions packages/@aws-cdk/aws-elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@

---

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

> **CFN Resources:** All classes with the `Cfn` prefix in this module ([CFN Resources]) are always
> stable and safe to use.
>
> [CFN Resources]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_lib
<!-- -->

> **Stable:** Higher level constructs in this module that are marked stable will not undergo any
> breaking changes. They will strictly follow the [Semantic Versioning](https://semver.org/) model.
> This API may emit warnings. Backward compatibility is not guaranteed.
---

Expand Down
Loading

0 comments on commit 122d723

Please sign in to comment.