AWS云形成不能有效的实例ID

时间:2019-01-18 23:53:52

标签: amazon-web-services amazon-cloudformation

我正在AWS中创建一个cloudformation模板。我仍然遇到错误: WaitCondition收到失败的消息:“ ValidationError:”,唯一标识为:i-04885f92b0b4a99ab

我尝试更改实例ID。和许多其他方式。这些都不起作用。

AWS :: CloudFormation :: WaitCondition发生错误

 {
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "KeyName": {
        "Description": "Name of an existing EC2 KeyPair to enable       SSH access to the instances",
        "Type": "AWS::EC2::KeyPair::KeyName"
      },
      "InstanceType": {
        "Description": "FormEngine EC2 instance type",
        "Type": "String",
        "Default": "t2.micro"
      }
    },
    "Mappings": {
"AWSInstanceType2Arch": {
  "t2.micro": {
    "Arch": "64"
  }
},
"AWSRegionArch2AMI": {
  "us-west-2": {
    "64": "ami-f2d3638a"
  }
}
    },
    "Resources": {
      "WebServerGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
          "GroupDescription": "Enable SSH and HTTP access",
          "SecurityGroupIngress": [
            {
              "IpProtocol": "tcp",
              "FromPort": "22",
              "ToPort": "22",
              "CidrIp": "0.0.0.0/0"
            },
            {
              "IpProtocol": "tcp",
              "FromPort": "80",
              "ToPort": "80",
              "CidrIp": "0.0.0.0/0"
      }
    ]
  }
},
"CfnUser": {
  "Type": "AWS::IAM::User",
  "Properties": {
    "Path": "/",
    "Policies": [
      {
        "PolicyName": "Admin",
        "PolicyDocument": {
          "Statement": [
            {
              "Effect": "Allow",
              "Action": "*",
              "Resource": "*"
            }
          ]
        }
      }
    ]
  }
},
"HostKeys": {
  "Type": "AWS::IAM::AccessKey",
  "Properties": {
    "UserName": {
      "Ref": "CfnUser"
    }
  }
},
"WebServer": {
  "Type": "AWS::EC2::Instance",
  "Metadata": {
    "AWS::CloudFormation::Init": {
      "config": {
        "packages": {
          "yum": {
            "java-1.6.0-openjdk": [],
            "tomcat6": [],
            "httpd": []
          }
        },
        "files": {
          "/var/www/html/index.html": {
            "source": "http://a00807428-lab02/index.html",
            "mode": "000600",
            "owner": "apache",
            "group": "apache"
          },
          "/var/www/html/index.html": {
            "source": "http://a00807428-lab02/index.html",
            "mode": "000600",
            "owner": "apache",
            "group": "apache"
          }
        }
      }
    }
  },
  "Properties": {
    "ImageId": {
      "Fn::FindInMap": [
        "AWSRegionArch2AMI",
        {
          "Ref": "AWS::Region"
        },
        {
          "Fn::FindInMap": [
            "AWSInstanceType2Arch",
            {
              "Ref": "InstanceType"
            },
            "Arch"
          ]
        }
      ]
    },
    "InstanceType": {
      "Ref": "InstanceType"
    },
    "SecurityGroups": [
      {
        "Ref": "WebServerGroup"
      }
    ],
    "KeyName": {
      "Ref": "KeyName"
    },
    "Tags": [
      {
        "Key": "Name",
        "Value": "WebServer"
      }
    ],
    "UserData": {
      "Fn::Base64": {
        "Fn::Join": [
          "",
          [
            "#!/bin/bash -v\n",
            "date > /home/ec2-user/starttime\n",
            "yum update -y aws-cfn-bootstrap\n",
            "## Error reporting helper function\n",
            "function error_exit\n",
            "{\n",
            "   /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '",
            {
              "Ref": "WaitHandle"
            },
            "'\n",
            "   exit 1\n",
            "}\n",
            "## Initialize CloudFormation bits\n",
            "/opt/aws/bin/cfn-init -v -s ",
            {
              "Ref": "AWS::StackId"
            },
            " -r FormEngine",
            "   --access-key ",
            {
              "Ref": "HostKeys"
            },
            "   --secret-key ",
            {
              "Fn::GetAtt": [
                "HostKeys",
                "SecretAccessKey"
              ]
            },
            "   --region ",
            {
              "Ref": "AWS::Region"
            },
            " > /tmp/cfn-init.log 2>&1 || error_exit $(</tmp/cfn-init.log)\n",


            "# Configure Apache HTTPD\n",
            "chkconfig httpd on\n",
            "chkconfig --level 345 httpd on\n",

            "# Start servers\n",

            "/etc/init.d/httpd start\n",
            "# Send signal to WaitHandle that the setup is completed\n",
            "/opt/aws/bin/cfn-signal",
            " -e 0",
            " '",
            {
              "Ref": "WaitHandle"
            },
            "'",
            "\n",
            "date > /home/ec2-user/stoptime"
          ]
        ]
      }
    }
  }
},
"WaitHandle": {
  "Type": "AWS::CloudFormation::WaitConditionHandle"
},
"WaitCondition": {
  "Type": "AWS::CloudFormation::WaitCondition",
  "DependsOn": "WebServer",
  "Properties": {
    "Handle": {
      "Ref": "WaitHandle"
    },
    "Timeout": "1200"
  }
},
"IPAddress": {
  "Type": "AWS::EC2::EIP"
},
"IPAssoc": {
  "Type": "AWS::EC2::EIPAssociation",
  "Properties": {
    "InstanceId": {
      "Ref": "WebServer"
    },
    "EIP": {
      "Ref": "IPAddress"
    }
  }
}
    },
    "Outputs": {
      "InstanceIPAddress": {
        "Value": {
          "Ref": "IPAddress"
              },
        "Description": "public IP address of the new WebServer"
      },
      "InstanceName": {
        "Value": {
          "Fn::GetAtt": [
            "WebServer",
            "PublicDnsName"
          ]
        },
        "Description": "public DNS name of the new WebServer"
      }
    }
  }

成功创建了云信息。

0 个答案:

没有答案