Created
May 2, 2021 16:30
-
-
Save borja-munoz/87991884b9c7ecdf5b00f5c4481dbc01 to your computer and use it in GitHub Desktop.
Execute SQL stamement using Redshift Data API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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