RedshiftQuery

class aws_cdk.aws_events_targets.RedshiftQuery(cluster_arn, *, database, sql, db_user=None, dead_letter_queue=None, input=None, role=None, secret=None, send_event_bridge_event=None, statement_name=None)

Bases: object

Schedule an Amazon Redshift Query to be run, using the Redshift Data API.

If you would like Amazon Redshift to identify the Event Bridge rule, and present it in the Amazon Redshift console, append a QS2- prefix to both statementName and ruleName.

ExampleMetadata:

infused

Example:

import aws_cdk.aws_redshiftserverless as redshiftserverless

# workgroup: redshiftserverless.CfnWorkgroup


rule = events.Rule(self, "Rule",
    schedule=events.Schedule.rate(cdk.Duration.hours(1))
)

dlq = sqs.Queue(self, "DeadLetterQueue")

rule.add_target(targets.RedshiftQuery(workgroup.attr_workgroup_workgroup_arn,
    database="dev",
    dead_letter_queue=dlq,
    sql=["SELECT * FROM foo", "SELECT * FROM baz"]
))
Parameters:
  • cluster_arn (str) – The ARN of the Amazon Redshift cluster.

  • database (str) – The Amazon Redshift database to run the query against.

  • sql (Sequence[str]) – The SQL queries to be executed. Each query is run sequentially within a single transaction; the next query in the array will only execute after the previous one has successfully completed. - When multiple sql queries are included, this will use the batchExecuteStatement API. Therefore, if any statement fails, the entire transaction is rolled back. - If a single SQL statement is to be executed, this will use the executeStatement API. Default: - No SQL query is specified

  • db_user (Optional[str]) – The Amazon Redshift database user to run the query as. This is required when authenticating via temporary credentials. Default: - No Database user is specified

  • dead_letter_queue (Optional[IQueue]) – The queue to be used as dead letter queue. Default: - No dead letter queue is specified

  • input (Optional[RuleTargetInput]) – The input to the state machine execution. Default: - the entire EventBridge event

  • role (Optional[IRole]) – The IAM role to be used to execute the SQL statement. Default: - a new role will be created.

  • secret (Optional[ISecret]) – The secret containing the password for the database user. This is required when authenticating via Secrets Manager. If the full secret ARN is not specified, this will instead use the secret name. Default: - No secret is specified

  • send_event_bridge_event (Optional[bool]) – Should an event be sent back to Event Bridge when the SQL statement is executed. Default: false

  • statement_name (Optional[str]) – The name of the SQL statement. You can name the SQL statement for identitfication purposes. If you would like Amazon Redshift to identify the Event Bridge rule, and present it in the Amazon Redshift console, append a QS2- prefix to the statement name. Default: - No statement name is specified

Methods

bind(rule, _id=None)

Returns the rule target specification.

NOTE: Do not use the various inputXxx options. They can be set in a call to addTarget.

Parameters:
  • rule (IRule) –

  • _id (Optional[str]) –

Return type:

RuleTargetConfig