Skip to content

(elasticsearch): Domain.fromDomainAttributes gives "Invalid URL" when endpoint is a token #15188

@HelioStrike

Description

@HelioStrike

I'm getting a Invalid URL when trying to use Domain.fromDomainAttributes with a CfnDomain object. The CfnDomain object was retrieved from a CfnInclude object. Here's the snippet of code that's failing for me.

private getDomainFromTemplate(name: string, cfnTemplate: CfnInclude): IDomain {
    const cfnDomain = cfnTemplate.getResource(name) as CfnDomain;
    return Domain.fromDomainAttributes(this, name, {domainArn: cfnDomain.attrArn, domainEndpoint: cfnDomain.attrDomainEndpoint});
}

Reproduction Steps

Here's some minimal code that causes the bug.

import * as elasticsearch from '@aws-cdk/aws-elasticsearch';

const domain = new elasticsearch.CfnDomain(this, "domain", {
    domainName: "domainName"
});
elasticsearch.Domain.fromDomainAttributes(this, name, {domainArn: domain.attrArn, domainEndpoint: domain.attrDomainEndpoint});

What did you expect to happen?

The error shouldn't happen and the Domain object should be successfully created.

What actually happened?

internal/url.js:257
  throw new ERR_INVALID_URL(input);
  ^

TypeError [ERR_INVALID_URL]: Invalid URL: ${Token[TOKEN.1766]}
    at onParseError (internal/url.js:257:9)
    at new URL (internal/url.js:333:5)
    at extractNameFromEndpoint (/Users/saimuty/workplace/dr_infra/src/JuryDisputeResolutionNAWSCDK/node_modules/monocdk/lib/aws-elasticsearch/lib/domain.js:946:26)
    at Function.fromDomainAttributes (/Users/saimuty/workplace/dr_infra/src/JuryDisputeResolutionNAWSCDK/node_modules/monocdk/lib/aws-elasticsearch/lib/domain.js:903:28)

Environment

  • CDK CLI Version : 1.107.0 (build 52c4434)
  • Framework Version: 1.107.0 (build 52c4434)
  • Node.js Version: v12.21.0
  • OS : MacOS Big Sur 11.4
  • Language (Version): Typescript (4.0.5)

This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-elasticsearchRelated to Amazon Elasticsearch ServicebugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions