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

feat(iot): allow setting Actions of TopicRule #17110

Merged
merged 11 commits into from
Oct 28, 2021

Conversation

yamatatsu
Copy link
Contributor

I'm trying to implement aws-iot L2 Constructs.

This PR is the next step of #16681

refar:


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Oct 22, 2021

@github-actions github-actions bot added the @aws-cdk/aws-iot Related to AWS IoT label Oct 22, 2021
@yamatatsu yamatatsu force-pushed the aws-iot-rule-action branch from 7388b1c to f68be0a Compare October 22, 2021 05:21
@yamatatsu
Copy link
Contributor Author

I met following error on yarn build at aws-iot 🤔

error: [awslint:no-unused-type:@aws-cdk/aws-iot.ActionConfig] type or enum is not used by exported classes (declared at lib/action.ts:19)
error: [awslint:no-unused-type:@aws-cdk/aws-iot.IAction] type or enum is not used by exported classes (declared at lib/action.ts:7)

And I confirmed this error was suppressed when using the IAction in TopicRule.

Shall we implement using the IAction in TopicRule as possible as simple? (ex. not implement addAction())

@skinny85
Copy link
Contributor

Shall we implement using the IAction in TopicRule as possible as simple? (ex. not implement addAction())

Yes, we should implement using IAction in this PR too (add actions: IAction[] to TopicRuleProps, and then use it inside TopicRule). If you want to implement TopicRule.addAction() in this PR, I'm fine with that too.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting in "Request changes" to clear this one from my To-Do list. @yamatatsu please re-request my review when this is ready!

@yamatatsu yamatatsu force-pushed the aws-iot-rule-action branch from f68be0a to 9fcb358 Compare October 23, 2021 09:05
@mergify mergify bot dismissed skinny85’s stale review October 23, 2021 09:05

Pull request has been modified.

This change adds `IAction` to aws-iot for preparing to implemamt AWS IoT Rule
actions.
@yamatatsu yamatatsu force-pushed the aws-iot-rule-action branch from 9fcb358 to 7a72b32 Compare October 23, 2021 14:29
@yamatatsu yamatatsu requested a review from skinny85 October 24, 2021 01:20
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have the @aws-cdk/aws-iot-actions module on master, let's add a single implementation of IAction there, and use that in the ReadMe of @aws-cdk/aws-iot, instead of an anonymous object.

@mergify mergify bot dismissed skinny85’s stale review October 26, 2021 15:49

Pull request has been modified.

@yamatatsu yamatatsu requested a review from skinny85 October 26, 2021 17:03
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @yamatatsu! Minor suggestions before we merge this in.

packages/@aws-cdk/aws-iot-actions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iot-actions/lib/lambda-action.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iot-actions/lib/lambda-action.ts Outdated Show resolved Hide resolved
constructor(private readonly lambdaFn: lambda.IFunction) {}

bind(rule: iot.ITopicRule): iot.ActionConfig {
this.lambdaFn.addPermission('invokedByAwsIotRule', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use function.grantInvoke() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skinny85 Thank you for your review!

In my understanding, using addPermission() is better. Because a lambda resource policy created by using grantInvoke() is more lax than using addPermission().

As described in this document, lambda resource policy fields sourceAccount and sourceArn are required (or recommended?). But functions.grantInvoke() cannot add sourceAccount and sourceArn as this code.

For confirmation, I tried following code instead of this.func.addPermission():

this.func.grantInvoke({ grantPrincipal: new iam.ServicePrincipal('iot.amazonaws.com') });

Then there is template difference as following:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, fair enough 🙂.

packages/@aws-cdk/aws-iot/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iot/lib/topic-rule.ts Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
@mergify mergify bot dismissed skinny85’s stale review October 27, 2021 07:42

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost perfect @yamatatsu! Change the account in LambdaAction, and rename it to LambdaFunctionAction, and we'll merge this in!

packages/@aws-cdk/aws-iot-actions/lib/lambda-action.ts Outdated Show resolved Hide resolved
*/
constructor(private readonly func: lambda.IFunction) {}

bind(rule: iot.ITopicRule): iot.ActionConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bind(rule: iot.ITopicRule): iot.ActionConfig {
bind(topicRule: iot.ITopicRule): iot.ActionConfig {

*
* @param rule The TopicRule that would trigger this action.
*/
bind(rule: ITopicRule): ActionConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bind(rule: ITopicRule): ActionConfig;
bind(topicRule: ITopicRule): ActionConfig;

/**
* The action to invoke an AWS Lambda function, passing in an MQTT message.
*/
export class LambdaAction implements iot.IAction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to LambdaFunctionAction.

@mergify mergify bot dismissed skinny85’s stale review October 27, 2021 22:16

Pull request has been modified.

@yamatatsu yamatatsu requested a review from skinny85 October 28, 2021 07:20
@yamatatsu
Copy link
Contributor Author

yamatatsu commented Oct 28, 2021

@skinny85 I've addressed the comments!👍

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect @yamatatsu, thanks for incorporating all of my comments!

@skinny85 skinny85 changed the title feat(iot): Add IAction feat(iot): add the concept of Actions to TopicRule Oct 28, 2021
@skinny85 skinny85 changed the title feat(iot): add the concept of Actions to TopicRule feat(iot): allow setting Actions of TopicRule Oct 28, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 28, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 0cabb9f into aws:master Oct 28, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 28, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: c86e5f0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@yamatatsu yamatatsu deleted the aws-iot-rule-action branch November 5, 2021 01:39
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
I'm trying to implement aws-iot L2 Constructs.

This PR is the next step of aws#16681

refar: 
- aws#16681 (comment)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iot Related to AWS IoT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants