在 AWS Service Catalog 中設定 Amazon EMR 範本 (適用於管理員) - Amazon SageMaker

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

在 AWS Service Catalog 中設定 Amazon EMR 範本 (適用於管理員)

本節提供有關管理員如何設定AWS Service Catalog產品的詳細資訊,以便使用者可以從 Amazon SageMaker Studio 傳統筆記型電腦獨立自行佈建 Amazon EMR 叢集。此外,管理員還可以透過某種方式設定 Amazon EMR 叢集範本,以便終端使用者可以自訂叢集的各個層面以符合其特定需求。例如,管理員可以定義允許的執行個體類型清單,使用者可以在建立叢集時從中選擇這些執行個體類型。

本主題假設您熟悉如何在 AWS Service Catalog、Amazon EMRAWS CloudFormation 建立產品組合以及產品

注意

您可以參考 aws-範例/sagemaker-工作室-emr GitHub 儲存庫中的範 AWS CloudFormation 本,做為部署 IAM 角色、Amazon VPC、沙箱工作室經典網域、使用者設定檔,以及用於啟動 Amazon EMR 叢集的範本的 CloudFormation 堆疊範例。 CloudFormation 根據您在工作室傳統版和 Amazon EMR 叢集之間的身份驗證方法,有多種可用選項可用。在這些範例中,父 CloudFormation範本會將 SageMaker VPC ID、安全群組和子網路 ID 參數傳遞至 Amazon EMR 叢集的 CloudFormation 範本。

您可以在巢狀儲存庫中存取各種 CloudFormation Amazon EMR 範本範本範本的範例,並進一步從單一帳戶部署到跨帳戶。

如需連線至 Amazon EMR 叢集時可用的身分驗證方法的詳細資訊,請參閱使用工作室傳統筆記本的 Amazon EMR 叢集

為了簡化 Amazon EMR 叢集的建立,管理員可以將 Amazon EMR 叢集的CloudFormation 範本註冊為產品組合中的產品。 AWS Service Catalog然後,他們將 Service Catalog 組合與 Studio 傳統執行角色產生關聯,以確保 Studio 傳統中範本的可用性。此外,為了確保資料科學家能夠探索這些範本、佈建 Amazon EMR 叢集,以及從其 Studio Classic 筆記本連接到 Amazon EMR 叢集,管理員需要設定適當的存取許可。

下列清單提供管理員需要套用至基準 CloudFormation 堆疊的其他設定,以便讓 Studio Classic 存取 Service Catalog 產品和佈建 Amazon EMR 叢集。這些設定必須套用於多個層級:

  • 在 Service Catalog 產品組合中

  • 在 Service Catalog 產品中

  • 在宣告為 Service Catalog 產品的 CloudFormation Amazon EMR 範本中

最後,管理員必須根據工作室典型版和 Amazon EMR 位於相同或不 AWS 同的帳戶,將必要的許可指派給存取叢集的 Studio 傳統執行角色和部署 Amazon EMR 的帳戶。

  • 先決條件:網路和身分驗證需求

    先決條件是,請確定您已檢閱中的網路和安全性需求,設定網路 (針對管理員)並且已建立支援您選擇之驗證方法的基準 CloudFormation 堆疊。您可以在 aws- 樣本/圖模機-工作室 CloudFormation emr 中找到模板的示例。

  • 在您的 Service Catalog 產品組合:

    將下列區段新增至學檔 CloudFormation 範本 (請參閱 YAML 格式的範例),以將您的產品組合與存取叢集的 Studio 典型執行角色產生關聯。

    SageMakerStudioEMRProductPortfolioPrincipalAssociation: Type: AWS::ServiceCatalog::PortfolioPrincipalAssociation Properties: PrincipalARN: SageMakerExecutionRole.Arn PortfolioId: SageMakerStudioEMRProductPortfolio ID PrincipalType: IAM
  • 在您的 Service Catalog 產品:

    將下列標籤鍵 "sagemaker:studio-visibility:emr" 新增至參考 Amazon EMR 範本資源的 Service Catalog 產品中,並設定為值為 "true" (此處為 YAML)。這確保了模板在工作室經典的可見性。

    SMStudioEMRNoAuthProduct: Type: AWS::ServiceCatalog::CloudFormationProduct Properties: Owner: AWS Name: SageMaker Studio Domain No Auth EMR ProvisioningArtifactParameters: - Name: SageMaker Studio Domain No Auth EMR Description: Provisions a SageMaker domain and No Auth EMR Cluster Info: LoadTemplateFromURL: Link to your CloudFormation template. For example, https://aws-ml-blog.s3.amazonaws.com/artifacts/astra-m4-sagemaker/end-to-end/CFN-EMR-NoStudioNoAuthTemplate-v3.yaml Tags: - Key: "sagemaker:studio-visibility:emr" Value: "true"
  • 在 Service Catalog 產品中的 Amazon EMR 叢集 CloudFormation 範本中:

    新增以下強制性堆疊參數作為預留位置。本節會填入使用者在從 Studio 傳統佈建叢集時所使用的 Studio 典型專案名稱和識別碼。

    SageMakerProjectName: Type: String Description: Name of the project SageMakerProjectId: Type: String Description: Service generated Id of the project.

    管理員可以指定 DefaultAllowedValues 以在範本的參數區段中包含選項,以便使用者在建立叢集時輸入或選取自訂值。下列範例說明管理員在建立 Amazon EMR 範本時可設定的其他輸入參數。

    "Parameters": { "EmrClusterName": { "Type": "String", "Description": "EMR cluster Name." }, "MasterInstanceType": { "Type": "String", "Description": "Instance type of the EMR master node.", "Default": "m5.xlarge", "AllowedValues": [ "m5.xlarge", "m5.2xlarge", "m5.4xlarge" ] }, "CoreInstanceType": { "Type": "String", "Description": "Instance type of the EMR core nodes.", "Default": "m5.xlarge", "AllowedValues": [ "m5.xlarge", "m5.2xlarge", "m5.4xlarge", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge" ] }, "CoreInstanceCount": { "Type": "String", "Description": "Number of core instances in the EMR cluster.", "Default": "2", "AllowedValues": [ "2", "5", "10" ] }, "EmrReleaseVersion": { "Type": "String", "Description": "The release version of EMR to launch.", "Default": "emr-5.33.1", "AllowedValues": [ "emr-5.33.1", "emr-6.4.0" ] } }
  • 最後,附加必要的身分與存取權管理政策,以便透過工作室傳統筆記本提供 CloudFormation Amazon EMR 範本的能見度,以及 Amazon EMR 叢集的自我佈建功能。您必須新增這些政策的角色取決於 Studio 經典版和 Amazon EMR 是否部署在相同的帳戶 (單一帳戶) 或不同的帳戶 (跨帳戶) 中。

    • 如果您的 Amazon EMR 叢集部署在與工作室經典 AWS 帳戶相同的帳戶中,請參閱單一帳戶索引標籤。

    • 如果您的 Amazon EMR 叢集部署在與工作室傳統 AWS 帳戶不同的帳戶中,請參閱跨帳戶索引標籤。

    如需使用角色進行跨帳戶存取權的更多資訊,請參閱 IAM 中的跨帳戶資源存取跨帳戶政策評估邏輯

    Single account

    將下列權限附加至存取叢集的 Studio 典型執行角色。

    下列清單提供所需的權限明細。

    • AllowEMRTemplateDiscovery 允許 Amazon EMR 範本的可探索性。

    • AllowSagemakerProjectManagement可建立SageMaker 專案。在工作室傳統版中,可透過專 AWS Service Catalog 案授予存取權。

    • AllowClusterDetailsDiscoveryAllowClusterDiscovery允許探索和連線至 Amazon EMR 叢集。

    • AllowPresignedUrl 允許建立預先簽署 URL 來存取 Spark 使用者介面。

    以下是包含這些許可的完整 JSON。

    { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowPresignedUrl", "Effect": "Allow", "Action": [ "elasticmapreduce:DescribeCluster", "elasticmapreduce:ListInstanceGroups", "elasticmapreduce:CreatePersistentAppUI", "elasticmapreduce:DescribePersistentAppUI", "elasticmapreduce:GetPersistentAppUIPresignedURL", "elasticmapreduce:GetOnClusterAppUIPresignedURL" ], "Resource": [ "arn:aws:elasticmapreduce:studio-region:studio-account:cluster/*" ] }, { "Sid": "AllowClusterDetailsDiscovery", "Effect": "Allow", "Action": [ "elasticmapreduce:DescribeCluster", "elasticmapreduce:ListInstances", "elasticmapreduce:ListInstanceGroups", "elasticmapreduce:DescribeSecurityConfiguration" ], "Resource": [ "arn:aws:elasticmapreduce:studio-region:studio-account:cluster/*" ] }, { "Sid": "AllowClusterDiscovery", "Effect": "Allow", "Action": [ "elasticmapreduce:ListClusters" ], "Resource": "*" }, { "Sid": "AllowEMRTemplateDiscovery", "Effect": "Allow", "Action": [ "servicecatalog:SearchProducts" ], "Resource": "*" }, { "Sid": "AllowSagemakerProjectManagement", "Effect": "Allow", "Action": [ "sagemaker:CreateProject", "sagemaker:DeleteProject" ], "Resource": "arn:aws:sagemaker:studio-region:studio-account:project/*" }, ] }
    Cross accounts

    如果您的 Amazon EMR 叢集和工作室傳統版部署在不同的 AWS 帳戶中,您可以透過多個步驟設定許可。

    • 信任帳戶 (部署 Amazon EMR 的帳戶),建立具有下列許可及信任關係的自訂 IAM 角色 (在此頁面稱為 ASSUMABLE-ROLE)。

      如需在 AWS 帳戶建立角色的相關資訊,請參閱建立 IAM 角色 (主控台)

      1. 新增定義下列許可的 IAM 政策。

        • AllowClusterDetailsDiscoveryAllowClusterDiscovery 允許探索和連線至 Amazon EMR 叢集。

        • AllowPresignedUrl 允許建立預先簽署 URL 來存取 Spark 使用者介面。

        以下是包含這些許可的完整 JSON。

        { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowPresignedUrl", "Effect": "Allow", "Action": [ "elasticmapreduce:DescribeCluster", "elasticmapreduce:ListInstanceGroups", "elasticmapreduce:CreatePersistentAppUI", "elasticmapreduce:DescribePersistentAppUI", "elasticmapreduce:GetPersistentAppUIPresignedURL", "elasticmapreduce:GetOnClusterAppUIPresignedURL" ], "Resource": [ "arn:aws:elasticmapreduce:emr-region:emr-account:cluster/*" ] }, { "Sid": "AllowClusterDetailsDiscovery", "Effect": "Allow", "Action": [ "elasticmapreduce:DescribeCluster", "elasticmapreduce:ListInstances", "elasticmapreduce:ListInstanceGroups", "elasticmapreduce:DescribeSecurityConfiguration" ], "Resource": [ "arn:aws:elasticmapreduce:emr-region:emr-account:cluster/*" ] }, { "Sid": "AllowClusterDiscovery", "Effect": "Allow", "Action": [ "elasticmapreduce:ListClusters" ], "Resource": "*" } ] }
      2. 若要授與受信任帳戶 (部署 Studio Classic 的帳戶) 在信任帳戶中擔任角色的權限,請包含下列信任關係。

        { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::studio-account:root" }, "Action": "sts:AssumeRole" } ] }
    • 受信任的帳戶 (部署 Studio 傳統版的帳戶) 上,將下列權限和信任關係新增至 Studio 典型執行角色。

      1. 新增定義下列許可的 IAM 政策。

        • AllowSagemakerProjectManagement以允許建立SageMaker 專案。在工作室傳統版中,可透過專 AWS Service Catalog 案授予存取權。

        • AllowEMRTemplateDiscovery 允許 Amazon EMR 範本的可探索性。

        以下是包含這些許可的完整 JSON。

        { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSagemakerProjectManagement", "Effect": "Allow", "Action": [ "sagemaker:CreateProject", "sagemaker:DeleteProject" ], "Resource": "arn:aws:sagemaker:::project/*" }, { "Sid": "AllowEMRTemplateDiscovery", "Effect": "Allow", "Action": [ "servicecatalog:SearchProducts" ], "Resource": "*" } ] }
      2. 若要授與 Studio 典型執行角色在信任帳戶ASSUMABLE-ROLE中承擔的權限,請包含下列信任關係。

        { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowRoleAssumptionForCrossAccountDiscovery", "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": ["arn:aws:iam::emr-account:role/ASSUMABLE-ROLE" ] }] }
    • 最後,請參跨帳戶使用案例的其他組態 (適用於管理員)閱以了解如何將 ARN 提供ASSUMABLE-ROLE給 Studio 經典執行角色。ARN 會在啟動時由工作室經典 Jupyter 伺服器載入。Studio 經典執行角色會假設跨帳戶角色,以探索並連接到信任帳戶中的 Amazon EMR 叢集。

一旦 Amazon SageMaker 工作室傳統版中提供這些 CloudFormation 範本,資料科學家就可以使用這些範本來自行佈建 Amazon EMR 叢集。每個在模板中"Parameters"指定的成為 Studio 經典的集群創建形式的輸入框,與相應的"AllowedValues"出現在一個下拉菜單。

下圖顯示了從 CloudFormation Amazon EMR 範本組裝的動態表單,以在 SageMaker 工作室經典中創建一個 Amazon EMR 叢集。

從 CloudFormation Amazon EMR 模板組裝的動態表單的插圖,以在 SageMaker 工作室經典中創建一個 Amazon EMR 集群。

請瀏覽從經典工作室啟動 Amazon EMR 集群以了解如何使用這些 Amazon EMR 範本從工作室傳統版啟動叢集。