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

Fn.GetAtt Expected Scalar got Intrinsic #4870

Closed
joekiller opened this issue Nov 5, 2019 · 3 comments

Comments

@joekiller
Copy link

@joekiller joekiller commented Nov 5, 2019

This might be another example of #2005. When I am trying to use values from CfnInclude resources I get jsii.errors.JSIIError: Expected Scalar, got {"$jsii.byref":"@aws-cdk/core.Intrinsic@10003"}

Reproduction Steps

from aws_cdk import (
    core
)

app = core.App()
stack = core.Stack(app, "stack")
core.CfnInclude(stack, "RawStack", template={
    "Resources": {
        "MySnsTopic": {
            "Type": "AWS::SNS:Topic"
        }
    }
}
)
core.CfnOutput(stack, "TopicName", value=core.Fn.get_att('MySnsTopic', 'TopicName'))
app.synth()

Error Log

jsii.errors.JavaScriptError: 
  Error: Expected Scalar, got {"$jsii.byref":"@aws-cdk/core.Intrinsic@10003"}
      at Object.deserialize (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:12601:23)
      at Kernel._toSandbox (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7353:61)
      at /tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:12777:29
      at mapValues (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:13006:27)
      at Object.deserialize (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:12773:20)
      at Kernel._toSandbox (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7353:61)
      at /tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7406:33
      at Array.map (<anonymous>)
      at Kernel._boxUnboxParameters (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7406:19)
      at Kernel._wrapSandboxCode (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7447:19)
      at Kernel._create (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6992:26)
      at Kernel.create (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6746:21)
      at KernelHost.processRequest (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6521:28)
      at KernelHost.run (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6464:14)
      at Immediate._onImmediate (/tmp/test/venv/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6467:37)
      at processImmediate (internal/timers.js:439:21)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "app.py", line 15, in <module>
    core.CfnOutput(stack, "TopicName", value=core.Fn.get_att('MySnsTopic', 'TopicName'))
  File "/tmp/test/venv/lib/python3.7/site-packages/jsii/_runtime.py", line 66, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/tmp/test/venv/lib/python3.7/site-packages/aws_cdk/core/__init__.py", line 3189, in __init__
    jsii.create(CfnOutput, self, [scope, id, props])
  File "/tmp/test/venv/lib/python3.7/site-packages/jsii/_kernel/__init__.py", line 214, in create
    overrides=overrides,
  File "/tmp/test/venv/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 331, in create
    return self._process.send(request, CreateResponse)
  File "/tmp/test/venv/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 316, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Expected Scalar, got {"$jsii.byref":"@aws-cdk/core.Intrinsic@10003"}

Environment

  • CLI Version : 1.15.0 (build bdbe3aa)
  • Framework Version: 1.15.0
  • OS : Arch Linux
  • Language : Python 3.7

Other

This really holds up being able to integrate or build upon old stacks.


This is 🐛 Bug Report

@RomainMuller

This comment has been minimized.

Copy link
Contributor

@RomainMuller RomainMuller commented Nov 8, 2019

The value of CfnOutput must be a str, and you're passing some instance of an intrinsic function. You have to expressedly stringify that.

@joekiller

This comment has been minimized.

Copy link
Author

@joekiller joekiller commented Nov 8, 2019

thanks @RomainMuller. Updating the get_att call in core.CfnOutput as follows fixed it up.

from:

core.Fn.get_att('MySnsTopic', 'TopicName')

to:

core.Fn.get_att('MySnsTopic', 'TopicName').to_string()
@joekiller joekiller closed this Nov 8, 2019
@joekiller

This comment has been minimized.

Copy link
Author

@joekiller joekiller commented Nov 8, 2019

In retrospec @RomainMuller is would be nice if get_att implemented pthon's __str__ method because I did try str(core.Fn.get_att('MySnsTopic', 'TopicName')) and f'{core.Fn.get_att('MySnsTopic', 'TopicName')}' which returned the __repr__ of the object instead of the string. ( <aws_cdk.core.Intrinsic object at 0x7f0126872a50>)

I'll open another issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.