如何解决使用 cfn-init,ec2 实例在以下情况下不断停止
尝试使用 AWS Linux AMI 测试 cfn-init。实例正在创建但自动停止。即使我尝试手动启动实例,它也会立即自行停止。不知道我做错了什么,实例就这样停止了。我所做的就是尝试对此进行测试并使用 cfn-init 设置一个文件。这是从我在网上找到的模板中获取的。任何帮助表示赞赏。
{
"AWstemplateFormatVersion": "2010-09-09","Parameters": {
"VPC": {
"Type": "AWS::EC2::VPC::Id","Description": "Select the VPC where the EC2 instances will be created","ConstraintDescription": "must be an existing VPC"
},"Linuxsubnet": {
"Type": "AWS::EC2::subnet::Id","Description": "Select subnet for Linux Instance","ConstraintDescription": "must be an existing subnet"
},"RemoteAccessCIDR": {
"Description": "CIDR block to allow access to linux instances","Type": "String","Default": "10.255.0.0/16","AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})","ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
},"LinuxInstanceType": {
"Default": "t2.micro","Description": "Amazon EC2 Linux Instance Type","Type": "String"
},"LinuxSecurityGroupIds": {
"Type": "String","Description": "Name of security group to use",},"LinuxSSHPort": {
"Description": "SSH Port Number on Linux client","Type": "Number","Default": 22,"ConstraintDescription": "must be 22 or a number from 1024 to 65535"
},"LinuxVolumeSize": {
"Description": "Size of EBS volume for Linux instance in GB","Default": 8,"ConstraintDescription": "must be 8 or higher"
},"KeyPair": {
"Description": "Name of existing EC2 key pair for Linux Instances","Type": "AWS::EC2::KeyPair::KeyName"
}
},"Resources": {
"TestMachine": {
"Type": "AWS::EC2::Instance","Metadata": {
"AWS::CloudFormation::Init": {
"configSets": {
"CreateStuff": "CreateFile"
},"CreateFile" : {
"files": {
"/tmp/testing.txt": {
"content": "hopefully this works","mode": "0755","owner": "root","group": "root"
}
}
}
}
},"Properties": {
"ImageId": "ami-0533f2ba8a1995cf9","InstanceType": {
"Ref": "LinuxInstanceType"
},"subnetId": {
"Ref": "Linuxsubnet"
},"SecurityGroupIds": [{
"Ref": "LinuxSecurityGroupIds"
}],"KeyName": {
"Ref": "KeyPair"
},"Tags": [
{
"Key": "Automatic Patches","Value": "True"
},{
"Key": "Description","Value": "Service-Catalog-EC2-Reference-Architecture"
},{
"Key": "acr:CostCenter","Value": "986002"
},{
"Key": "acr:Project","Value": "aws infrastructure general"
},{
"Key": "Name","Value": "cfn-init-vm1"
}
],"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1","Ebs": {
"Encrypted": "true","DeleteOnTermination":"true","VolumeSize": {
"Ref": "LinuxVolumeSize"
}
}
}
],"UserData": {
"Fn::Base64" : { "Fn::Join" : ["",[
"#!/bin/bash -xe\n","yum install -y aws-cfn-bootstrap\n","# Install the files and packages from the Metadata\n","/opt/aws/bin/cfn-init -v "," --stack ",{ "Ref" : "AWS::StackName" }," --resource TestMachine "," --configsets CreateStuff "," --region ","us-east-1","\n"
]]}
}
}
}
},"Outputs": {
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。