Skip to content

Instantly share code, notes, and snippets.

@borja-munoz
Created May 2, 2021 16:30
Show Gist options
  • Save borja-munoz/87991884b9c7ecdf5b00f5c4481dbc01 to your computer and use it in GitHub Desktop.
Save borja-munoz/87991884b9c7ecdf5b00f5c4481dbc01 to your computer and use it in GitHub Desktop.
Execute SQL stamement using Redshift Data API
import logging
import boto3
from botocore.exceptions import ClientError
client = boto3.client('redshift-data')
try:
# Execute the SQL statement
query_response = client.execute_statement(
ClusterIdentifier=cluster_identifier,
Database=database,
SecretArn=secret_arn,
Sql=("COPY {0} FROM '{1}' "
"IAM_ROLE '{2}' "
"FORMAT CSV IGNOREHEADER 1;").format(table_name, csv_file_path, redshift_role_arn)
)
except ClientError as e:
logging.error(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment