Skip to main content

snippets_py

Integration

New integration from credential
aws_redshift_client = yepcode.integration.aws_redshift("credential-slug")
New integration from plain authentication data
import boto3

session = boto3.Session(
aws_access_key_id="accessKeyId",
aws_secret_access_key="secretAccessKey",
region_name="region"
)
aws_redshift_client = session.client("redshift-data")

Execute Statement

Execute statement
response = aws_redshift_client.execute_statement(
ClusterIdentifier="cluster-name",
Database="db-name",
DbUser="db-user",
Sql="sql"
)

print(response.get("Id"))

Execute Statement with Parameters

Execute statement with parameters
sql = "select * from users where id = :id"
params = [{"name": "id", "value": "1"}]

response = aws_redshift_client.execute_statement(
ClusterIdentifier="cluster-name",
Database="db-name",
DbUser="db-user",
Sql=sql,
Parameters=params
)

print(response.get("Id"))

Describe Statement

Describe statement
response = aws_redshift_client.describe_statement(Id="statement-id")

print(response.get("Status"))

Get Statement Result

Get statement result
response = aws_redshift_client.get_statement_result(Id="statement-id")

for record in response.get("Records", []):
print(record)

List Statements

List statements
result = aws_redshift_client.list_statements()

for statement in result.get("Statements", []):
print(statement)