Skip to content

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

@dirkgomez

Description

@dirkgomez

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions