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

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

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

CreatePortal 搭配 a AWS SDK 或 CLI 使用

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

CLI
AWS CLI

建立入口網站

下列create-portal範例會為風力發電廠公司建立 Web 入口網站。您只能在啟用 AWS 單一登入的相同區域中建立入口網站。

aws iotsitewise create-portal \ --portal-name WindFarmPortal \ --portal-description "A portal that contains wind farm projects for Example Corp." \ --portal-contact-email support@example.com \ --role-arn arn:aws:iam::123456789012:role/service-role/MySiteWiseMonitorServiceRole

輸出:

{ "portalId": "a1b2c3d4-5678-90ab-cdef-aaaaaEXAMPLE", "portalArn": "arn:aws:iotsitewise:us-west-2:123456789012:portal/a1b2c3d4-5678-90ab-cdef-aaaaaEXAMPLE", "portalStartUrl": "https://a1b2c3d4-5678-90ab-cdef-aaaaaEXAMPLE.app.iotsitewise.aws", "portalStatus": { "state": "CREATING" }, "ssoApplicationId": "ins-a1b2c3d4-EXAMPLE" }

如需詳細資訊,請參閱 IoT SiteWise 使用者指南中的 AWS IoTWord 監視器入門IoT AWS SSO 使用者指南中的 EnableWordAWS IoT SiteWise AWS IoT SiteWise

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreatePortal

Java
Java 2.x 的 SDK
注意

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

/** * Creates a new IoT SiteWise portal. * * @param portalName the name of the portal to create. * @param iamRole the IAM role ARN to use for the portal. * @param contactEmail the email address of the portal contact. * @return a {@link CompletableFuture} that represents a {@link String} result of the portal ID. The calling code * can attach callbacks, then handle the result or exception by calling {@link CompletableFuture#join()} or * {@link CompletableFuture#get()}. * <p> * If any completion stage in this method throws an exception, the method logs the exception cause and keeps * it available to the calling code as a {@link CompletionException}. By calling * {@link CompletionException#getCause()}, the calling code can access the original exception. */ public CompletableFuture<String> createPortalAsync(String portalName, String iamRole, String contactEmail) { CreatePortalRequest createPortalRequest = CreatePortalRequest.builder() .portalName(portalName) .portalDescription("This is my custom IoT SiteWise portal.") .portalContactEmail(contactEmail) .roleArn(iamRole) .build(); return getAsyncClient().createPortal(createPortalRequest) .handle((response, exception) -> { if (exception != null) { logger.error("Failed to create portal: {} ", exception.getCause().getMessage()); throw (CompletionException) exception; } return response.portalId(); }); }
  • 如需 API 詳細資訊,請參閱 CreatePortal AWS SDK for Java 2.x 參考中的 API