无法为通过 SageMaker 创建的 ec2 关联另一个角色

问题描述 投票:0回答:1

我无法为通过 CreatePresignedNotebookInstanceUrl 创建的 EC2 实例关联新角色。

我通过 sagemaker 创建了一个笔记本实例,如下所示:cloud.hacktricks.xyz。我的 EC2 实例托管在 AWS 拥有的账户中。当我这样做时:

aws sts get-caller-identity 

{ 
   "UserId": XXXXXXXXXX
   "Account": YYYYYYYYY
   "Arn":"arn:aws:sts::YYYYYYYYY:assumed-role/sagemakerRole/SageMaker
  
}

使用此角色无法执行

aws s3 ls
,这是正常的,因此我尝试关联另一个角色MyNewRole,其中包含:AdministratorAccessAmazonS3FullAccessAmazonSSMManagedInstanceCore
aws ec2 associate-iam-instance-profile --instance-id <ec2-instance-id-of-notebook> --iam-instance-profile Name=MyNewRole 

它给了我: 调用AssociateIamInstanceProfile操作时出现错误(InvalidInstanceID.NotFound):实例ID不存在。

怎么可能找不到实例呢?哦_O

amazon-web-services amazon-ec2 amazon-sagemaker
1个回答
0
投票

要更新 SageMaker 笔记本实例的 IAM 角色,您必须停止笔记本实例并更新笔记本的关联 IAM 角色。 控制台说明 - https://docs.aws.amazon.com/sagemaker/latest/dg/nbi-update.html

如果您使用 CLI,请使用 stop-notebook-instanceupdate-notebook-instance 调用。

例如,

aws sagemaker stop-notebook-instance \
--notebook-instance-name my-notebook-name

# wait until the notebook is stopped and then run the update command
aws sagemaker update-notebook-instance \
--notebook-instance-name my-notebook-name \
--role-arn my-new-role

您还可以将这些策略直接附加到您的 SageMaker 承担的角色(而不是更新笔记本的角色)。

虽然 SageMaker 笔记本实例使用 EC2,但该服务由 AWS 托管,因此您将无法直接更新 EC2 实例(出于同样的原因,您不会在正在运行的 EC2 实例列表中看到 EC2 实例)。

© www.soinside.com 2019 - 2024. All rights reserved.