이 페이지에서는 Google Cloud CLI, 클라이언트 라이브러리, Spanner 드라이버와 함께 Cloud Spanner API를 사용하는 데 필요한 설정 단계를 안내합니다.
Google Cloud 콘솔에서 Spanner를 사용하려면 콘솔을 사용한 빠른 시작을 참조하세요.
필요한 역할
Spanner 데이터베이스를 사용하고 상호작용하는 데 필요한 권한을 얻으려면 관리자에게 다음 IAM 역할을 부여해 달라고 요청하세요.
-
데이터 읽기 및 쓰기:
인스턴스의 Cloud Spanner 데이터베이스 사용자(
roles/spanner.databaseUser
) -
데이터베이스에 대한 읽기 전용 액세스 권한:
인스턴스에 대한 Cloud Spanner 데이터베이스 리더(
roles/spanner.databaseReader
)
역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.
커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.
Google Cloud 프로젝트 설정
-
Google Cloud 콘솔의 프로젝트 페이지로 이동합니다.
- 새 Google Cloud 프로젝트를 만들거나 프로젝트 이름을 클릭하여 기존 프로젝트를 엽니다.
-
터미널 창을 열고
MY_PROJECT_ID
를 프로젝트 ID(프로젝트 이름 아님)로 바꾸어 프로젝트를 Google Cloud CLI의 기본 프로젝트로 설정합니다.gcloud config set project MY_PROJECT_ID
-
Make sure that billing is enabled for your Google Cloud project.
Spanner 가격 책정에 대해서도 알아볼 수 있습니다.
-
프로젝트에서 Cloud Spanner API를 사용하도록 설정합니다.
참고: 다른 프로젝트의 서비스 계정을 사용하여 Spanner 인스턴스에 액세스하는 경우 두 프로젝트 모두에서 Spanner API를 사용 설정해야 합니다.
인증 설정
Select the tabs for how you plan to access the API:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
- C++에서 Spanner 시작하기
- C++에서 Spanner 시작하기
- Go에서 Spanner 시작하기
- 자바에서 Spanner 시작하기
- JDBC에서 Spanner 시작하기
- Node.js에서 Spanner 시작하기
- PHP에서 Spanner 시작하기
- Python에서 Spanner 시작하기
- Ruby에서 Spanner 시작하기
- REST에서 Spanner 시작하기
- gcloud에서 Spanner 시작하기
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
서비스 계정 가장 기능을 사용하여 사용자 인증 정보 대신 Google API에 인증하도록 gcloud CLI를 설정하려면 다음 명령어를 실행합니다.
gcloud config set auth/impersonate_service_account SERVICE_ACCT_EMAIL
자세한 내용은 서비스 계정 가장을 참조하세요.
Terraform
로컬 개발 환경에서 Terraform 코드를 사용하려면 gcloud CLI를 설치 및 초기화한 다음 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정하세요.
자세한 내용은 다음을 참조하세요: Set up authentication for a local development environment.
클라이언트 라이브러리
로컬 개발 환경에서 클라이언트 라이브러리를 사용하려면 gcloud CLI를 설치 및 초기화한 다음 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정하세요.
자세한 내용은 다음을 참조하세요: Set up authentication for a local development environment.
서비스 계정 가장 기능을 사용하여 사용자 인증 정보 대신 Google API에 인증하도록 로컬 ADC 파일을 설정하려면 다음 명령어를 실행합니다.
gcloud auth application-default login --impersonate-service-account=SERVICE_ACCT_EMAIL
자세한 내용은 서비스 계정 가장을 참조하세요.
REST
로컬 개발 환경에서 REST API를 사용하려면 gcloud CLI에 제공한 사용자 인증 정보를 사용합니다.
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
자세한 내용은 Google Cloud 인증 문서의 REST 사용을 위한 인증을 참조하세요.
서비스 계정 가장 기능을 사용하여 REST API 요청의 액세스 토큰을 생성할 수 있습니다. 자세한 내용은 가장 서비스 계정을 참조하세요.
Google Cloud CLI 실행
개발 환경과 인증을 설정했으므로 이제 gcloud
명령줄 도구를 실행하여 Spanner와 상호작용합니다.
gcloud spanner instance-configs list
프로젝트가 액세스할 수 있는 Spanner 인스턴스 구성의 목록(리전 구성, 이중 리전 구성, 멀티 리전 구성 포함)이 표시됩니다. 자세한 내용은 인스턴스 개요를 참조하세요.
이제 설정을 완료하였습니다.
다음 단계
Cloud 클라이언트 라이브러리와 드라이버를 사용하여 Spanner 인스턴스, 데이터베이스, 테이블, 색인을 만드는 방법을 알아봅니다. 그런 다음 Spanner에서 데이터를 저장하고 쿼리하고 읽으세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-16(UTC)