Skip to content

Commit fd149b1

Browse files
authored
fix(opensearchservice): imported domain's domainendpoint is a url not an endpoint (#18027)
imported Domain's domainEndpoint should be a endpoint and not a url. Fixes [#18017](#18017) BREAKING CHANGE: imported domain property `domainEndpoint` used to contain `https://` prefix, now the prefix is dropped and it returns the same value as a `domainEndpoint` on a created domain ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a6dde1e commit fd149b1

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

packages/@aws-cdk/aws-elasticsearch/lib/domain.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
12181218
return new class extends DomainBase {
12191219
public readonly domainArn = domainArn;
12201220
public readonly domainName = domainName;
1221-
public readonly domainEndpoint = domainEndpoint;
1221+
public readonly domainEndpoint = domainEndpoint.replace(/^https?:\/\//, '');
12221222

12231223
constructor() { super(scope, id); }
12241224
};

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -928,26 +928,30 @@ describe('import', () => {
928928

929929
test('static fromDomainEndpoint(endpoint) allows importing an external/existing domain', () => {
930930
const domainName = 'test-domain-2w2x2u3tifly';
931-
const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
931+
const domainEndpointWithoutHttps = `${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
932+
const domainEndpoint = `https://${domainEndpointWithoutHttps}`;
932933
const imported = Domain.fromDomainEndpoint(stack, 'Domain', domainEndpoint);
933934

934935
expect(imported.domainName).toEqual(domainName);
935936
expect(imported.domainArn).toMatch(RegExp(`es:testregion:1234:domain/${domainName}$`));
937+
expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps);
936938

937939
expect(stack).not.toHaveResource('AWS::Elasticsearch::Domain');
938940
});
939941

940942
test('static fromDomainAttributes(attributes) allows importing an external/existing domain', () => {
941943
const domainName = 'test-domain-2w2x2u3tifly';
942944
const domainArn = `arn:aws:es:testregion:1234:domain/${domainName}`;
943-
const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
945+
const domainEndpointWithoutHttps = `${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
946+
const domainEndpoint = `https://${domainEndpointWithoutHttps}`;
944947
const imported = Domain.fromDomainAttributes(stack, 'Domain', {
945948
domainArn,
946949
domainEndpoint,
947950
});
948951

949952
expect(imported.domainName).toEqual(domainName);
950953
expect(imported.domainArn).toEqual(domainArn);
954+
expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps);
951955

952956
expect(stack).not.toHaveResource('AWS::Elasticsearch::Domain');
953957
});

packages/@aws-cdk/aws-opensearchservice/lib/domain.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
11481148
public readonly domainArn = domainArn;
11491149
public readonly domainName = domainName;
11501150
public readonly domainId = domainName;
1151-
public readonly domainEndpoint = domainEndpoint;
1151+
public readonly domainEndpoint = domainEndpoint.replace(/^https?:\/\//, '');
11521152

11531153
constructor() { super(scope, id); }
11541154
};

packages/@aws-cdk/aws-opensearchservice/test/domain.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -930,26 +930,30 @@ describe('import', () => {
930930

931931
test('static fromDomainEndpoint(endpoint) allows importing an external/existing domain', () => {
932932
const domainName = 'test-domain-2w2x2u3tifly';
933-
const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
933+
const domainEndpointWithoutHttps = `${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
934+
const domainEndpoint = `https://${domainEndpointWithoutHttps}`;
934935
const imported = Domain.fromDomainEndpoint(stack, 'Domain', domainEndpoint);
935936

936937
expect(imported.domainName).toEqual(domainName);
937938
expect(imported.domainArn).toMatch(RegExp(`es:testregion:1234:domain/${domainName}$`));
939+
expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps);
938940

939941
expect(stack).not.toHaveResource('AWS::OpenSearchService::Domain');
940942
});
941943

942944
test('static fromDomainAttributes(attributes) allows importing an external/existing domain', () => {
943945
const domainName = 'test-domain-2w2x2u3tifly';
944946
const domainArn = `arn:aws:es:testregion:1234:domain/${domainName}`;
945-
const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
947+
const domainEndpointWithoutHttps = `${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
948+
const domainEndpoint = `https://${domainEndpointWithoutHttps}`;
946949
const imported = Domain.fromDomainAttributes(stack, 'Domain', {
947950
domainArn,
948951
domainEndpoint,
949952
});
950953

951954
expect(imported.domainName).toEqual(domainName);
952955
expect(imported.domainArn).toEqual(domainArn);
956+
expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps);
953957

954958
expect(stack).not.toHaveResource('AWS::OpenSearchService::Domain');
955959
});

0 commit comments

Comments
 (0)