데이터 API 호출 - Amazon Redshift

데이터 API 호출

Data API 또는 AWS CLI를 호출하여 클러스터 또는 서버리스 작업 그룹에서 SQL 문을 실행할 수 있습니다. SQL 문을 실행하는 프라이머리 작업은 Amazon Redshift Data API 참조ExecuteStatementBatchExecuteStatement입니다. Data API는 AWS SDK에서 지원되는 프로그래밍 언어를 지원합니다. 이에 대한 자세한 내용은 AWS 기반의 도구를 참조하세요.

Data API 호출의 코드 예제를 보려면 GitHub에서 Getting Started with Redshift Data API를 참조하세요. 이 리포지토리에는 AWS Lambda를 사용하여 Amazon EC2, AWS Glue Data Catalog 및 Amazon SageMaker Runtime에서 Amazon Redshift 데이터에 액세스하는 예가 있습니다. 프로그래밍 언어의 예로는 Python, Go, Java 및 Javascript가 있습니다.

AWS CLI를 사용하여 Data API를 호출할 수 있습니다.

다음 예에서는 AWS CLI를 사용하여 Data API를 호출합니다. 예제를 실행하려면 환경에 맞게 파라미터 값을 편집합니다. 많은 예제에서 cluster-identifier가 클러스터에 대해 실행되도록 제공됩니다. 서버리스 작업 그룹에 대해 실행할 때는 workgroup-name을 대신 제공해야 합니다. 이 예에서는 몇 가지 Data API 작업을 보여줍니다. 자세한 내용은 AWS CLI 명령 참조를 참조하세요.

다음 예의 명령은 가독성을 위해 분할되고 형식이 지정되었습니다.

SQL 문을 실행하려면

SQL 문을 실행하려면 aws redshift-data execute-statement AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

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

다음은 이 응답의 예입니다.

{ "ClusterIdentifier": "mycluster-test", "CreatedAt": 1598323175.823, "Database": "dev", "Id": "c016234e-5c6c-4bc5-bb16-2c5b8ff61814", "SecretArn": "arn:aws:secretsmanager:us-west-2:123456789012:secret:yanruiz-secret-hKgPWn" }

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

aws redshift-data execute-statement --region us-west-2 --db-user myuser --cluster-identifier mycluster-test --database dev --sql "select * from stl_query limit 1"

다음은 이 응답의 예입니다.

{ "ClusterIdentifier": "mycluster-test", "CreatedAt": 1598306924.632, "Database": "dev", "DbUser": "myuser", "Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766" }

다음 AWS CLI 명령은 서버리스 작업 그룹에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

aws redshift-data execute-statement --database dev --workgroup-name myworkgroup --sql "select 1;"

다음은 이 응답의 예입니다.

{ "CreatedAt": "2022-02-11T06:25:28.748000+00:00", "Database": "dev", "DbUser": "IAMR:RoleName", "Id": "89dd91f5-2d43-43d3-8461-f33aa093c41e", "WorkgroupName": "myworkgroup" }

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는AWS Secrets Manager 인증 방법과 멱등성 토큰을 사용합니다.

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 --client-token b855dced-259b-444c-bc7b-d3e8e33f94g1

다음은 이 응답의 예입니다.

{ "ClusterIdentifier": "mycluster-test", "CreatedAt": 1598323175.823, "Database": "dev", "Id": "c016234e-5c6c-4bc5-bb16-2c5b8ff61814", "SecretArn": "arn:aws:secretsmanager:us-west-2:123456789012:secret:yanruiz-secret-hKgPWn" }

파라미터가 있는 SQL 문을 실행하려면

SQL 문을 실행하려면 aws redshift-data execute-statement AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다. SQL 텍스트에는 명명된 파라미터 distance가 있습니다. 이 경우, 조건자에 사용되는 거리는 5입니다. SELECT 문에서는 열 이름에 대해 명명된 파라미터를 조건자에서만 사용할 수 있습니다. SQL 문의 명명된 파라미터 값은 parameters 옵션에 지정됩니다.

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 ratecode FROM demo_table WHERE trip_distance > :distance" --parameters "[{\"name\": \"distance\", \"value\": \"5\"}]" --database dev

다음은 이 응답의 예입니다.

{ "ClusterIdentifier": "mycluster-test", "CreatedAt": 1598323175.823, "Database": "dev", "Id": "c016234e-5c6c-4bc5-bb16-2c5b8ff61814", "SecretArn": "arn:aws:secretsmanager:us-west-2:123456789012:secret:yanruiz-secret-hKgPWn" }

다음 예에서는 샘플 데이터베이스의 EVENT 테이블을 사용합니다. 자세한 내용은 Amazon Redshift 데이터베이스 개발자 안내서EVENT 테이블을 참조하세요.

데이터베이스에 EVENT 테이블이 없으면 다음과 같이 Data API를 사용하여 생성할 수 있습니다.

aws redshift-data execute-statement --database dev --cluster-id my-test-cluster --db-user awsuser --sql "create table event( eventid integer not null distkey, venueid smallint not null, catid smallint not null, dateid smallint not null sortkey, eventname varchar(200), starttime timestamp)"

다음 명령은 EVENT 테이블에 한 행을 삽입합니다.

aws redshift-data execute-statement --database dev --cluster-id my-test-cluster --db-user awsuser --sql "insert into event values(:eventid, :venueid::smallint, :catid, :dateid, :eventname, :starttime)" --parameters "[{\"name\": \"eventid\", \"value\": \"1\"}, {\"name\": \"venueid\", \"value\": \"1\"}, {\"name\": \"catid\", \"value\": \"1\"}, {\"name\": \"dateid\", \"value\": \"1\"}, {\"name\": \"eventname\", \"value\": \"event 1\"}, {\"name\": \"starttime\", \"value\": \"2022-02-22\"}]"

다음 명령은 EVENT 테이블에 두 번째 행을 삽입합니다. 이 예제에서는 다음 작업을 설명합니다.

  • id라는 파라미터가 SQL 텍스트에서 4번 사용됩니다.

  • 파라미터 starttime을 삽입할 때 암시적 형식 변환이 자동으로 적용됩니다.

  • venueid 열은 SMALLINT 데이터 형식으로 캐스팅됩니다.

  • DATE 데이터 형식을 나타내는 문자열은 암시적으로 TIMESTAMP 데이터 형식으로 변환됩니다.

  • 주석은 SQL 텍스트 내에서 사용할 수 있습니다.

aws redshift-data execute-statement --database dev --cluster-id my-test-cluster --db-user awsuser --sql "insert into event values(:id, :id::smallint, :id, :id, :eventname, :starttime) /*this is comment, and it won't apply parameterization for :id, :eventname or :starttime here*/" --parameters "[{\"name\": \"eventname\", \"value\": \"event 2\"}, {\"name\": \"starttime\", \"value\": \"2022-02-22\"}, {\"name\": \"id\", \"value\": \"2\"}]"

다음은 삽입된 두 행을 보여줍니다.

eventid | venueid | catid | dateid | eventname | starttime ---------+---------+-------+--------+-----------+--------------------- 1 | 1 | 1 | 1 | event 1 | 2022-02-22 00:00:00 2 | 2 | 2 | 2 | event 2 | 2022-02-22 00:00:00

다음 명령은 WHERE 절에서 명명된 파라미터를 사용하여 행을 검색합니다. 여기서 eventid1입니다.

aws redshift-data execute-statement --database dev --cluster-id my-test-cluster --db-user awsuser --sql "select * from event where eventid=:id" --parameters "[{\"name\": \"id\", \"value\": \"1\"}]"

다음 명령을 실행하여 이전 SQL 문의 SQL 결과를 가져옵니다.

aws redshift-data get-statement-result --id 7529ad05-b905-4d71-9ec6-8b333836eb5a

다음 결과를 제공합니다.

{ "Records": [ [ { "longValue": 1 }, { "longValue": 1 }, { "longValue": 1 }, { "longValue": 1 }, { "stringValue": "event 1" }, { "stringValue": "2022-02-22 00:00:00.0" } ] ], "ColumnMetadata": [ { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "eventid", "length": 0, "name": "eventid", "nullable": 0, "precision": 10, "scale": 0, "schemaName": "public", "tableName": "event", "typeName": "int4" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "venueid", "length": 0, "name": "venueid", "nullable": 0, "precision": 5, "scale": 0, "schemaName": "public", "tableName": "event", "typeName": "int2" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "catid", "length": 0, "name": "catid", "nullable": 0, "precision": 5, "scale": 0, "schemaName": "public", "tableName": "event", "typeName": "int2" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "dateid", "length": 0, "name": "dateid", "nullable": 0, "precision": 5, "scale": 0, "schemaName": "public", "tableName": "event", "typeName": "int2" }, { "isCaseSensitive": true, "isCurrency": false, "isSigned": false, "label": "eventname", "length": 0, "name": "eventname", "nullable": 1, "precision": 200, "scale": 0, "schemaName": "public", "tableName": "event", "typeName": "varchar" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "label": "starttime", "length": 0, "name": "starttime", "nullable": 1, "precision": 29, "scale": 6, "schemaName": "public", "tableName": "event", "typeName": "timestamp" } ], "TotalNumRows": 1 }

여러 SQL 문을 실행하려면

하나의 명령으로 여러 SQL 문을 실행하려면 aws redshift-data batch-execute-statement AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 3개의 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

aws redshift-data batch-execute-statement --region us-west-2 --db-user myuser --cluster-identifier mycluster-test --database dev --sqls "set timezone to BST" "select * from mytable" "select * from another_table"

다음은 이 응답의 예입니다.

{ "ClusterIdentifier": "mycluster-test", "CreatedAt": 1598306924.632, "Database": "dev", "DbUser": "myuser", "Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766" }

SQL 문에 대한 메타데이터를 나열하려면

SQL 문에 대한 메타데이터를 나열하려면 aws redshift-data list-statements AWS CLI 명령을 사용합니다. 이 명령을 실행하기 위한 권한 부여는 호출자의 IAM 권한을 기반으로 합니다.

다음 AWS CLI 명령은 실행된 SQL 문을 나열합니다.

aws redshift-data list-statements --region us-west-2 --status ALL

다음은 이 응답의 예입니다.

{ "Statements": [ { "CreatedAt": 1598306924.632, "Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766", "QueryString": "select * from stl_query limit 1", "Status": "FINISHED", "UpdatedAt": 1598306926.667 }, { "CreatedAt": 1598311717.437, "Id": "e0ebd578-58b3-46cc-8e52-8163fd7e01aa", "QueryString": "select * from stl_query limit 1", "Status": "FAILED", "UpdatedAt": 1598311719.008 }, { "CreatedAt": 1598313683.65, "Id": "c361d4f7-8c53-4343-8c45-6b2b1166330c", "QueryString": "select * from stl_query limit 1", "Status": "ABORTED", "UpdatedAt": 1598313685.495 }, { "CreatedAt": 1598306653.333, "Id": "a512b7bd-98c7-45d5-985b-a715f3cfde7f", "QueryString": "select 1", "Status": "FINISHED", "UpdatedAt": 1598306653.992 } ] }

SQL 문에 대한 메타데이터를 설명하려면

SQL 문에 대한 메타데이터에 대한 설명을 가져오려면 aws redshift-data describe-statement AWS CLI 명령을 사용합니다. 이 명령을 실행하기 위한 권한 부여는 호출자의 IAM 권한을 기반으로 합니다.

다음 AWS CLI 명령은 SQL 문을 설명합니다.

aws redshift-data describe-statement --id d9b6c0c9-0747-4bf4-b142-e8883122f766 --region us-west-2

다음은 이 응답의 예입니다.

{ "ClusterIdentifier": "mycluster-test", "CreatedAt": 1598306924.632, "Duration": 1095981511, "Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766", "QueryString": "select * from stl_query limit 1", "RedshiftPid": 20859, "RedshiftQueryId": 48879, "ResultRows": 1, "ResultSize": 4489, "Status": "FINISHED", "UpdatedAt": 1598306926.667 }

다음은 여러 SQL 문으로 batch-execute-statement 명령을 실행한 후 describe-statement 응답의 예입니다.

{ "ClusterIdentifier": "mayo", "CreatedAt": 1623979777.126, "Duration": 6591877, "HasResultSet": true, "Id": "b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652", "RedshiftPid": 31459, "RedshiftQueryId": 0, "ResultRows": 2, "ResultSize": 22, "Status": "FINISHED", "SubStatements": [ { "CreatedAt": 1623979777.274, "Duration": 3396637, "HasResultSet": true, "Id": "b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652:1", "QueryString": "select 1;", "RedshiftQueryId": -1, "ResultRows": 1, "ResultSize": 11, "Status": "FINISHED", "UpdatedAt": 1623979777.903 }, { "CreatedAt": 1623979777.274, "Duration": 3195240, "HasResultSet": true, "Id": "b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652:2", "QueryString": "select 2;", "RedshiftQueryId": -1, "ResultRows": 1, "ResultSize": 11, "Status": "FINISHED", "UpdatedAt": 1623979778.076 } ], "UpdatedAt": 1623979778.183 }

SQL 문의 결과를 가져오려면

실행된 SQL 문에서 결과를 가져오려면 redshift-data get-statement-result AWS CLI 명령을 사용합니다. execute-statement 또는 batch-execute-statement에 대한 응답으로 수신하는 Id를 제공할 수 있습니다. batch-execute-statement에 의해 실행된 SQL 문의 Id 값은 describe-statement의 결과에서 검색할 수 있으며 b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652:2와 같이 콜론과 시퀀스 번호가 접미사로 붙습니다. batch-execute-statement가 있는 여러 SQL 문을 실행하면 describe-statement와 같이 각 SQL 문에 Id 값이 있습니다. 이 명령을 실행하기 위한 권한 부여는 호출자의 IAM 권한을 기반으로 합니다.

다음 문은 execute-statement에 의해 실행되는 SQL 문의 결과를 반환합니다.

aws redshift-data get-statement-result --id d9b6c0c9-0747-4bf4-b142-e8883122f766 --region us-west-2

다음 문은 batch-execute-statement에 의해 실행되는 두 번째 SQL 문의 결과를 반환합니다.

aws redshift-data get-statement-result --id b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652:2 --region us-west-2

다음은 get-statement-result 호출 응답의 예입니다.

{ "ColumnMetadata": [ { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "userid", "length": 0, "name": "userid", "nullable": 0, "precision": 10, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "int4" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "query", "length": 0, "name": "query", "nullable": 0, "precision": 10, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "int4" }, { "isCaseSensitive": true, "isCurrency": false, "isSigned": false, "label": "label", "length": 0, "name": "label", "nullable": 0, "precision": 320, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "bpchar" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "xid", "length": 0, "name": "xid", "nullable": 0, "precision": 19, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "int8" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "pid", "length": 0, "name": "pid", "nullable": 0, "precision": 10, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "int4" }, { "isCaseSensitive": true, "isCurrency": false, "isSigned": false, "label": "database", "length": 0, "name": "database", "nullable": 0, "precision": 32, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "bpchar" }, { "isCaseSensitive": true, "isCurrency": false, "isSigned": false, "label": "querytxt", "length": 0, "name": "querytxt", "nullable": 0, "precision": 4000, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "bpchar" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "label": "starttime", "length": 0, "name": "starttime", "nullable": 0, "precision": 29, "scale": 6, "schemaName": "", "tableName": "stll_query", "typeName": "timestamp" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "label": "endtime", "length": 0, "name": "endtime", "nullable": 0, "precision": 29, "scale": 6, "schemaName": "", "tableName": "stll_query", "type": 93, "typeName": "timestamp" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "aborted", "length": 0, "name": "aborted", "nullable": 0, "precision": 10, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "int4" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "insert_pristine", "length": 0, "name": "insert_pristine", "nullable": 0, "precision": 10, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "int4" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": true, "label": "concurrency_scaling_status", "length": 0, "name": "concurrency_scaling_status", "nullable": 0, "precision": 10, "scale": 0, "schemaName": "", "tableName": "stll_query", "typeName": "int4" } ], "Records": [ [ { "longValue": 1 }, { "longValue": 3 }, { "stringValue": "health" }, { "longValue": 1023 }, { "longValue": 15279 }, { "stringValue": "dev" }, { "stringValue": "select system_status from stv_gui_status;" }, { "stringValue": "2020-08-21 17:33:51.88712" }, { "stringValue": "2020-08-21 17:33:52.974306" }, { "longValue": 0 }, { "longValue": 0 }, { "longValue": 6 } ] ], "TotalNumRows": 1 }

테이블을 설명하려면

테이블을 설명하는 메타데이터를 가져오려면 aws redshift-data describe-table AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 테이블을 설명하는 메타데이터를 반환합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

aws redshift-data describe-table --region us-west-2 --cluster-identifier mycluster-test --database dev --schema information_schema --table sql_features --secret arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn

다음은 이 응답의 예입니다.

{ "ColumnList": [ { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "feature_id", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "feature_name", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" } ] }

다음 AWS CLI 명령은 클러스터에 대해 테이블을 설명하는 SQL 문을 실행합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

aws redshift-data describe-table --region us-west-2 --db-user myuser --cluster-identifier mycluster-test --database dev --schema information_schema --table sql_features

다음은 이 응답의 예입니다.

{ "ColumnList": [ { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "feature_id", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "feature_name", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "sub_feature_id", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "sub_feature_name", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "is_supported", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "is_verified_by", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" }, { "isCaseSensitive": false, "isCurrency": false, "isSigned": false, "length": 2147483647, "name": "comments", "nullable": 1, "precision": 2147483647, "scale": 0, "schemaName": "information_schema", "tableName": "sql_features", "typeName": "character_data" } ] }

클러스터의 데이터베이스를 나열하려면

클러스터의 데이터베이스를 나열하려면 aws redshift-data list-databases AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스를 나열합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

aws redshift-data list-databases --region us-west-2 --secret arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn --cluster-identifier mycluster-test --database dev

다음은 이 응답의 예입니다.

{ "Databases": [ "dev" ] }

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스를 나열합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

aws redshift-data list-databases --region us-west-2 --db-user myuser --cluster-identifier mycluster-test --database dev

다음은 이 응답의 예입니다.

{ "Databases": [ "dev" ] }

데이터베이스의 스키마를 나열하려면

데이터베이스의 스키마를 나열하려면 aws redshift-data list-schemas AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스의 스키마를 나열합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

aws redshift-data list-schemas --region us-west-2 --secret arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn --cluster-identifier mycluster-test --database dev

다음은 이 응답의 예입니다.

{ "Schemas": [ "information_schema", "pg_catalog", "pg_internal", "public" ] }

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스의 스키마를 나열합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

aws redshift-data list-schemas --region us-west-2 --db-user mysuser --cluster-identifier mycluster-test --database dev

다음은 이 응답의 예입니다.

{ "Schemas": [ "information_schema", "pg_catalog", "pg_internal", "public" ] }

데이터베이스의 테이블을 나열하려면

데이터베이스의 테이블을 나열하려면 aws redshift-data list-tables AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스의 테이블을 나열합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

aws redshift-data list-tables --region us-west-2 --secret arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn --cluster-identifier mycluster-test --database dev --schema information_schema

다음은 이 응답의 예입니다.

{ "Tables": [ { "name": "sql_features", "schema": "information_schema", "type": "SYSTEM TABLE" }, { "name": "sql_implementation_info", "schema": "information_schema", "type": "SYSTEM TABLE" } }

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스의 테이블을 나열합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

aws redshift-data list-tables --region us-west-2 --db-user myuser --cluster-identifier mycluster-test --database dev --schema information_schema

다음은 이 응답의 예입니다.

{ "Tables": [ { "name": "sql_features", "schema": "information_schema", "type": "SYSTEM TABLE" }, { "name": "sql_implementation_info", "schema": "information_schema", "type": "SYSTEM TABLE" } ] }