首页 > 解决方案 > aws_launch_configuration: timeout - last error: dial tcp :22: connectex: No connection could be made because the target machine主动拒绝它

问题描述

我有以下自动缩放组的启动配置:

resource "aws_launch_configuration" "ASG-launch-config" {
  #name = "ASG-launch-config"  # see: https://github.com/hashicorp/terraform/issues/3665
  name_prefix = "ASG-launch-config-"
  image_id = "ami-a4dc46db" #Ubuntu 16.04 LTS
  #image_id = "ami-b70554c8" #Amazon Linux 2
  instance_type = "t2.micro"
  security_groups = ["${aws_security_group.WEB-DMZ.id}"]
  key_name = "MyEC2KeyPair"
  #user_data = <<-EOF
  #            #!/bin/bash
  #            echo "Hello, World" > index.html
  #            nohup busybox httpd -f -p "${var.server_port}" &
  #          EOF


  provisioner "file" {
  source="script.sh"
  destination="/tmp/script.sh"
  }
  provisioner "remote-exec" {
  inline=[
  "chmod +x /tmp/script.sh",
  "sudo /tmp/script.sh"
  ]
  }
  connection {
  user="ubuntu"
  private_key="${file("MyEC2KeyPair.pem")}"
  }

  lifecycle {
    create_before_destroy = true
  }
}

错误:应用计划时出错:

发生 1 个错误:

我想运行一个 bash 脚本来基本上在创建的实例上安装 WordPress。该脚本在资源类型“aws_instance”“示例”中运行良好

如何解决这个问题?

标签: bashamazon-web-servicesterraformterraform-provider-aws

解决方案


听起来该实例正在拒绝您的流量。在没有配置脚本的情况下启动一个实例,看看您是否可以使用您提供的密钥通过 SSH 连接到它。您可能希望使用-v.


推荐阅读