0

Ma question concerne la réalisation d'attendre cfn-signal avant d'ajouter un EC2 de démarrage à l'ELB (si possible, en utilisant cloudformation). Pour l'instant, l'ELB commence à utiliser l'instance sans attendre qu'il soit prêt, pire, si je démarre le service apache seulement à la fin du "boot", il n'attend pas la période de grâce et supprime l'instance avant a fini d'être initialisé.comment attendre le signal cfn avant d'ajouter un EC2 de démarrage à l'ELB

ici est mon AutoScalingGroup conf:

"webServerASG": { 
    "Type": "AWS::AutoScaling::AutoScalingGroup", 

    "CreationPolicy": { 
    "ResourceSignal": { 
     "Timeout": "PT10M", 
     "Count": { "Ref": "WebServerDesiredCapacity" } 
    } 
    }, 
    "UpdatePolicy" : { 
    "AutoScalingReplacingUpdate" : { 
     "WillReplace" : true 
    }, 
    "AutoScalingRollingUpdate" : { 
     "MaxBatchSize" : 1, 
     "MinInstancesInService" : 1, 
     "MinSuccessfulInstancesPercent" : 75, 
     "SuspendProcesses" : [ "AlarmNotification", "ScheduledActions", "AZRebalance", "ReplaceUnhealthy", "HealthCheck", "Launch" ], 
     "WaitOnResourceSignals": true, 
     "PauseTime" : "PT10M" 
    } 
    }, 
    "Properties": { 
    "AvailabilityZones": [...], 
    "Cooldown": "60", 
    "HealthCheckGracePeriod": "560", 
    "HealthCheckType": "ELB", 
    "MaxSize": { "Ref": "WebServerMaxCapacity" }, 
    "MinSize": "1", 
    "DesiredCapacity": { "Ref": "WebServerDesiredCapacity" }, 
    "VPCZoneIdentifier": [...], 
    "NotificationConfigurations": [...], 
    "LaunchConfigurationName": { "Ref": "webServer01LC" }, 
    "LoadBalancerNames": [ { "Ref": "webServerLoadBalancerELB" } ], 
    "MetricsCollection": [...], 
    "TerminationPolicies": [ 
     "Default" 
    ] 
    } 
}, 

avec cette conf pour le LoadBalancer:

"webServerLoadBalancerELB": { 
    "Type": "AWS::ElasticLoadBalancing::LoadBalancer", 
    "Properties": { 
    "Subnets": [...], 
    "HealthCheck": { 
     "HealthyThreshold": "10", 
     "Interval": "30", 
     "Target": "HTTP:80/aws/healthcheck.php", 
     "Timeout": "5", 
     "UnhealthyThreshold": "2" 
    }, 
    "ConnectionDrainingPolicy": { 
     "Enabled": "true", 
     "Timeout": "300" 
    }, 
    "ConnectionSettings": { 
     "IdleTimeout": "60" 
    }, 
    "CrossZone": "true", 
    "SecurityGroups": [...], 
    "Listeners": [ 
     { 
     "LoadBalancerPort": "80", 
     "Protocol": "HTTP", 
     "InstancePort": "80", 
     "InstanceProtocol": "HTTP" 
     } 
    ] 
    } 
} 

et pour la LaunchConfiguration:

"webServer01LC": { 
    "Type": "AWS::AutoScaling::LaunchConfiguration", 
    "Properties": { 
    "AssociatePublicIpAddress": false, 
    "ImageId": {...}, 
    "InstanceType": "t2.small", 
    "KeyName": {...}, 
    "IamInstanceProfile": "EC2WebServerRole", 
    "SecurityGroups": [...], 
    "BlockDeviceMappings": [...], 
    "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ 
     "#!/bin/bash\n", 

     "echo '\n### pip install cloud-init : ' | tee --append /var/log//userData.log \n", 
     "pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz 2>> /var/log//userData.log\n", 
     "ln -s /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup >> /var/log//userData.log>&1\n", 


     "echo '\n### execute the AWS::CloudFormation::Init defined in the Metadata' | tee --append /var/log//userData.log \n", 
     "cfn-init -v", 
       " --region ", { "Ref" : "AWS::Region" }, 
       " --stack ", { "Ref" : "AWS::StackName" }, 
       " --resource lciTophubWebServer01LC ", 
       " \n", 

     "cfn-signal --exit-code $? --region ", { "Ref" : "AWS::Region" }, " --stack ", { "Ref" : "AWS::StackName" }, " --resource asgiTophubWebServerASG \n", 
     "echo '\n### end of the script!' | tee --append /var/log//userData.log \n" 
    ]]}} 
    }, 
    "Metadata": {...} 
} 

Répondre

0

J'ai découvert mon problème: Les vérifications d'état ELB sont exécutées sans pause, donc pendant la période de grâce, le les tests sont en cours. Une fois la période de grâce terminée, le groupe de mise à l'échelle automatique examine immédiatement les vérifications d'état ELB en cours.

Dans mon cas, j'avais "HealthyThreshold": "10" et "Interval": "30" donc il a fallu ELB 10 * 30 = 300 sec. pour changer d'avis (même 329,99 si je n'ai pas de chance) et c'est beaucoup trop long comparé au HealthCheckGracePeriod qui est seulement 560 (560 - 329,99 = 230,01 secondes à gauche pour avoir fini de démarrer).

J'ai abrégé ce délai "redevenu en bonne santé" en passant HealthyThreshold à 2: 560 - 99,99 = 460,01 sec. gauche pour commencer.