Skip to content

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

@Rizxcviii

Description

@Rizxcviii

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions