이 튜토리얼에서는 App Engine 가변형 환경의 인스턴스에서 실행되는 샘플 .NET 코어 API와 Extensible Service Proxy(ESP)를 구성 및 배포하는 방법을 설명합니다. 샘플 API는 OpenAPI 사양을 사용하여 설명됩니다. 이 가이드에서는 API 키를 만들어 API에 대한 요청에 사용하는 방법도 설명합니다.
Cloud Endpoints 개요는 Endpoints 정보와 Endpoints 아키텍처를 참조하세요.
목표
아래의 개략적인 작업 목록을 사용하여 튜토리얼을 진행합니다. API에 요청을 보내려면 모든 작업을 수행해야 합니다.
- Google Cloud 프로젝트를 설정하고, 필요한 소프트웨어를 설치하고, App Engine 애플리케이션을 만듭니다. 시작하기 전에를 참고하세요.
- 샘플 코드를 다운로드합니다. 샘플 코드 받기를 참조하세요.
- Endpoints를 구성하는 데 사용되는
openapi.yaml파일을 구성합니다. Endpoints 구성을 참조하세요. - Endpoints 구성을 배포하여 Endpoints 서비스를 만듭니다. Endpoints 구성 배포를 참조하세요.
- 샘플 API와 ESP를 App Engine에 배포합니다. API 백엔드 배포를 참조하세요.
- API에 요청을 보냅니다. API에 요청 보내기를 참조하세요.
- API 활동을 추적합니다. API 활동 추적을 참조하세요.
- Google Cloud 계정에 요금이 청구되지 않도록 합니다. 정리를 참고하세요.
비용
이 문서에서는 비용이 청구될 수 있는 Google Cloud구성요소를 사용합니다.
프로젝트 사용량을 기준으로 예상 비용을 산출하려면 가격 계산기를 사용하세요.
이 문서에 설명된 태스크를 완료했으면 만든 리소스를 삭제하여 청구가 계속되는 것을 방지할 수 있습니다. 자세한 내용은 삭제를 참조하세요.
시작하기 전에
시작하기 전에
- Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
- 나중에 필요하므로 프로젝트 ID를 기록해 둡니다.
-
이 가이드에는 텍스트 편집기에서 사용할 수 있는 .NET Core 2.x SDK가 필요합니다. 통합 개발 환경(IDE)은 반드시 필요하지는 않지만 편의를 위해 다음 IDE 중 하나를 사용하는 것이 좋습니다.
- macOS, Linux, Windows에서 실행되는 Visual Studio Code. Visual Studio Code를 사용하는 경우에는 .NET Core 2.x도 설치해야 합니다.
- .NET Core 2.x를 포함하는 Windows용 Visual Studio 2017.
- .NET Core 2.x를 포함하는 Mac용 Visual Studio.
애플리케이션이 요청을 샘플 API로 전송하도록 해야 합니다. 이 가이드에서 제공하는 예시에서는 PowerShell 3.0 이상에서 지원되는
Invoke-WebRequest를 사용합니다.- Google Cloud CLI를 다운로드합니다.
-
gcloud CLI를 업데이트하고 Endpoints 구성요소를 설치합니다.
gcloud components update
-
Google Cloud CLI (
gcloud)에 Google Cloud의 데이터 및 서비스에 액세스할 수 있는 권한이 있는지 확인합니다. 새 브라우저 탭이 열리면 계정을 선택합니다.gcloud auth login
-
기본 프로젝트를 프로젝트 ID로 설정합니다.
gcloud config set project YOUR_PROJECT_ID
YOUR_PROJECT_ID를 Google Cloud 프로젝트 ID로 바꿉니다. 다른 Google Cloud 프로젝트가 있고
gcloud를 사용하여 이를 관리하려면 gcloud CLI 구성 관리를 참고하세요. - App Engine 애플리케이션을 만들 리전을 선택합니다. 다음 명령어를 실행하여 리전 목록을 가져옵니다.
gcloud app regions list
- App Engine 애플리케이션을 만듭니다.
YOUR_PROJECT_ID를 Google Cloud프로젝트 ID로 바꾸고 YOUR_REGION를 App Engine 애플리케이션을 생성하려는 리전으로 바꿉니다.
gcloud app create \ --project=YOUR_PROJECT_ID \ --region=YOUR_REGION
샘플 코드 가져오기
샘플 API를 다운로드하는 방법은 다음과 같습니다.
샘플 코드를 zip 파일로 다운로드합니다.
zip 파일의 압축을 풀고
dotnet-docs-samples-master\endpoints\getting-started디렉터리로 변경합니다.Visual Studio에서
GettingStarted.sln을 열거나 자주 사용하는 편집기를 사용하여endpoints\getting-started\src\IO.Swagger디렉터리의 파일을 수정합니다.
엔드포인트 구성
앱의 노출 영역과 인증 요구사항을 설명하는 OpenAPI 2.0 또는 OpenAPI 3.x 기반의 OpenAPI 문서가 있어야 합니다. 자세한 내용은 지원되는 OpenAPI 버전을 참고하세요.
ESPv2가 앱을 호출하는 데 필요한 정보를 갖도록 각 앱의 URL이 포함된 Google 전용 필드도 추가해야 합니다. OpenAPI를 처음 사용하는 경우 OpenAPI 개요에서 자세한 내용을 참조하세요.
OpenAPI 2.0
OpenAPI 2.0 사양을 사용하여 Endpoints를 구성하려면 다운로드한 샘플 코드의 dotnet-docs-samples-master\endpoints\getting-started 디렉터리에서 사용할 수 있는 openapi-appengine.yaml 파일을 사용하면 됩니다.
OpenAPI 2.0 사양의 콘텐츠는 다음과 유사해야 합니다.
swagger: "2.0" info: description: "A simple Google Cloud Endpoints API example." title: "Endpoints Example" version: "1.0.0" host: "YOUR_PROJECT_ID.appspot.com" consumes: - "application/json" produces: - "application/json" schemes: - "https" paths: "/echo": post: description: "Echo back a given message." operationId: "echo" produces: - "application/json" responses: 200: description: "Echo" schema: $ref: "#/definitions/echoMessage" parameters: - description: "Message to echo" in: body name: message required: true schema: $ref: "#/definitions/echoMessage" security: - api_key: [] "/auth/info/googlejwt": get: description: "Returns the requests' authentication information." operationId: "auth_info_google_jwt" produces: - "application/json" responses: 200: description: "Authentication info." schema: $ref: "#/definitions/authInfoResponse" x-security: - google_jwt: audiences: # This must match the "aud" field in the JWT. You can add multiple # audiences to accept JWTs from multiple clients. - "echo.endpoints.sample.google.com" "/auth/info/googleidtoken": get: description: "Returns the requests' authentication information." operationId: "authInfoGoogleIdToken" produces: - "application/json" responses: 200: description: "Authenication info." schema: $ref: "#/definitions/authInfoResponse" x-security: - google_id_token