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

events.Rule has no way to access the rule name #3809

Closed
jeshan opened this issue Aug 27, 2019 · 4 comments · Fixed by #4252
Closed

events.Rule has no way to access the rule name #3809

jeshan opened this issue Aug 27, 2019 · 4 comments · Fixed by #4252
Assignees
Labels
bug This issue is a bug. guidance Question that needs advice or information. package/awscl Cross-cutting issues related to the AWS Construct Library

Comments

@jeshan
Copy link

jeshan commented Aug 27, 2019

Hi,
Looking at the Tokens doc page:
https://docs.aws.amazon.com/cdk/latest/guide/tokens.html?shortFooter=true
It's unclear how we could manipulate a property to be used in another resource.
For example, a cloudwatch events rule returns the ruleArn property.
However, I need the rule name property instead (which is not available in the rule object).

I tried to get the name as a sbustring from the arn in Python syntax like this:

rule = Rule(self, 'rule', targets=[LambdaFunction(fn)], schedule=Schedule.rate(Duration.days(1)))
rule.rule_arn # works
rule.rule_arn[5:10] # not good

The last statement does not work since the arn actually looks something like ${Token[TOKEN.219]} at runtime.
I'm thinking that maybe I should be using Token/Lazy/Produce here but I can't figure it out.

@jeshan jeshan added the needs-triage This issue or PR still needs to be triaged. label Aug 27, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 27, 2019

You can use stack.parseArn() to take apart the ARN into components, from which you can get the name.

Would you normally use { Ref: MyRule } in a CloudFormation template? If so, this is actually a missing property on the Rule object.

@rix0rrr rix0rrr added package/awscl Cross-cutting issues related to the AWS Construct Library bug This issue is a bug. guidance Question that needs advice or information. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 27, 2019
@jeshan
Copy link
Author

jeshan commented Aug 27, 2019

parseArn works well for me, thanks.

Would you normally use { Ref: MyRule } in a CloudFormation template

Yes, correct. Here is an example:

image

With the CDK, we can't just reference the rule object, as it throws the error (invoked through Python):

jsii.errors.JavaScriptError: 
  Error: Resolution error: Resolution error: Trying to resolve() a Construct at /Resources/${Token[production.backup-results.fn-failed-invocations-too-high.Resource.LogicalID.543]}/Properties/dimensions/0/value/node.
  Object creation stack:
    at new Intrinsic (/tmp/jsii-kernel-0K7vPp/node_modules/@aws-cdk/core/lib/private/intrinsic.js:20:44)
    at new PostResolveToken (/tmp/jsii-kernel-0K7vPp/node_modules/@aws-cdk/core/lib/util.js:72:9)

@jeshan
Copy link
Author

jeshan commented Aug 27, 2019

@rix0rrr what do you think? Should I close this one and open a new one for the missing ref?

@NGL321
Copy link
Contributor

NGL321 commented Aug 27, 2019

@jeshan This issue should be fine to use to track the fix!

😸

@rix0rrr rix0rrr changed the title How to operate on resolved values? events.Rule has no way to access the rule name Aug 28, 2019
rix0rrr added a commit that referenced this issue Sep 26, 2019
`ruleName` was missing. Add it.

Fixes #3809.
@mergify mergify bot closed this as completed in #4252 Sep 27, 2019
mergify bot pushed a commit that referenced this issue Sep 27, 2019
`ruleName` was missing. Add it.

Fixes #3809.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. guidance Question that needs advice or information. package/awscl Cross-cutting issues related to the AWS Construct Library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants