AWS System Manager 启动会话:调用 StartSession 操作时发生错误 (TargetNotConnected): 未连接

2024-01-10

Problem:

当我尝试使用 AWS System Session Manager CLI 命令在本地连接到正在运行的 EC2 实例时:aws ssm start-session --target i-123456

我收到错误:

An error occurred (TargetNotConnected) when calling the StartSession operation: i-123456 is not connected.

背景:

  • 托管在自定义 VPC 内的私有子网上的 Linux 2 实例
  • VPC 端点 https://docs.aws.amazon.com/systems-manager/latest/userguide/setup-create-vpc.html用于将 System Manager 连接到托管实例,无需 NAT GW 或 IGW。
  • 端点服务名称:
com.amazonaws.us-west-2.s3
com.amazonaws.us-west-2.ec2
com.amazonaws.us-west-2.ec2messages
com.amazonaws.us-west-2.ssm
com.amazonaws.us-west-2.ssmmessages
  • AWS CLI == 2.0.40
  • Python==3.7.4
  • 自定义 Terraform 模块,用于在私有子网之一内启动气流实例(请参阅下面的模块“airflow_aws_resources”)
  • 与此问题相关的唯一 .tf 文件是气流.tf https://github.com/marshall7m/tf_modules/blob/master/airflow-aws-resources/airflow.tf在模块“airflow_aws_resources”内。此文件包含通过 SSM 连接的 EC2 实例的安全组和实例配置文件配置。

使用 Terraform 重现:

module "airflow_aws_resources" {
  source                      = "github.com/marshall7m/tf_modules/airflow-aws-resources"
  resource_prefix             = "test"
  vpc_id                      = module.vpc.vpc_id
  env                         = "testing"
  private_bucket              = "test-bucket"
  private_subnets_ids         = module.vpc.private_subnets
  private_subnets_cidr_blocks = module.vpc.private_subnets_cidr_blocks

  create_airflow_instance     = true
  create_airflow_instance_sg  = true
  create_airflow_db           = false
  create_airflow_db_sg        = false
  airflow_instance_ssm_access = true
  airflow_instance_ssm_region = "us-west-2"

  airflow_instance_ami  = "ami-0841edc20334f9287"
  airflow_instance_type = "t2.micro"

}

resource "aws_security_group" "vpc_endpoints" {
  name        = "test-vpc-endpoint-sg"
  description = "Default security group for vpc endpoints"
  vpc_id = module.vpc.vpc_id
  
  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["10.0.0.32/28", "10.0.0.64/28"]
  }

  ingress {
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    #private subnet cidr blocks
    cidr_blocks = ["10.0.0.32/28", "10.0.0.64/28"]
  }

  egress {
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = ["10.0.0.32/28", "10.0.0.64/28"]
  }
  egress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["10.0.0.32/28", "10.0.0.64/28"]
  }
}

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  version = "2.44.0"
  name = "test-vpc" 
  cidr = "10.0.0.0/24"

  azs = ["us-west-2a", "us-west-2b"]
  
  private_subnets = ["10.0.0.32/28", "10.0.0.64/28"]
  private_dedicated_network_acl = true
  private_subnet_suffix = "private"

  public_subnets = ["10.0.0.96/28", "10.0.0.128/28"]
  public_dedicated_network_acl = true
  public_subnet_suffix = "public"

  enable_s3_endpoint = true

  enable_ec2messages_endpoint = true
  ec2messages_endpoint_security_group_ids = [aws_security_group.vpc_endpoints.id]
  enable_ec2_endpoint = true
  ec2_endpoint_security_group_ids = [aws_security_group.vpc_endpoints.id]

  enable_ssm_endpoint = true
  ssm_endpoint_security_group_ids = [aws_security_group.vpc_endpoints.id]
  enable_ssmmessages_endpoint = true
  ssmmessages_endpoint_security_group_ids = [aws_security_group.vpc_endpoints.id]

  enable_nat_gateway = false
  single_nat_gateway = false
  enable_vpn_gateway = false

  create_database_subnet_route_table = false
  create_database_internet_gateway_route = false
  create_database_subnet_group = false
   
  manage_default_network_acl = false 
  enable_dns_hostnames = true
  enable_dns_support = true
  
  private_inbound_acl_rules = [
    {
      "description": "Allows inbound https traffic for aws s3 package requests"
      "cidr_block": "0.0.0.0/0",
      "from_port": 443,
      "to_port": 443,
      "protocol": "tcp",
      "rule_action": "allow",
      "rule_number": 101
    },
    { 
      "description": "Allows inbound http traffic for aws s3 package requests"
      "cidr_block": "0.0.0.0/0",
      "from_port": 80,
      "to_port": 80,
      "protocol": "tcp",
      "rule_action": "allow",
      "rule_number": 102
    }
  ]
  private_outbound_acl_rules = [
    {
      "description": "Allows outbound https traffic for aws s3 package requests"
      "cidr_block": "0.0.0.0/0",
      "from_port": 443,
      "to_port": 443,
      "protocol": "tcp",
      "rule_action": "allow",
      "rule_number": 101
    },
    { 
      "description": "Allows outbound http traffic for aws s3 package requests"
      "cidr_block": "0.0.0.0/0",
      "from_port": 80,
      "to_port": 80,
      "protocol": "tcp",
      "rule_action": "allow",
      "rule_number": 102
    }
  ]
  
  vpc_endpoint_tags = {
    type = "vpc-endpoint"
  }
}

尝试:

#1

我尝试了 EC2 控制台 SSM 中的故障排除提示(AWS Ec2 控制台 >> 实例 ID >> 连接 >> 会话管理器):

  1. SSM 代理已预安装在 AWS Linux 实例类型上。尽管我通过 SSH 访问实例并运行进行了双重检查sudo status amazon-ssm-agent返回:amazon-ssm-agent start/running, process 1234

  2. 上面显示的 EC2 实例配置文件包含所需的AmazonSSMManagedInstanceCore policy

  3. 我已完成会话管理器先决条件。

#2

附加AmazonSSMFullAccess使用以下命令的用户:aws ssm start-session --target i-123456

通过 SSM 连接实例时出现同样的错误:

An error occurred (TargetNotConnected) when calling the StartSession operation: i-123456 is not connected.

#3

将 HTTPS 入站/出站流量从 VPC 终端节点的关联私有子网添加到 EC2 实例安全组(请参阅气流.tf https://github.com/marshall7m/tf_modules/blob/master/airflow-aws-resources/airflow.tf)

同样的错误:

An error occurred (TargetNotConnected) when calling the StartSession operation: i-123456 is not connected.

#4

在系统管理器控制台中,我使用了“快速设置”选项,并使用中指定的实例配置文件配置了“快速设置”气流.tf https://github.com/marshall7m/tf_modules/blob/master/airflow-aws-resources/airflow.tf以及具有默认角色的系统管理员角色。 ec2 实例在快速设置页面中成功注册了“托管实例”。

同样的错误:

An error occurred (TargetNotConnected) when calling the StartSession operation: i-123456 is not connected.

#5

鉴于这是一个测试 VPC 和 EC2 实例,我尝试允许来自所有 IPv4 源 (0.0.0.0/0) 的所有类型的流量访问以下资源:

  • 私有子网 NACL
  • EC2实例安全组
  • 与以下接口/网关端点关联的安全组:
com.amazonaws.us-west-2.s3
com.amazonaws.us-west-2.ec2
com.amazonaws.us-west-2.ec2messages
com.amazonaws.us-west-2.ssm
com.amazonaws.us-west-2.ssmmessages

通过 SSM 连接实例时出现同样的错误:

An error occurred (TargetNotConnected) when calling the StartSession operation: i-123456 is not connected.

I would 参考这里 https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started.html确保一切设置正确。我首先添加配置文件参数。如果这仍然不起作用,当我的个人资料的默认区域与我想要开始活动会话的区域不同时,我遇到了类似的问题。因此,我还需要使用区域参数。下面的 .ssh/config 示例:

host ssh i-abc123
ProxyCommand sh -c "aws --region desired_region --profile my_profile ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"

我还鼓励使用 AWS CLI v2。将 .ssh/config 配置为如上所示后,只需在 CLI 中执行以下命令:

ssh i-abc123
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AWS System Manager 启动会话:调用 StartSession 操作时发生错误 (TargetNotConnected): 未连接 的相关文章

随机推荐

  • Anaconda pip 离线安装包括依赖项(tensorflow)

    我想在没有互联网连接的系统上的 anaconda 环境中安装 tensorflow 并且我没有 root 访问权限 即我只想将其安装到本地用户 我已经下载了tensorflow的 whl文件和所需的依赖项 并将它们复制到我要使用的机器上 进
  • 从 infix 更改为 postfix 有什么好处?

    我今天看书了 它引入了从中缀变为后缀的算法 有什么好处 提前致谢 其一 与计算中缀表达式不同 您可以借助堆栈从左到右一次扫描轻松计算后缀表达式 其次 后缀表达式中不需要括号和优先规则等概念
  • 是否可以在 pandas 中使用自定义过滤器功能?

    我可以使用我的辅助函数来确定投篮是否为三指针作为 Pandas 中的过滤函数吗 我的实际功能要复杂得多 但我针对这个问题简化了它 def isThree x y return x y 3 print data isThree data x
  • 如何在iphone中获取gmsmapview的坐标中心

    我正在使用新的 iOS 版 Google 地图 SDK 我可以从 GMSMapView center 获取真实坐标吗 现在它返回一个 CGPoint 的值 但它不是真正的坐标 感谢和问候 Use the projection method
  • 从 Kotlin 隐藏静态 Java 方法

    我们正在将许多 java 静态方法转换为 kotlin 扩展函数 然而 我们需要保留一些 JUST FOR JAVA 的方法 我们希望强制 kotlin 代码使用扩展函数 有没有办法从 kotlin 中隐藏 java 静态方法 您可以使用注
  • Google Apps脚本:复制电子表格非常慢

    我有一个 Web 应用程序 其中脚本连接到电子表格 在脚本中 我从电子表格中查找文件的 ssid 打开该文件 然后复制并重命名它 相关行如下所示 var copy SpreadsheetApp openById ssid copy newN
  • sonarqube 忽略 sonar.junit.reportPaths

    我有一个 gradle 项目 它应用了 sonarqube gradle 插件 版本 2 6 我在我团队的 sonarqube 服务器版本 6 4 版本 25310 上运行它 根据文档 https docs sonarqube org di
  • å 在 xml 文件中是否有效?

    IE 不喜欢在 XML 文件中显示 字符 这是一个 IE 问题还是 和类似的字符确实是无效的 XML 我是否必须创建 xx 所有这些字母的值 Michel 顺便说一句 字符位于 CDATA 标记内 声明是这样的 嗯 似乎无法将 xml 声明
  • 角度 4 中的 html2canvas

    我可以在 Angular 4 中使用 html2canvas 截取屏幕截图 但我需要使用 http post 调用将字符串图像发送到服务器端 成分 import Component OnInit NgZone from angular co
  • 如何覆盖Visual Studio 2017社区的编译命令[重复]

    这个问题在这里已经有答案了 我想用一个简单的 shell 脚本覆盖默认的 Visual Studio C 编译器 我想要的是捕获参数 例如文件名 并创建一些统计信息 但是我想完全覆盖编译过程 也就是说 我想从我的 shell 脚本调用原始编
  • 模拟滚动视图内的拖动

    我正在努力拦截并重新发送发送到滚动视图的手势 我想做的事 杀死滚动视图中的所有手势识别器 我已经做到了这一点 在滚动视图中添加新的手势识别器 我也做到了这一点 使新识别器的行为与旧识别器相同 我还没有做到这一点 我需要帮助才能做到这一点 我
  • Boto - AWS SNS 如何提取主题的 ARN 号

    创建 AWS SNS 主题时 a conn create topic topicname 或获取已创建的主题 a conn get all topics 结果是 u CreateTopicResponse u ResponseMetadat
  • 如何减少 python 导入包的 Visual Studio 代码中的自动完成延迟?

    我正在使用 python 3 7 3 和 Visual Studio 代码 1 33 1 当我导入任何库 如 cv2 或 numpy 并尝试使用它时 自动完成需要 4 5 秒来识别函数 当我使用 print slice 等默认函数时 它们会
  • 是否必须使用 typedef 将 size_t 定义为五种标准无符号整数类型之一?

    C11标准写道 6 2 5 类型 4 有五个标准有符号整数类型 指定为signed char short int int long int and long long int 因此 五种标准无符号整数类型将是unsigned char un
  • 无法在 Android Studio 3.0 AVD Manager 或 SDK Manager 中下载系统映像

    When I try to list and download system images in AVD Manager nothing shows up in the list See below None of the three ta
  • Java 是否通过具有标记为 Final 的单个实现者的接口来优化方法调用?

    如果我引用一个类并调用它的方法 并且该类或方法是最终的 我的理解是编译器或 JVM 会用更便宜的静态分派替换动态分派 因为它可以准确确定哪个版本将被调用 但是 如果我有一个接口的引用 并且该接口当前只有一个实现者 并且该实现者是最终的或者该
  • 什么时候我们需要将数组的大小作为参数传递

    我对在 C C 中传递数组有点困惑 我看到一些签名是这样的情况 void f int arr 有些是这样的 void f int arr int size 有人可以详细说明有什么区别以及何时以及如何使用它吗 首先 传递给函数的数组实际上传递
  • 以编程方式裁剪位图的底部部分

    我有一张从相机拍摄的位图 我想裁剪图像 使其只留下底部部分 裁剪后的图像应比原始位图的高度低 80 因此我只需要从左边缘开始的底部部分的 20 我在代码中明确地执行此操作 没有任何 Android 裁剪意图 一张图片来形象化我想要实现的目标
  • 如何检测 JSF 2.0 页面中的字段值更改

    我正在使用 JSF 2 0 开发一个相当大且复杂的页面 其中包含许多字段 页面底部将有一个退出命令按钮 当用户选择退出选项时 我需要检测用户是否在页面的某个字段中输入了任何值 我现在使用支持 bean 中每个字段值的 null 检查来执行此
  • AWS System Manager 启动会话:调用 StartSession 操作时发生错误 (TargetNotConnected): 未连接

    Problem 当我尝试使用 AWS System Session Manager CLI 命令在本地连接到正在运行的 EC2 实例时 aws ssm start session target i 123456 我收到错误 An error