選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

使用適用於 Java 的 SDK 2.x 的 API Gateway 範例 - AWS SDK 程式碼範例

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用適用於 Java 的 SDK 2.x 的 API Gateway 範例

下列程式碼範例示範如何使用 AWS SDK for Java 2.x 搭配 API Gateway 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境中查看內容中的動作。

案例是向您展示如何呼叫服務中的多個函數或與其他 AWS 服務組合來完成特定任務的程式碼範例。

AWS 社群貢獻是由多個團隊所建立和維護的範例 AWS。若要提供意見回饋,請使用連結儲存庫中提供的機制。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

動作

下列程式碼範例示範如何使用 CreateDeployment

SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static String createNewDeployment(ApiGatewayClient apiGateway, String restApiId, String stageName) { try { CreateDeploymentRequest request = CreateDeploymentRequest.builder() .restApiId(restApiId) .description("Created using the AWS API Gateway Java API") .stageName(stageName) .build(); CreateDeploymentResponse response = apiGateway.createDeployment(request); System.out.println("The id of the deployment is " + response.id()); return response.id(); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 CreateDeployment

下列程式碼範例示範如何使用 CreateDeployment

SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static String createNewDeployment(ApiGatewayClient apiGateway, String restApiId, String stageName) { try { CreateDeploymentRequest request = CreateDeploymentRequest.builder() .restApiId(restApiId) .description("Created using the AWS API Gateway Java API") .stageName(stageName) .build(); CreateDeploymentResponse response = apiGateway.createDeployment(request); System.out.println("The id of the deployment is " + response.id()); return response.id(); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 CreateDeployment

下列程式碼範例示範如何使用 CreateRestApi

SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static String createAPI(ApiGatewayClient apiGateway, String restApiId, String restApiName) { try { CreateRestApiRequest request = CreateRestApiRequest.builder() .cloneFrom(restApiId) .description("Created using the Gateway Java API") .name(restApiName) .build(); CreateRestApiResponse response = apiGateway.createRestApi(request); System.out.println("The id of the new api is " + response.id()); return response.id(); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 CreateRestApi

下列程式碼範例示範如何使用 CreateRestApi

SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static String createAPI(ApiGatewayClient apiGateway, String restApiId, String restApiName) { try { CreateRestApiRequest request = CreateRestApiRequest.builder() .cloneFrom(restApiId) .description("Created using the Gateway Java API") .name(restApiName) .build(); CreateRestApiResponse response = apiGateway.createRestApi(request); System.out.println("The id of the new api is " + response.id()); return response.id(); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 CreateRestApi

下列程式碼範例示範如何使用 DeleteDeployment

SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static void deleteSpecificDeployment(ApiGatewayClient apiGateway, String restApiId, String deploymentId) { try { DeleteDeploymentRequest request = DeleteDeploymentRequest.builder() .restApiId(restApiId) .deploymentId(deploymentId) .build(); apiGateway.deleteDeployment(request); System.out.println("Deployment was deleted"); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 DeleteDeployment

下列程式碼範例示範如何使用 DeleteDeployment

SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static void deleteSpecificDeployment(ApiGatewayClient apiGateway, String restApiId, String deploymentId) { try { DeleteDeploymentRequest request = DeleteDeploymentRequest.builder() .restApiId(restApiId) .deploymentId(deploymentId) .build(); apiGateway.deleteDeployment(request); System.out.println("Deployment was deleted"); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 DeleteDeployment

下列程式碼範例示範如何使用 DeleteRestApi

SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static void deleteAPI(ApiGatewayClient apiGateway, String restApiId) { try { DeleteRestApiRequest request = DeleteRestApiRequest.builder() .restApiId(restApiId) .build(); apiGateway.deleteRestApi(request); System.out.println("The API was successfully deleted"); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 DeleteRestApi

下列程式碼範例示範如何使用 DeleteRestApi

SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static void deleteAPI(ApiGatewayClient apiGateway, String restApiId) { try { DeleteRestApiRequest request = DeleteRestApiRequest.builder() .restApiId(restApiId) .build(); apiGateway.deleteRestApi(request); System.out.println("The API was successfully deleted"); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 DeleteRestApi

案例

下列程式碼範例示範如何建立無伺服器應用程式,讓使用者以標籤管理相片。

SDK for Java 2.x

顯示如何開發照片資產管理應用程式,以便使用 Amazon Rekognition 偵測圖片中的標籤,並將其儲存以供日後擷取。

如需完整的原始碼和如何設定及執行的指示,請參閱 GitHub 上的完整範例。

如要深入探索此範例的來源,請參閱 AWS  社群上的文章。

此範例中使用的服務
  • API Gateway

  • DynamoDB

  • Lambda

  • Amazon Rekognition

  • Amazon S3

  • Amazon SNS

下列程式碼範例示範如何建立無伺服器應用程式,讓使用者以標籤管理相片。

SDK for Java 2.x

顯示如何開發照片資產管理應用程式,以便使用 Amazon Rekognition 偵測圖片中的標籤,並將其儲存以供日後擷取。

如需完整的原始碼和如何設定及執行的指示,請參閱 GitHub 上的完整範例。

如要深入探索此範例的來源,請參閱 AWS  社群上的文章。

此範例中使用的服務
  • API Gateway

  • DynamoDB

  • Lambda

  • Amazon Rekognition

  • Amazon S3

  • Amazon SNS

下列程式碼範例示範如何建立 Amazon API Gateway 調用的 AWS Lambda 函數。

SDK for Java 2.x

示範如何使用 Lambda Java 執行時間 API 建立 AWS Lambda 函數。此範例會叫用不同的 AWS 服務來執行特定的使用案例。此範例示範如何建立 Amazon API Gateway 調用的 Lambda 函數,該函數會掃描 Amazon DynamoDB 資料表中的工作週年紀念日,並使用 Amazon Simple Notification Service (Amazon SNS) 傳送文字訊息給您的員工,在他們的週年紀念日向他們道賀。

如需完整的原始碼和如何設定及執行的指示,請參閱 GitHub 上的完整範例。

此範例中使用的服務
  • API Gateway

  • DynamoDB

  • Lambda

  • Amazon SNS

下列程式碼範例示範如何建立 Amazon API Gateway 調用的 AWS Lambda 函數。

SDK for Java 2.x

示範如何使用 Lambda Java 執行時間 API 建立 AWS Lambda 函數。此範例會叫用不同的 AWS 服務來執行特定的使用案例。此範例示範如何建立 Amazon API Gateway 調用的 Lambda 函數,該函數會掃描 Amazon DynamoDB 資料表中的工作週年紀念日,並使用 Amazon Simple Notification Service (Amazon SNS) 傳送文字訊息給您的員工,在他們的週年紀念日向他們道賀。

如需完整的原始碼和如何設定及執行的指示,請參閱 GitHub 上的完整範例。

此範例中使用的服務
  • API Gateway

  • DynamoDB

  • Lambda

  • Amazon SNS

AWS 社群貢獻

下列程式碼範例示範如何使用 API Gateway 搭配 Lambda 和 DynamoDB 建置和測試無伺服器應用程式

SDK for Java 2.x

示範如何使用 Java SDK 建置和測試由具有 Lambda 和 DynamoDB 的 API Gateway 組成的無伺服器應用程式。

如需完整的原始碼和如何設定及執行的指示,請參閱 GitHub 上的完整範例。

此範例中使用的服務
  • API Gateway

  • DynamoDB

  • Lambda

下列程式碼範例示範如何使用 API Gateway 搭配 Lambda 和 DynamoDB 建置和測試無伺服器應用程式

SDK for Java 2.x

示範如何使用 Java SDK 建置和測試由具有 Lambda 和 DynamoDB 的 API Gateway 組成的無伺服器應用程式。

如需完整的原始碼和如何設定及執行的指示,請參閱 GitHub 上的完整範例。

此範例中使用的服務
  • API Gateway

  • DynamoDB

  • Lambda

下一個主題:

Application Auto Scaling

上一個主題:

ACM
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。