aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.7k stars 3.93k forks source link

opensearchservice: unable to create IDomain from Token #24005

Open corrjo opened 1 year ago

corrjo commented 1 year ago

Describe the bug

opensearchservice.Domain.fromDomainEndpoint unable to us parameters to resolve domain and create IDomain

example:

    const osDomain = openSearch.Domain.fromDomainEndpoint(
      this,
      'osDomain',
      ssm.StringParameter.valueForStringParameter(this, '/path/to/my/param'),
    );

https://github.com/aws/aws-cdk/blob/74318c7d22bfc00de9e005f68a0a6aaa58c7db39/packages/%40aws-cdk/aws-opensearchservice/lib/domain.ts#L1730 Creates the url using url.URL, which is a great way to verify its valid, but since the input is a token until deploy it won't resolve

Expected Behavior

I would expect it to create an IDomain using the Token

Current Behavior

only works if input is a valid url at synth time

Reproduction Steps

Create a parameter store parameter at /path/to/my/param containing the OS Domain endpoint url

openSearch.Domain.fromDomainEndpoint(
      this,
      'osDomain',
      ssm.StringParameter.valueForStringParameter(this, '/path/to/my/param'),
    );

Possible Solution

don't use url.URL

Additional Information/Context

No response

CDK CLI Version

2.63.1

Framework Version

No response

Node.js Version

v18.12.1

OS

macos

Language

Typescript

Language Version

No response

Other information

No response

peterwoodworth commented 1 year ago

Thanks for reporting this, I was able to reproduce failure here.

I found I was able to work around this if I use fromDomainAttributes and specify the arn as well. We should provide the option to import from just the endpoint without requiring the value of the endpoint to be known at synth. However to provide this option we may need to require that other info is known (such as the domain name) so that we can construct the arn of the domain if not provided