如何使用AWS CLI在Redshift数据库上运行查询

Sai*_*aju 4 amazon-s3 amazon-web-services amazon-redshift

我想通过将查询作为字符串通过其CLI传递给AWS的某些受支持的命令来运行查询。

我可以看到提到的特定于AWS Redshift的命令没有任何内容,它可以远程执行命令

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

需要帮助。

小智 6

您需要使用psql。没有可用于redshift的API接口。

Redshift宽松地基于postgresql,因此您可以使用psql命令行工具连接到集群。

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


Piy*_*gra 6

您可以使用 Redshift Data API 通过 AWS CLI 在 Redshift 上执行查询。

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
Run Code Online (Sandbox Code Playgroud)

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