Cloudformation Init 配置文件不写入文件

Cloudformation Init config files not writing the files

我正在使用 AWS Cloudformation 脚本启动一个自动扩展的 Ec2 实例 - 下面提供了示例代码

    "GatewayLabAutoScalingGroup": {
  "Metadata": {
    "AWS::CloudFormation::Init": {
      "config": {
        "commands": {
          "a_install_pip": {
            "command": "pip install requests boto3"
          },
          "c_restart_cron": {
            "command": "service crond restart"
          },
          "d_restart_cfn_hup": {
            "command": "service cfn-hup restart"
          }
        },
        "files": {
          "/etc/cfn/cfn-hup.conf": {
            "content": {
              "Fn::Join": [
                "",
                [
                  "[main]\nstack=",
                  {
                    "Ref": "AWS::StackName"
                  },
                  "\nregion=",
                  {
                    "Ref": "AWS::Region"
                  },
                  "\nverbose=true\ninterval=1\n"
                ]
              ]
            },
            "group": "root",
            "mode": "000644",
            "owner": "root"
          },
          "/usr/local/sbin/join_ad_script.sh": {
            "content": {
              "Fn::Join": [
                "",
                [
                  "sudo yum -y update\nsudo yum -y install sssd realmd krb5-workstation\nsudo realm leave\n\nDOMAIN=\"",
                  {
                    "Ref": "SimpleADDomain"
                  },
                  "\"\n\ncat <<EOF > /etc/resolv.conf\nnameserver ",
                  {
                    "Fn::Select": [
                      0,
                      {
                        "Fn::GetAtt": [
                          "WorkspacesSimplead",
                          "DnsIpAddresses"
                        ]
                      }
                    ]
                  },
                  "\nnameserver ",
                  {
                    "Fn::Select": [
                      1,
                      {
                        "Fn::GetAtt": [
                          "WorkspacesSimplead",
                          "DnsIpAddresses"
                        ]
                      }
                    ]
                  },
                  "\nEOF\n\n# empty all current sssd cache\nsss_cache -E\n\necho ",
                  {
                    "Ref": "SimpleADPassword"
                  },
                  " | sudo realm join -U Administrator@${DOMAIN^^} ${DOMAIN^^} --verbose\nsudo sed -re 's/^(PasswordAuthentication)([[:space:]]+)no/\1\2yes/' -i.`date -I` /etc/ssh/sshd_config\necho \"enumerate=true\" >> /etc/sssd/sssd.conf\nsudo service sssd restart\nsudo service sshd restart\n\n# empty all current sssd cache\nsss_cache -E\n"
                ]
              ]
            },
            "group": "root",
            "mode": "000755",
            "owner": "root"
          }
        }
      }
    }
  },
  "Properties": {
    "AvailabilityZones": [
      {
        "Fn::Select": [
          0,
          {
            "Fn::GetAZs": ""
          }
        ]
      }
    ],
    "HealthCheckGracePeriod": 300,
    "HealthCheckType": "EC2",
    "LaunchConfigurationName": {
      "Ref": "GatewayLabLaunchConfiguration"
    },
    "LoadBalancerNames": [

    ],
    "MaxSize": 2,
    "MinSize": 1,
    "Tags": [
      {
        "Key": "Name",
        "PropagateAtLaunch": true,
        "Value": "hub-autoscaling"
        }
      }
    ],
    "VPCZoneIdentifier": [
      {
        "Ref": "EC2SubnetSubnet1"
      }
    ]
  },
  "Type": "AWS::AutoScaling::AutoScalingGroup",
  "UpdatePolicy": {
    "AutoScalingRollingUpdate": {
      "MaxBatchSize": 1,
      "MinInstancesInService": 1,
      "PauseTime": "PT60S"
    }
  }
}

实例中没有写入文件 该实例即将出现在私有 VPC 中 我们在端口 8080

上配置了代理

实例在没有代理的情况下连接到 NAT 网关时工作正常

我打开了端口 80、22 和 443

userdata 语句最初是 运行 然后他们调用 cfn-init 脚本

脚本中有一些错误,它们从未完成;上面提到的问题之一是我在代理后面的实例

获取代理配置作为 UserData 的一部分很有帮助