3

CloudFormation 템플릿에서 사용자 정의 Ubuntu AMI를 사용하고 있는데 CREATE_FAILED AWS::AutoScaling::AutoScalingGroup WebServerGroup Received 0 SUCCESS signal(s) out of 1. Unable to satisfy 100% MinSuccessfulInstancesPercent requirement이라는 오류가 발생합니다. 생성 된 EC2 인스턴스의 로그 파일을 /var/log/cfn-init.log에 확인하고 로그 파일에서 Could not enable service cfn-hup을 확인했습니다. 아래는 내 템플릿의 일부입니다.우분투 : cfn-hup 서비스를 활성화 할 수 없습니다.

"WebServerGroup": { 
    "Type": "AWS::AutoScaling::AutoScalingGroup", 
    "Properties": { 
    "AvailabilityZones": { 
     "Ref": "AZs" 
    }, 
    "VPCZoneIdentifier": { 
     "Ref": "Subnets" 
    }, 
    "LaunchConfigurationName": { 
     "Ref": "LaunchConfig" 
    }, 
    "MinSize": "1", 
    "MaxSize": "10", 
    "DesiredCapacity": { 
     "Ref": "InstanceCount" 
    }, 
    "TargetGroupARNs" : [{"Ref": "TargetGroup"}], 
    "Tags": [{ 
     "Key": "opsworks_stack_id", 
     "Value": { 
     "Ref": "OpsWorksStackId" 
     }, 
     "PropagateAtLaunch": "true" 
    }] 
    }, 
    "CreationPolicy": { 
    "ResourceSignal": { 
     "Timeout": "PT15M" 
    } 
    }, 
    "UpdatePolicy": { 
    "AutoScalingRollingUpdate": { 
     "MinInstancesInService": "1", 
     "MaxBatchSize": "1", 
     "WaitOnResourceSignals": "true", 
     "PauseTime": "PT15M" 
    } 
    } 
}, 


"LaunchConfig" : { 
    "Type" : "AWS::AutoScaling::LaunchConfiguration", 
    "Metadata" : { 
    "Comment" : "Install a simple application", 
    "AWS::CloudFormation::Init" : { 
     "config" : { 

     "files" : { 

      "/etc/cfn/cfn-hup.conf" : { 
      "content" : { "Fn::Join" : ["", [ 
       "[main]\n", 
       "stack=", { "Ref" : "AWS::StackId" }, "\n", 
       "region=", { "Ref" : "AWS::Region" }, "\n" 
       ]]}, 
      "mode" : "000400", 
      "owner" : "root", 
      "group" : "root" 
      }, 

      "/etc/cfn/hooks.d/cfn-auto-reloader.conf" : { 
      "content": { "Fn::Join" : ["", [ 
       "[cfn-auto-reloader-hook]\n", 
       "triggers=post.update\n", 
       "path=Resources.LaunchConfig.Metadata.AWS::CloudFormation::Init\n", 
       "action=/usr/local/bin/cfn-init -v ", 
       "   --stack ", { "Ref" : "AWS::StackName" }, 
       "   --resource LaunchConfig ", 
       "   --region ", { "Ref" : "AWS::Region" }, "\n", 
       "runas=root\n" 
       ]]} 
      } 
     }, 

     "services" : { 
      "sysvinit" : { 
      "cfn-hup" : { "enabled" : "true", "ensureRunning" : "true", 
      "files" : ["/etc/cfn/cfn-hup.conf", "/etc/cfn/hooks.d/cfn-auto-reloader.conf"]} 
      } 
      } 
     } 
     } 
    }, 

    "Properties" : { 
     "AssociatePublicIpAddress" : "true", 
     "ImageId" : { "Ref" : "AmiId" }, 
     "SecurityGroups" : [ { "Ref" : "LoadBalancerSecurityGroup" } ], 
     "KeyName"  : { "Ref" : "KeyName" }, 
     "InstanceType" : { "Ref" : "InstanceType" }, 
     "IamInstanceProfile": {"Ref" :"RoleName"}, 
     "UserData"  : { "Fn::Base64" : { "Fn::Join" : ["", [ 
     "#!/bin/bash -xe\n", 
     "easy_install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n", 

     "/usr/local/bin/cfn-init -v ", 
     "   --stack ", { "Ref" : "AWS::StackName" }, 
     "   --resource LaunchConfig ", 
     "   --region ", { "Ref" : "AWS::Region" }, "\n", 

     "/usr/local/bin/cfn-signal -e $? ", 
     "   --stack ", { "Ref" : "AWS::StackName" }, 
     "   --resource WebServerGroup ", 
     "   --region ", { "Ref" : "AWS::Region" }, "\n", 

     "sed -i'' -e 's/.*requiretty.*//' /etc/sudoers", "\n", 
     "pip install --upgrade awscli", "\n", 

     "INSTANCE_ID=$(aws opsworks register ", 
     "   --use-instance-profile ", 
     "   --infrastructure-class ec2 ", 
     "   --region ", { "Ref" : "AWS::Region" }, 
     "   --stack-id ", { "Ref" : "OpsWorksStackId" }, 
     "   --override-hostname $(tr -cd 'a-z' < /dev/urandom |head -c8) --local 2>&1 |grep -o 'Instance ID: .*' |cut -d' ' -f3)", "\n", 

     "aws opsworks wait instance-registered ", 
     "   --region ", { "Ref" : "AWS::Region" }, 
     "   --instance-id $INSTANCE_ID", "\n", 

     "aws opsworks assign-instance ", 
     "   --region ", { "Ref" : "AWS::Region" }, 
     "   --instance-id $INSTANCE_ID ", 
     "   --layer-ids ", { "Ref": "OpsWorksLayerId" }, "\n" 
    ]]}} 
    } 
    } 

답변

2

나는 내 코드가 무엇이 잘못되었는지 알아냅니다. 그것의 cfn-hup 서비스. 설치 후 시작되지 않습니다. 사용자 데이터의 변경 사항을 확인하십시오. 아래는 업데이트 된 코드입니다.

"LaunchConfig" : { 
    "Type" : "AWS::AutoScaling::LaunchConfiguration", 
    "Metadata" : { 
    "Comment" : "Install a simple application", 
    "AWS::CloudFormation::Init" : { 
     "config" : { 

     "files" : { 

      "/etc/cfn/cfn-hup.conf" : { 
      "content" : { "Fn::Join" : ["", [ 
       "[main]\n", 
       "stack=", { "Ref" : "AWS::StackId" }, "\n", 
       "region=", { "Ref" : "AWS::Region" }, "\n" 
       ]]}, 
      "mode" : "000400", 
      "owner" : "root", 
      "group" : "root" 
      }, 

      "/etc/cfn/hooks.d/cfn-auto-reloader.conf" : { 
      "content": { "Fn::Join" : ["", [ 
       "[cfn-auto-reloader-hook]\n", 
       "triggers=post.update\n", 
       "path=Resources.LaunchConfig.Metadata.AWS::CloudFormation::Init\n", 
       "action=/usr/local/bin/cfn-init -v ", 
       "   --stack ", { "Ref" : "AWS::StackName" }, 
       "   --resource LaunchConfig ", 
       "   --region ", { "Ref" : "AWS::Region" }, "\n", 
       "runas=root\n" 
       ]]} 
      } 
     }, 

     "services" : { 
      "sysvinit" : { 
      "cfn-hup" : { "enabled" : "true", "ensureRunning" : "true", 
      "files" : ["/etc/cfn/cfn-hup.conf", "/etc/cfn/hooks.d/cfn-auto-reloader.conf"]} 
      } 
      } 
     } 
     } 
    }, 

    "Properties" : { 
     "AssociatePublicIpAddress" : "true", 
     "ImageId" : { "Ref" : "AmiId" }, 
     "SecurityGroups" : [ { "Ref" : "LoadBalancerSecurityGroup" } ], 
     "KeyName"  : { "Ref" : "KeyName" }, 
     "InstanceType" : { "Ref" : "InstanceType" }, 
     "IamInstanceProfile": {"Ref" :"RoleName"}, 
     "UserData"  : { "Fn::Base64" : { "Fn::Join" : ["", [ 
     "#!/bin/bash \n", 
     "easy_install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n", 
     "sudo ln /usr/local/bin/cfn-hup /etc/init.d/ \n", 
     "sudo initctl reload-configuration \n", 
     "sudo chmod 700 /etc/init.d/cfn-hup \n", 
     "sudo chown root:root /etc/init.d/cfn-hup \n", 
     "sudo update-rc.d cfn-hup defaults \n", 
     "sudo update-rc.d cfn-hup enable \n", 
     "/usr/local/bin/cfn-init -v ", 
     "   --stack ", { "Ref" : "AWS::StackName" }, 
     "   --resource LaunchConfig ", 
     "   --region ", { "Ref" : "AWS::Region" }, "\n", 

     "/usr/local/bin/cfn-signal -e $? ", 
     "   --stack ", { "Ref" : "AWS::StackName" }, 
     "   --resource WebServerGroup ", 
     "   --region ", { "Ref" : "AWS::Region" }, "\n", 

     "sed -i'' -e 's/.*requiretty.*//' /etc/sudoers", "\n", 
     "pip install --upgrade awscli", "\n", 

     "INSTANCE_ID=$(aws opsworks register ", 
     "   --use-instance-profile ", 
     "   --infrastructure-class ec2 ", 
     "   --region ", { "Ref" : "AWS::Region" }, 
     "   --stack-id ", { "Ref" : "OpsWorksStackId" }, 
     "   --override-hostname $(tr -cd 'a-z' < /dev/urandom |head -c8) --local 2>&1 |grep -o 'Instance ID: .*' |cut -d' ' -f3)", "\n", 

     "aws opsworks wait instance-registered ", 
     "   --region ", { "Ref" : "AWS::Region" }, 
     "   --instance-id $INSTANCE_ID", "\n", 

     "aws opsworks assign-instance ", 
     "   --region ", { "Ref" : "AWS::Region" }, 
     "   --instance-id $INSTANCE_ID ", 
     "   --layer-ids ", { "Ref": "OpsWorksLayerId" }, "\n" 
    ]]}} 
    } 
    } 
관련 문제