Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(elasticsearch): deprecate all APIs except ElasticsearchVersion #19296

Merged
merged 18 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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