CreateApp 搭配 a AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

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

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

CreateApp 搭配 a AWS SDK 或 CLI 使用

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

CLI
AWS CLI

範例 1:建立應用程式

以下 create-app 範例會建立新應用程式 (專案)。

aws pinpoint create-app \ --create-application-request Name=ExampleCorp

輸出:

{ "ApplicationResponse": { "Arn": "arn:aws:mobiletargeting:us-west-2:AIDACKCEVSQ6C2EXAMPLE:apps/810c7aab86d42fb2b56c8c966example", "Id": "810c7aab86d42fb2b56c8c966example", "Name": "ExampleCorp", "tags": {} } }

範例 2:建立已標記的應用程式

下列 create-app 範例會建立新的應用程式 (專案),並將標籤 (金鑰和值) 與應用程式產生關聯。

aws pinpoint create-app \ --create-application-request Name=ExampleCorp,tags={"Stack"="Test"}

輸出:

{ "ApplicationResponse": { "Arn": "arn:aws:mobiletargeting:us-west-2:AIDACKCEVSQ6C2EXAMPLE:apps/810c7aab86d42fb2b56c8c966example", "Id": "810c7aab86d42fb2b56c8c966example", "Name": "ExampleCorp", "tags": { "Stack": "Test" } } }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateApp

Java
Java 2.x 的 SDK
注意

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

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.CreateAppRequest; import software.amazon.awssdk.services.pinpoint.model.CreateAppResponse; import software.amazon.awssdk.services.pinpoint.model.CreateApplicationRequest; import software.amazon.awssdk.services.pinpoint.model.PinpointException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class CreateApp { public static void main(String[] args) { final String usage = """ Usage: <appName> Where: appName - The name of the application to create. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String appName = args[0]; System.out.println("Creating an application with name: " + appName); PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); String appID = createApplication(pinpoint, appName); System.out.println("App ID is: " + appID); pinpoint.close(); } public static String createApplication(PinpointClient pinpoint, String appName) { try { CreateApplicationRequest appRequest = CreateApplicationRequest.builder() .name(appName) .build(); CreateAppRequest request = CreateAppRequest.builder() .createApplicationRequest(appRequest) .build(); CreateAppResponse result = pinpoint.createApp(request); return result.applicationResponse().id(); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; } }
  • 如需 API 詳細資訊,請參閱 CreateApp AWS SDK for Java 2.x 參考中的 API

Kotlin
Kotlin 的 SDK
注意

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

suspend fun createApplication(applicationName: String?): String? { val createApplicationRequestOb = CreateApplicationRequest { name = applicationName } PinpointClient { region = "us-west-2" }.use { pinpoint -> val result = pinpoint.createApp( CreateAppRequest { createApplicationRequest = createApplicationRequestOb }, ) return result.applicationResponse?.id } }
  • 如需 API 詳細資訊,請參閱 CreateApp AWS for Kotlin SDK 參考中的 API