Doc AWS SDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. AWS
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
AWS SDK 또는 CLI와 CreatePortal
함께 사용
다음 코드 예제는 CreatePortal
의 사용 방법을 보여 줍니다.
- CLI
-
- AWS CLI
-
포털 생성
다음
create-portal
예시에서는 풍력 발전 단지 회사의 웹 포털을 생성합니다. AWS Single Sign-On을 활성화한 리전과 동일한 리전에서만 포털을 생성할 수 있습니다.aws iotsitewise create-portal \ --portal-name
WindFarmPortal
\ --portal-description"A portal that contains wind farm projects for Example Corp."
\ --portal-contact-emailsupport@example.com
\ --role-arnarn: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" }
자세한 내용은 AWS IoT SiteWise 사용 설명서의 IoT SiteWise Monitor 시작하기 AWS 및 IoT SiteWise AWS IoT SiteWise 사용 설명서의 AWS SSO 활성화를 참조하세요.
-
API 세부 정보는 AWS CLI 명령 참조의 CreatePortal
섹션을 참조하세요.
-
- Java
-
- SDK for Java 2.x
-
참고
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 세부 정보는 AWS SDK for Java 2.x API 참조의 CreatePortal을 참조하세요.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. import { CreatePortalCommand, IoTSiteWiseClient, } from "@aws-sdk/client-iotsitewise"; import { parseArgs } from "node:util"; /** * Create a Portal. * @param {{ portalName: string, portalContactEmail: string, roleArn: string }} */ export const main = async ({ portalName, portalContactEmail, roleArn }) => { const client = new IoTSiteWiseClient({}); try { const result = await client.send( new CreatePortalCommand({ portalName: portalName, // The name to give the created Portal. portalContactEmail: portalContactEmail, // A valid contact email. roleArn: roleArn, // The ARN of a service role that allows the portal's users to access the portal's resources. }), ); console.log("Portal created successfully."); return result; } catch (caught) { if (caught instanceof Error && caught.name === "IoTSiteWiseError") { console.warn( `${caught.message}. There was a problem creating the Portal.`, ); } else { throw caught; } } };
-
API 세부 정보는 AWS SDK for JavaScript API 참조의 CreatePortal을 참조하세요.
-
- Python
-
- SDK for Python (Boto3)
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. class IoTSitewiseWrapper: """Encapsulates AWS IoT SiteWise actions using the client interface.""" def __init__(self, iotsitewise_client: client) -> None: """ Initializes the IoTSitewiseWrapper with an AWS IoT SiteWise client. :param iotsitewise_client: A Boto3 AWS IoT SiteWise client. This client provides low-level access to AWS IoT SiteWise services. """ self.iotsitewise_client = iotsitewise_client self.entry_id = 0 # Incremented to generate unique entry IDs for batch_put_asset_property_value. @classmethod def from_client(cls) -> "IoTSitewiseWrapper": """ Creates an IoTSitewiseWrapper instance with a default AWS IoT SiteWise client. :return: An instance of IoTSitewiseWrapper initialized with the default AWS IoT SiteWise client. """ iotsitewise_client = boto3.client("iotsitewise") return cls(iotsitewise_client) def create_portal( self, portal_name: str, iam_role_arn: str, portal_contact_email: str ) -> str: """ Creates an AWS IoT SiteWise Portal. :param portal_name: The name of the portal to create. :param iam_role_arn: The ARN of an IAM role. :param portal_contact_email: The contact email of the portal. :return: The ID of the created portal. """ try: response = self.iotsitewise_client.create_portal( portalName=portal_name, roleArn=iam_role_arn, portalContactEmail=portal_contact_email, ) portal_id = response["portalId"] waiter = self.iotsitewise_client.get_waiter("portal_active") waiter.wait(portalId=portal_id, WaiterConfig={"MaxAttempts": 40}) return portal_id except ClientError as err: if err.response["Error"]["Code"] == "ResourceAlreadyExistsException": logger.error("Portal %s already exists.", portal_name) else: logger.error( "Error creating portal %s. Here's why %s", portal_name, err.response["Error"]["Message"], ) raise
-
API 세부 정보는 AWS SDK for Python (Boto3) API 참조의 CreatePortal을 참조하세요.
-