5

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.

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

Comments

6

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

2 Comments

I am already using psql @pandelis but i am facing issues regarding "client_encoding" . I thought of asking it on a different thread and learn if there is anything which can be done from CLI or Powershell Cmdlets
Since this answer was written, Amazon Redshift has added the Redshift Data API. See the other answer for an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.