Ongoing service disruptions
For the most recent update on ongoing service disruptions affecting the AWS Middle East (UAE) Region (ME-CENTRAL-1), refer to the AWS Health Dashboard. For information on AWS Service migration, see How do I migrate my services to another region?
すべてのインスタンスが同じ IAM ロールを使用している場合、特定の API 呼び出しを行った SageMaker ノートブックインスタンスを特定するにはどうすればよいですか?
複数の Amazon SageMaker ノートブックインスタンスがあります。それらはすべて同じ AWS Identity and Access Management (IAM) ロールを使用します。各 API アクションの AWS CloudTrail イベントには、アクションを実行したノートブックインスタンスに関係なく、同じプリンシパル ID (セッション名) が表示されます。どのノートブックインスタンスがどの API アクションを実行したかを知る必要があります。
簡単な説明
同じ IAM ロールを持つ複数の SageMaker インスタンスがある場合、CloudTrail イベントは API アクションを実行したインスタンスを識別しません。
次の CloudTrail イベントログの例では、プリンシパル ID が「SageMaker」と表示されています。デフォルトでは、プリンシパル ID は特定の SageMaker インスタンスを識別しません。
{ "eventVersion": "1.05", "userIdentity": { "type": "AssumedRole", "principalId": "AAAAAAAAAAAAAAAAAA:SageMaker",
解決策
インスタンスを区別するノートブックスクリプトを作成するには、次の手順を実行します。
-
SageMaker ノートブックインスタンスの IAM 実行ロールを作成します。または、既存の実行ロールを使用します。以下の手順では、実行ロールの Amazon リソースネーム (ARN) は、arn:aws:iam::111122223333:role/service-role/AmazonSageMaker-ExecutionRoleです。実行ロールの ARN は異なります。
-
sts:AssumeRole を含む IAM ポリシーを実行ロールにアタッチします。sts: AssumeRole アクションを使用すると、実行ロールを別のセッション名で引き受けることができます。
例:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "arn:aws:iam::111122223333:role/service-role/AmazonSageMaker-ExecutionRole" } ] }3.実行ロールの信頼ポリシーに次の権限が含まれていることを確認します。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "sagemaker.amazonaws.com" }, "Action": "sts:AssumeRole" }, { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:root" }, "Action": "sts:AssumeRole", "Condition": { "StringLike": { "aws:PrincipalArn": "arn:aws:iam::111122223333:role/service-role/AmazonSageMaker-ExecutionRole" } } } ] } -
次のようなスタートノートブックライフサイクル設定スクリプトを作成します。このサンプルスクリプトは、ノートブックインスタンス名を取得し、その名前をセッション名として使用します。詳細については、LCC スクリプトを使用した SageMaker ノートブックインスタンスのカスタマイズを参照してください。
#Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. #Permission is hereby granted, free of charge, to any person obtaining a copy of this #software and associated documentation files (the "Software"), to deal in the Software #without restriction, including without limitation the rights to use, copy, modify, #merge, publish, distribute, sublicense, and/or sell copies of the Software, and to #permit persons to whom the Software is furnished to do so. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A #PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE #SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #!/bin/bash set -ex # Obtain the name of the notebook instance nbname=$(jq -r '.ResourceName' /opt/ml/metadata/resource-metadata.json) echo "Notebook Name = $nbname" # Use the AWS Command Line Interface (AWS CLI) to obtain the Amazon Resource Name (ARN) of the IAM execution role nbinfo=$(aws sagemaker describe-notebook-instance --notebook-instance-name $nbname) nbrole=$(jq -r '.RoleArn' <<< "$nbinfo") echo "Notebook Role = $nbrole" # Obtain the Region of the notebook instance nbregion=$(aws configure get region) echo "Notebook Region = $nbregion" # Write Assume Role Provider Settings to a new config file echo "Writing new config file" cat > /home/ec2-user/.aws/config.new <<EOF1 [default] region=$nbregion role_arn = $nbrole credential_source = Ec2InstanceMetadata role_session_name = $nbname sts_regional_endpoints = regional EOF1 echo "Moving new config to config file" sudo mv /home/ec2-user/.aws/config.new /home/ec2-user/.aws/config # Secure the "config" file so that it can't be deleted/updated without root user permissions sudo chattr +i /home/ec2-user/.aws/config -
次に、SageMaker ノートブックインスタンスを作成して (例:test-2) 、その後、前の手順で作成したライフサイクル設定スクリプトをその他の設定にアタッチします。
注: ルートアクセスをオフにして上記のノートブックインスタンスを作成するには、「Use Control root access to a SageMaker notebook instance」を参照してください。ノートブックインスタンスを作成したら、RootAccess フィールドを無効に設定します。このアクションにより、ユーザーは設定ファイルを削除または更新できなくなります。
CloudTrail でノートブックインスタンスを特定する
API アクションを実行したノートブックインスタンスを特定するには、CloudTrail イベントを確認します。userIdentity オブジェクトの下、プリンシパル Id と arn にノートブックインスタンスの名前が表示されます。
たとえば、次のイベントの詳細は、SageMaker ノートブックインスタンス ** test-2** が API コールを行ったことを示しています。
{ "eventVersion": "1.05", "userIdentity": { "type": "AssumedRole", "principalId": "AAAAAAAAAAAAAAAAAAAA:test-2", "arn": "arn:aws:sts::111122223333:assumed-role/AmazonSageMaker-ExecutionRole/test-2", "accountId": "111122223333", "accessKeyId": "AAAAAAAAAAAAAAAAAAAA", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AAAAAAAAAAAAAAAAAAAA", "arn": "arn:aws:iam::111122223333:role/service-role/AmazonSageMaker-ExecutionRole", "accountId": "111122223333", "userName": "AmazonSageMaker-ExecutionRole" }, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2020-09-12T00:45:04Z" } }, "invokedBy": "im.amazonaws.com" }, "eventTime": "2020-09-12T00:49:04Z", "eventSource": "sagemaker.amazonaws.com", "eventName": "CreateEndpoint", "awsRegion": "us-east-1", "sourceIPAddress": "im.amazonaws.com", "userAgent": "im.amazonaws.com", "requestParameters": { "endpointName": "sagemaker-mxnet-ep", "endpointConfigName": "sagemaker-mxnet-epc", "tags": [] }, "responseElements": { "endpointArn": "arn:aws:sagemaker:us-east-1:111122223333:endpoint/sagemaker-mxnet-ep" }, "requestID": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "eventID": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "eventType": "AwsApiCall", "recipientAccountId": "111122223333" }
関連情報
- 言語
- 日本語

関連するコンテンツ
- 質問済み 7ヶ月前
- 質問済み 4ヶ月前