简体   繁体   中英

How to run Queries on Redshift Database using AWS CLI

I want to run queries by passing them as string to some supported command of AWS through its CLI.

I can see that the commands specific to AWS Redshift mentioned doesnt have anything which says that it can execute commands remotely

Link : https://docs.aws.amazon.com/cli/latest/reference/redshift/index.html

Need help on this.

You need to use psql. There is no API interface to redshift.

Redshift is based loosely on postgresql however so you can connect to the cluster using the psql command line tool.

https://docs.aws.amazon.com/redshift/latest/mgmt/connecting-from-psql.html

You can use Redshift Data API to execute queries on Redshift using AWS CLI.

aws redshift-data execute-statement 
    --region us-west-2 
    --secret arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn 
    --cluster-identifier mycluster-test 
    --sql "select * from stl_query limit 1" 
    --database dev

https://aws.amazon.com/about-aws/whats-new/2020/09/announcing-data-api-for-amazon-redshift/ https://docs.aws.amazon.com/redshift/latest/mgmt/data-api.html https://docs.aws.amazon.com/cli/latest/reference/redshift-data/index.html#cli-aws-redshift-data

There is now a query tool (like pgcli) for Redshift call RSQL: https://aws.amazon.com/about-aws/whats-new/2021/09/amazon-redshift-rsql-amazon-redshift-clusters-databases/

It's not quite the CLI, but depending in your use case, it may fit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM