-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Proposal: Token.toString() #24
Comments
At least it would help debuggability. However, to make it do "the right thing" we'd need to change the context as well. We could make the Token stringify to As in, it would need to become this: rule.addTarget(topic, {
textTemplate: new FnSub(`Hello, bucket ${bucket.bucketName}`)
}); Still a pretty good addition because right now it's very inconvenient to use |
I would actually not use FnSub for the substitution but rather implement our own substitution scheme in Here's some way we can implement this: The first time a token is |
My point is, if it's a Not saying it couldn't be done, but it might introduce some nasty edge cases. |
Good point, but I would just use |
It would definitely be an interesting experiment. Do we expose |
Tokens (such as resource attributes) can now be implicitly converted into strings. Parameters and attributes can now be combined into larger strings using the native string facilities of the host language. The process will be reversed by the resolve() function during synthesis, which will split the string up again into string literals and CloudFormation intrinsics. The same transformation is applied during JSON.stringify(), so that Tokens in a complex JSON structure are preserved. Fixes #24 and #168.
Tokens (such as resource attributes) can now be implicitly converted into strings. This allows using any late-bound CloudFormation value where strings can be used in the host language, and the native string facilities of the host language can be used as well to further process strings. The process is reversed by the resolve() function during synthesis, which will split the string up again into string literals and CloudFormation intrinsics (combined by `{Fn::Join}`). Introduces `CloudFormationJSON.stringify` to produce a similar result, but used for JSON-encoding of complex objects that may contain Tokens. This is used in JSON-encoded policy statements, CloudFormation actions, state machine definitions, and more. Additional changes: - Add a VSCode launch config (with a helper script) to directly debug a unit test from within the IDE. This allows setting breakpoints. - SecretParameter no longer duckily implements Token; this will not work in other jsii languages anyway. - Nested `FnConcat` structures will be flattened in the CloudFormation output. Fixes #24 and #168.
References to runtime attributes of resources (the name of the bucket, the ARN of a topic, etc). At the moment, these are represented a
Token
objects. Tokens are objects that have aresolve
method. When a stack is synthesized, every toke node in the JSON document is resolved and the result is plugged into the document.One of the usability issues we are experiencing with tokens is that it is very common to need to format strings that reference them. For example:
Sadly, this code will not behave as expected.
bucket.bucketName
is an object of typeBucketName
, which extendsToken
, and not a string. The resulting string would be"Hello, bucket [Object]
".If we had a
toString
method for tokens, which would have been meaningful and substitutable during synthesis, the above code would behave as expected.The text was updated successfully, but these errors were encountered: