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

opensearchservice: creating OpenSearch domain from Endpoint results in malformed ARN when using VPC endpoint #29771

Open
martingrzzler opened this issue Apr 9, 2024 · 1 comment
Labels
@aws-cdk/aws-opensearch Related to the @aws-cdk/aws-opensearchservice package bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@martingrzzler
Copy link

Describe the bug

Calling Domain.fromDomainEndpoint leads to wrong domainArn when called with a VPC endpoint.

Domain.fromDomainEndpoint(
      this,
      'OpenSearchDomain',
      'https://vpc-name-xxxxxxxxx.region.es.amazonaws.com',
    )

The problem is caused by the extractNameFromEndpoint function.

Expected Behavior

Given endpoint https://vpc-name-xxxxxxxxx.region.es.amazonaws.com
Expect extractNameFromEndpoint to return name

Current Behavior

Actual vpc-name

Reproduction Steps

const domain = Domain.fromDomainEndpoint(
      this,
      'OpenSearchDomain',
      'https://vpc-name-xxxxxxxxx.region.es.amazonaws.com',
    )
    new CfnOutput(this, 'DomainArn', { // wrong ARN starting with name vpc-
      value: domain.domainArn,
    })

Possible Solution

function extractNameFromEndpoint(domainEndpoint: string) {
  const { hostname } = new URL(domainEndpoint);
  const domain = hostname.split(".")[0];
  const parts = domain.split("-");

  return parts.length === 3 ? parts[1] : parts[0];
}

Additional Information/Context

No response

CDK CLI Version

2.136.0

Framework Version

No response

Node.js Version

v21.6.0

OS

macOS

Language

TypeScript

Language Version

No response

Other information

No response

@martingrzzler martingrzzler added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 9, 2024
@github-actions github-actions bot added the @aws-cdk/aws-opensearch Related to the @aws-cdk/aws-opensearchservice package label Apr 9, 2024
@pahud pahud changed the title (aws-opensearchservice): (creating OpenSearch domain from Endpoint results in malformed ARN when using VPC endpoint) opensearchservice: creating OpenSearch domain from Endpoint results in malformed ARN when using VPC endpoint Apr 9, 2024
@pahud
Copy link
Contributor

pahud commented Apr 9, 2024

Sounds like it only happens when called with a VPC endpoint.

Thank you for the report and feel free to submit a PR to help us address this bug.

@pahud pahud added p2 effort/medium Medium work item – several days of effort effort/small Small work item – less than a day of effort and removed effort/medium Medium work item – several days of effort needs-triage This issue or PR still needs to be triaged. labels Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-opensearch Related to the @aws-cdk/aws-opensearchservice package bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants