-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(@aws-cdk/aws-events-triggers): introducing sqs target support in event rule #2683
Conversation
packages/@aws-cdk/aws-events-targets/test/sqs/integ.sqs-event-rule-target.ts
Outdated
Show resolved
Hide resolved
@rix0rrr thank you for your feedback. I'm sorry I didn't provide to you all the info about the error: the error is thrown when the template is not compliant - the test fail - I don't know if it is the
I fixed the code and the error is not there anymore: I was able to add the condition as you said, and the
This is the output provided by Cloudformation: Invalid value for the parameter Policy. (Service: AmazonSQS; Status Code: 400; Error Code: InvalidAttributeValue; Request ID: d05e3b85-7cb8-5a28-b8ae-6eee5581d891) |
I brought the changes of 0.33.0 in my branch. Package.json changes in peerDependencies needed for sqs integration |
Hello @made2591 , hello @rix0rrr !
Before that, we were doing This is the code I am using:
|
Even simpler: this works
this throws the error about cyclic dependency
|
@Visorgood I'm not 100%, but I think the error you are getting is due to the CDK lifecycle (see docs). When you define the targets of your rule, the rule doesn't exist yet. The permissions are granted in the Try to add the target manually after the creation of the rule:
and see what happens. If it solved, imagine this behaviour is not so far from the one you get with SAM when you have IAM permissions that need to be constrained to the Function itself: you have to split the role from the definition of the function, to have references available in two different steps in another point of the template. Hope to be helpful |
Doing |
Yes, I found what is wrong: it's due to the condition we put around the |
Btw, if someone wants to jump in and help in debugging, this is the stack I used to test:
and
This throws the error mentioned above: without boundaries conditions it doesn't. This is also the reason why with SNS Topic it works yet... |
Great news! Thanks a lot for the effort! |
Hello @made2591 ! I assume CDK 0.35 doesn't contain this fix yet? |
No, it doesn't: to be honest as I said to you I don't know if it's ok to remove that permission constraint - actually, there was interest in propagating it to other targets as well 😊 so, I'm still waiting for a feedback for someone else from AWS, just to validate a PR in case it has to be fixed in that way |
But then it means that this functionality although available in AWS will not be available via CDK? I mean the ability to integrate different stacks with CloudWatch Rules. Is there any other way to make this work, except putting everything into one stack? |
I've managed to work it around by creating a Lambda in the same stack with the Rule, and trigger that Lambda by the rule, instead of sending an SQS message. The Lambda in turn sends a message to the queue that is in the different stack - and this works and worked before. Of course this required me to create small code for that Lambda, but this is still not so bad. |
Extend the Target for Event Rule to SQS Queues.
This may be needed in situations where users want to create an Event Rule and have as a target an SQS Queue.
I extended the package @aws-cdk/aws-events-targets by introducing a new Typescript file https://github.com/made2591/aws-cdk/blob/feature/aws-events-targets-sqs/packages/%40aws-cdk/aws-events-targets/lib/sqs.ts and by following the same approach used for SNS Topic
I also wrote the respective tests in the
test
folder. The SqsParameters are still not available but it's a skeleton to synthesize a Simple Queue as a Target.closes #1786
Pull Request Checklist
design
folderBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.