-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
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 a resolve 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:
const bucket = new s3.Bucket(this, 'MyBucket');
const rule = new cloudwatch.EventRule(this, 'Schedule', { scheduleExpression: 'rate(1 minute)' });
rule.addTarget(topic, {
textTemplate: `Hello, bucket ${bucket.bucketName}`
});Sadly, this code will not behave as expected. bucket.bucketName is an object of type BucketName, which extends Token, 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.