如何解决我的 EC2 实例上的错误“关联 iip-assoc-xxxxxxxx 为非活动关联”?

1 分钟阅读
0

我在更新实例配置文件时收到 Amazon Elastic Compute Cloud (Amazon EC2) 实例的以下错误消息: “关联 iip-assoc-xxxxxxxx 为非活动关联” 如何解决此错误?

简短描述

当您尝试更新实例配置文件时,此错误通常会发生,但 API 仍未满足之前的取消关联。您可以使用 AWS 命令行界面 (AWS CLI) 确定未满足的取消关联是否导致错误,并更正问题。

注意:如果在运行 AWS CLI 命令时遇到错误,请确保您使用的是最新版本的 AWS CLI

解决方法

1.    运行以下命令以识别实例的实例配置文件关联:

aws ec2 describe-iam-instance-profile-associations --filters "Name=instance-id,Values=i-xxxxxxxxxxxxxxxxx"

命令输出有多个关联,每个关联都有唯一的关联 ID (AssociationID)和状态 (State)。有些关联处于正在关联状态,有些处于正在取消关联状态,如下面的示例输出所示:

{
"IamInstanceProfileAssociations": [
  {
    "AssociationId": "iip-assoc-xxxxxxxxxxxxxxxx",
    "InstanceId": "i-xxxxxxxxxxxxxxxx",
    "IamInstanceProfile": {
      "Arn": "arn:aws:iam::xxxxxxxxxx:instance-profile/xxxxxxx",
      "Id": "xxxxxxxxxxxxxxxxxx"
     },
    "State": "disassociating"
  },
 {
    "AssociationId": "iip-assoc-xxxxxxxxxxxxxxxx",
    "InstanceId": "i-xxxxxxxxxxxxxxxx",
    "IamInstanceProfile": {
      "Arn": "arn:aws:iam::xxxxxxxxxxxx:instance-profile/xxxxxxxxx",
      "Id": "xxxxxxxxxxxxxxxx"
     },
    "State": "associating"
  }
 ]
}

2.    运行以下命令以取消所有关联 ID 的关联,包括处于正在关联和正在取消关联状态的关联 ID。将 iip-assoc-xxxxxxxxxxxxxxxxxx 替换为适当的 association-id

aws ec2 disassociate-iam-instance-profile --association-id iip-assoc-xxxxxxxxxxxxxxxxxx

3.    取消关联所有关联 ID 后,请尝试再次更新实例配置文件

**注意:**如果在执行解决步骤后错误仍然存在,请停止并启动实例。然后,再次运行 disassociate-iam-instance-profile 命令。请注意,当您停止实例时,存储在实例存储卷中的数据会丢失。在停止实例之前,请查看停止实例的影响列表


相关信息

使用实例配置文件

如何在 Amazon EC2 实例上附加或替换实例配置文件?

AWS 官方
AWS 官方已更新 2 年前