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" #31017

Closed
1 of 2 tasks
Rizxcviii opened this issue Aug 3, 2024 · 4 comments · Fixed by #29462
Closed
1 of 2 tasks
Labels
@aws-cdk/aws-events-targets effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@Rizxcviii
Copy link
Contributor

Rizxcviii commented Aug 3, 2024

Describe the feature

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 Information

Originally posted by @dirkgomez in #15712

Acknowledgements

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

CDK version used

2.151.0

Environment details (OS name and version, etc.)

Windows 11

@Rizxcviii Rizxcviii added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 3, 2024
@Rizxcviii
Copy link
Contributor Author

Rizxcviii commented Aug 3, 2024

@rix0rrr, I implemented your change that was recommended on the previous issue

@ashishdhingra ashishdhingra self-assigned this Aug 5, 2024
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 5, 2024
@ashishdhingra
Copy link
Contributor

AWS::Events::Rule Target does mention support for RedshiftDataParameters.

@Rizxcviii Thanks for opening this feature request and PR contribution.

@ashishdhingra ashishdhingra added effort/medium Medium work item – several days of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Aug 5, 2024
@ashishdhingra ashishdhingra removed their assignment Aug 5, 2024
@Rizxcviii
Copy link
Contributor Author

Hi @ashishdhingra, the original issue was marked as p1, this is the same issue as before

@mergify mergify bot closed this as completed in #29462 Aug 30, 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*
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 30, 2024
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.
Labels
@aws-cdk/aws-events-targets effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants