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

Support Kinesis Streams as an Event Rule target #2997

Closed
1 of 5 tasks
0xdabbad00 opened this issue Jun 21, 2019 · 4 comments Β· Fixed by #8176
Closed
1 of 5 tasks

Support Kinesis Streams as an Event Rule target #2997

0xdabbad00 opened this issue Jun 21, 2019 · 4 comments Β· Fixed by #8176
Assignees
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch @aws-cdk/aws-events-targets @aws-cdk/aws-kinesis Related to Amazon Kinesis effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. in-progress This issue is being actively worked on.

Comments

@0xdabbad00
Copy link

The CDK does not yet support that, as shown here: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.IRuleTarget.html

  • What is the motivation / use case for changing the behavior or adding this feature?
    I want to send CloudWatch Events to a Kinesis Stream. This is needed for GuardDuty event collection as shown here: https://summitroute.com/blog/2019/03/06/guardduty_event_collection_via_cloudwatch_events/

  • Please tell us about your environment:

    • CDK CLI Version: 0.35.0
    • Module Version: aws-events
    • OS: [all ]
    • Language: [ Javascript ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

@NGL321 NGL321 added feature-request A feature should be added or improved. @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch @aws-cdk/aws-kinesis Related to Amazon Kinesis labels Jun 21, 2019
@NGL321
Copy link
Contributor

NGL321 commented Jun 21, 2019

Hi Scott, thank you for reaching out!

We are currently pausing work on most new FRs and community PRs for a few weeks while we work towards stabilization and tuning to meet our consistency guidelines. Please feel free to discuss here, or put in a PR if you feel this is a problem you can resolve.

@0xdabbad00
Copy link
Author

Thanks for the response. I was able to work around this for now using the "escape hatch" concept described here: https://docs.aws.amazon.com/cdk/latest/guide/cfn_layer.html

@eladb eladb self-assigned this Aug 12, 2019
@eladb eladb assigned rix0rrr and unassigned eladb Sep 3, 2019
@NicoSorrenti
Copy link

@0xdabbad00 Scott, could you please give me a little insight on how you managed to do that? I'm looking on the link you sent, and the AWS Resource and Property Types Reference, but I can't find where that Kinesis event is. Thanks in advance

@0xdabbad00
Copy link
Author

@NicoSorrenti The following creates two CloudWatch Event rules. One for GuardDuty, Trusted Adisor, and test events, and one for CloudTrail events.

// Create IAM Role for CloudWatch Events to send to the Kinesis Stream
    const event_role = new iam.Role(this, "event_role", {
      assumedBy: new iam.ServicePrincipal('events.amazonaws.com')
    });

    event_role.addToPolicy(new iam.PolicyStatement({
      resources: [RECORDS_SOURCE],
      actions: ['kinesis:PutRecord*']
    }));

    // Create rule to send GuardDuty, TrustedAdvisor, heartbeat, and test_events to our Kinesis Stream
    // Some of the needed functionality does not exist in the CDK yet and must be over-ridden
    var guardduty_rule = new events.Rule(this, "guardduty_rule", {
      ruleName: "guardduty_rule",
      schedule: events.Schedule.expression("rate(30 minutes)"),  // Ignore this schedule, it will be over-ridden
      description: "Collects GuardDuty, TrustedAdvisor, heartbeat, and test events"
    });

    var guardduty_rule_resource = guardduty_rule.node.findChild('Resource');

    guardduty_rule_resource.addOverride('Properties.ScheduleExpression', undefined);
    guardduty_rule_resource.addOverride('Properties.EventPattern', 
      { source: [
        "aws.guardduty", 
        "aws.trustedadvisor",
        "event_test",
        "event_forwarder"]
      }
    );
    guardduty_rule_resource.addOverride('Properties.Targets', 
      [{
        Arn: RECORDS_SOURCE,
        Id: "target",
        RoleArn: event_role.roleArn
      }]
    );

    // Create rule to send CloudTrail events to our Kinesis Stream
    var cloudtrail_rule = new events.Rule(this, "cloudtrail_rule", {
      ruleName: "cloudtrail_rule",
      schedule: events.Schedule.expression("rate(30 minutes)"), // Ignore this schedule, it will be over-ridden
      description: "Collects CloudTrail events"
    });

    var cloudtrail_rule_resource = cloudtrail_rule.node.findChild('Resource');

    cloudtrail_rule_resource.addOverride('Properties.ScheduleExpression', undefined);
    cloudtrail_rule_resource.addOverride('Properties.EventPattern', 
      { "detail-type": ["AWS API Call via CloudTrail"] }
    );
    cloudtrail_rule_resource.addOverride('Properties.Targets', 
      [{
        Arn: RECORDS_SOURCE,
        Id: "target",
        RoleArn: event_role.roleArn
      }]
    );

RECORDS_SOURCE is a string for the ARN for the Kinesis Stream. I wrote this 4 months ago, so there may be some updates needed for newer versions of the CDK as it looks like I was using the CDK v0.34.0.

@rix0rrr rix0rrr added the effort/medium Medium work item – several days of effort label Jan 23, 2020
@SomayaB SomayaB added in-progress This issue is being actively worked on. @aws-cdk/aws-events-targets labels May 26, 2020
@mergify mergify bot closed this as completed in #8176 Jun 2, 2020
mergify bot pushed a commit that referenced this issue Jun 2, 2020
closes #2997


----

*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-cloudwatch Related to Amazon CloudWatch @aws-cdk/aws-events-targets @aws-cdk/aws-kinesis Related to Amazon Kinesis effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. in-progress This issue is being actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants