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

(aws-events-targets): Add scheduling a Redshift query to "Event Targets for Amazon EventBridge" #15712

Closed
1 of 2 tasks
dirkgomez opened this issue Jul 22, 2021 · 9 comments · Fixed by #29462 · 4 remaining pull requests
Closed
1 of 2 tasks

(aws-events-targets): Add scheduling a Redshift query to "Event Targets for Amazon EventBridge" #15712

dirkgomez opened this issue Jul 22, 2021 · 9 comments · Fixed by #29462 · 4 remaining pull requests
Labels
@aws-cdk/aws-events Related to CloudWatch Events @aws-cdk/aws-events-targets @aws-cdk/aws-redshift Related to Amazon Redshift closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1

Comments

@dirkgomez
Copy link
Contributor

The event targets module has implemented a couple of event targets but is missing some, one of which is scheduling a Redshift query.

Use Case

Schedule RedShift queries.

Proposed Solution

Cloudformation already allows for this, here's my current implementation which isn't yet very CDKish:

    const redshiftClusterArn = ...

    const redshiftRole = new iam.Role(this, 'RedshiftEventRole', {
      assumedBy: new iam.CompositePrincipal(new iam.ServicePrincipal('events.amazonaws.com'), new iam.AccountRootPrincipal()),
      managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonRedshiftDataFullAccess')],
    });

    redshiftRole.addToPolicy(
      new iam.PolicyStatement({
        resources: [redshiftClusterArn],
        actions: [
          'sts:AssumeRole',
        ],
      }),
    );

    const redshiftSecret = ...
    redshiftSecret.grantRead(redshiftRole);

    const loader = new events.Rule(this, 'eventRule', {
      schedule: events.Schedule.expression('cron(2 */1 * * ? *)'),
    });

    const cfnLoader = loader.node.defaultChild as events.CfnRule;
    cfnLoader.targets = [{
      arn: `${redshiftClusterArn}`,
      roleArn: redshiftRole.roleArn,
      id: 'loader',
      redshiftDataParameters: {
        database: 'databasename',
        sql: 'call myprocedure()',
        secretManagerArn: redshiftSecret.secretArn,
      },
    }];


Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@dirkgomez dirkgomez added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 22, 2021
@github-actions github-actions bot added @aws-cdk/aws-events Related to CloudWatch Events @aws-cdk/aws-events-targets @aws-cdk/aws-redshift Related to Amazon Redshift labels Jul 22, 2021
@njlynch njlynch added effort/medium Medium work item – several days of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Jul 23, 2021
@njlynch njlynch removed their assignment Jul 23, 2021
@njlynch
Copy link
Contributor

njlynch commented Jul 23, 2021

Thanks for the feature request and sample code, @dirkgomez .

We welcome community contributions! If you are able, we encourage you to contribute. If you decide to contribute, please start an engineering discussion in this issue to ensure there is a commonly understood design before submitting code. This will minimize the number of review cycles and get your code merged faster.

@dirkgomez
Copy link
Contributor Author

@njlynch I will try to figure out how a simple event target works, the CodeBuildProject looks like a good start.

@dirkgomez
Copy link
Contributor Author

@njlynch I hit the first roadblock (which may have been the reason to not implement this in the first place).

I added aws-redshift to the dependencies and the peerDependencies in package.json and I get this error:

In package package.json

  • [no-experimental-dependencies] It is not allowed to depend on experimental modules. @aws-cdk/aws-events-targets added a dependency on experimental module @aws-cdk/aws-redshift
    Error: Some package.json files had errors

Can you please advise me if it makes sense to continue and if so, how? Thanks!

@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 11, 2021

For now, it probably makes the most sense to replace clusterName and queryNqme (or whatever the parameters are) as string, instead of as typed objects. They should be replaced with typed references to ICluster and IQuery when the redshift module is stabilized (let's add a comment saying so, and potentially a GitHub ticket, so we don't forget)

@rix0rrr rix0rrr removed their assignment Aug 11, 2021
@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Aug 11, 2022
@Rizxcviii
Copy link
Contributor

Just created a PR for this

@manmartgarc
Copy link

Why is this closed? There's an open PR 🤔

@moelasmar
Copy link
Contributor

closed as duplicate of issue #31017

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2024
mergify bot pushed a commit that referenced this issue Aug 30, 2024
### Issue # (if applicable)

Closes #15712.
Closes #31017.

### Reason for this change

`RedshiftDataParameters` allow for a redshift query to be scheduled. This feature adds that in

### Description of changes

Added in the event target and the parameter into `aws-events`

### Description of how you validated changes

Added unit tests + integration test

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
xazhao pushed a commit to xazhao/aws-cdk that referenced this issue Sep 12, 2024
### Issue # (if applicable)

Closes aws#15712.
Closes aws#31017.

### Reason for this change

`RedshiftDataParameters` allow for a redshift query to be scheduled. This feature adds that in

### Description of changes

Added in the event target and the parameter into `aws-events`

### Description of how you validated changes

Added unit tests + integration test

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*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 subscribe to this conversation on GitHub. Already have an account? Sign in.