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

[aws-elasticsearch] Can't reference existing ES domain from imported values #10841

Closed
sysopcorner opened this issue Oct 13, 2020 · 8 comments
Closed
Labels
@aws-cdk/aws-elasticsearch Related to Amazon Elasticsearch Service bug This issue is a bug. duplicate This issue is a duplicate. effort/small Small work item – less than a day of effort p2

Comments

@sysopcorner
Copy link

I'm trying to import ES domain from Output values available in another CloudFormation Stack. I'm hitting jsii.errors.JSIIError: Invalid URL: ${Token[TOKEN.172]}. When I'm using extracted values directly importing ES works fine. Also note, that similar code works fine in different conditions - eg reference imported securityGroup

Reproduction Steps

        es = elasticsearch.Domain.from_domain_attributes(
            self, "ESDomain",
            domain_endpoint=core.Fn.import_value(
                    shared_value_to_import=es_domain_name + "-ElasticSearchSecurityGroupId"
                ),
            domain_arn=core.Fn.import_value(
                    shared_value_to_import=es_domain_name + "-ElasticSearchSecurityGroupId"
                )
        )

What did you expect to happen?

Import ES domain object from Outputs of another stack.

What actually happened?


**jsii.errors.JavaScriptError: 
  TypeError [ERR_INVALID_URL]: Invalid URL: ${Token[TOKEN.172]}**
     

Environment

  • CLI Version :1.67.0 (build 2b4dd71)
  • Framework Version: 1.67.0 (build 2b4dd71)
  • Node.js Version: v12.18.3
  • OS : Mac OS Catalina
  • Language (Version):vPython 3.8.5

Other

stackTrace:

jsii.errors.JavaScriptError: 
>   TypeError [ERR_INVALID_URL]: Invalid URL: ${Token[TOKEN.172]}
>       at onParseError (internal/url.js:256:9)
>       at new URL (internal/url.js:332:5)
>       at extractNameFromEndpoint (/private/var/folders/98/byg4ch215m58rf7vs2957w3m0000gn/T/jsii-kernel-BTnvjr/node_modules/@aws-cdk/aws-elasticsearch/lib/domain.js:711:26)
>       at Function.fromDomainAttributes (/private/var/folders/98/byg4ch215m58rf7vs2957w3m0000gn/T/jsii-kernel-BTnvjr/node_modules/@aws-cdk/aws-elasticsearch/lib/domain.js:684:28)
>       at ./cdk/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7780:51
>       at Kernel._wrapSandboxCode (./cdk/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8422:19)
>       at ./cdk/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7780:25
>       at Kernel._ensureSync (/Users/szym/bizgle/devops/cdk/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8395:20)
>       at Kernel.sinvoke (./cdk/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7779:26)
>       at KernelHost.processRequest (./cdk/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7458:28)
>       at KernelHost.run (./cdk/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7396:14)
>       at Immediate._onImmediate (./cdk/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7399:37)
>       at processImmediate (internal/timers.js:456:21)
> 
> The above exception was the direct cause of the following exception:
> 
> Traceback (most recent call last):
>   File "app.py", line 13, in <module>
>     CoreStack(
>   File "./cdk/.env/lib/python3.8/site-packages/jsii/_runtime.py", line 69, in __call__
>     inst = super().__call__(*args, **kwargs)
>   File "./cdk/server/infrastructure.py", line 29, in __init__
>     log_group = CloudWatchLogs(self, "CloudWatchLogs",
>   File "./cdk/.env/lib/python3.8/site-packages/jsii/_runtime.py", line 69, in __call__
>     inst = super().__call__(*args, **kwargs)
>   File "./devops/cdk/server/cloudwatch_logs.py", line 14, in __init__
>     es = elasticsearch.Domain.from_domain_attributes(
>   File "./cdk/.env/lib/python3.8/site-packages/aws_cdk/aws_elasticsearch/__init__.py", line 4796, in from_domain_attributes
>     return jsii.sinvoke(cls, "fromDomainAttributes", [scope, id, attrs])
>   File "./cdk/.env/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 125, in wrapped
>     return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
>   File "./cdk/.env/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 334, in sinvoke
>     response = self.provider.sinvoke(
>   File "./devops/cdk/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 354, in sinvoke
>     return self._process.send(request, InvokeResponse)
>   File "./cdk/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 321, in send
>     raise JSIIError(resp.error) from JavaScriptError(resp.stack)
> jsii.errors.JSIIError: Invalid URL: ${Token[TOKEN.172]}
> Subprocess exited with error 1

This is 🐛 Bug Report

@sysopcorner sysopcorner added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 13, 2020
@github-actions github-actions bot added the @aws-cdk/aws-elasticsearch Related to Amazon Elasticsearch Service label Oct 13, 2020
@iliapolo
Copy link
Contributor

@sysopcorner Indeed there is currently a hidden assumption that imported domains are initialized using concrete values. We will look into if this is strictly necessary or can we support tokens here as well.

In the meantime, may I ask why are you importing the domain and not passing a reference to the construct from the other stack? i.e:

export class DomainStack extends Stack {

  public readonly domain: elastic.Domain:

  constructor(scope: Construct, id: string) {
    this.domain = new elastic.Domain(...);
  }
}

In your other stack, you can accept the domain, CDK will take care of cross stack references.

export class AnotherStack extends Stack {
  constructor(scope: Construct, id: string, props: { domain: elastic.Domain }) {
    // treat props.domain here as you would if it was created in this stack.
  }
}

So In your app:

const domainStack = new DomainStack(...);
const anotherStack = new AnotherStack(..., { domain: domainStack.domain});

@iliapolo iliapolo added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2020
@GaganBhatia-Amplify
Copy link

@iliapolo I am facing a similar issue when I am trying to import the domain endpoint of ES.
In the above solution you proposed, we can only set String as Value of Outputs.
How can I reference the stack itself after import?

@iliapolo
Copy link
Contributor

iliapolo commented Dec 6, 2020

@GaganBhatia-Amplify I'm not suggesting to use the domain as an input/ouput, simply pass the object reference between the two stacks:

export class AnotherStack extends Stack {
  constructor(scope: Construct, id: string, props: { domain: elastic.Domain }) {
    // this is the reference, accepting it as a normal property.
    const domain = props.domain;
    
    // now just use the 'domain` constant exactly as you would if you created if by using `fromDomain...`
  }
}

@DidgetyTech
Copy link

DidgetyTech commented Feb 26, 2021

The static fromX in other resources are compatible with ImportValue and/or cdk.context.json, as the OP shows with SecurityGroups. It is surprising that these are not. Buckets, Users, Roles and more use this well established pattern. Not all stacks in an account are deployed in one cdk deploy action where passing refs through stack props is possible.

@DidgetyTech
Copy link

My team has a use case to import the Domain so that a Lambda can be granted to it and the url passed via Lambda environment variables. These permissions are rendered on the Lambda's IAM Role. We have several of these lambda stacks and one stack defining the Domain. They are deployed independently.

@smmnloes
Copy link

smmnloes commented Jun 8, 2021

+1
In the current state it is not possible to have a stack containing an ES-Domain be accessed by other stacks via exports, unless the stacks are deployed together (which in our case they are not, they live in different repos).
This would be a really useful feature if tokens would work.

@iliapolo iliapolo removed their assignment Jun 27, 2021
@BenChaimberg
Copy link
Contributor

duplicate of #15188
closed in #15219

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@BenChaimberg BenChaimberg added the duplicate This issue is a duplicate. label Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-elasticsearch Related to Amazon Elasticsearch Service bug This issue is a bug. duplicate This issue is a duplicate. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

No branches or pull requests

6 participants