2016-07-23 73 views
0

我有一個CloudFormation腳本,在VPC中部署單個實例。 該腳本僅在實例具有公共IP時起作用。沒有公共IP地址,模板部署在WaitCondition階段失敗。我想那是因爲WaitCondition需要實例可以訪問Internet?CloudFormation WaitCondition需要公共訪問

而不是分配一個公共IP,它會工作,如果我在服務器上設置代理地址?所以這個實例通過Web代理訪問Internet。如果是這種情況,那麼代理上的網址需要列入白名單?並且可以在用戶數據中添加add proxy address命令嗎?

下面是我的模板:

"Mappings": { 
    "AWSRegion2AMI": { 
     "ap-southeast-2": { 
     "Windows2008r2": "ami-27b39a44", 
     "Windows2012r2": "ami-83b198e0" 
     } 
    } 

    }, 

    "Resources": { 
    "DomainController": { 
     "Type": "AWS::EC2::Instance", 
     "Metadata": { 
     "AWS::CloudFormation::Init": { 
      "config": { 
      "files": { 
       "c:\\cfn\\cfn-hup.conf": { 
       "content": { 
        "Fn::Join": ["", [ 
        "[main]\n", 
        "stack=", { 
         "Ref": "AWS::StackId" 
        }, "\n", 
        "region=", { 
         "Ref": "AWS::Region" 
        }, "\n" 
        ]] 
       } 
       }, 

       "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf": { 
       "content": { 
        "Fn::Join": ["", [ 
        "[cfn-auto-reloader-hook]\n", 
        "triggers=post.update\n", 
        "path=Resources.DomainController.Metadata.AWS::CloudFormation::Init\n", 
        "action=cfn-init.exe -v -s ", { 
         "Ref": "AWS::StackId" 
        }, 
        " -r DomainController", 
        " --region ", { 
         "Ref": "AWS::Region" 
        }, "\n" 
        ]] 
       } 
       }, 

       "C:\\cfn\\RunCommand.bat": { 
       "content": "%~1\nIF %ERRORLEVEL% GTR 10 (exit /b 1) else (exit /b 0)" 
       } 
      }, 

      "commands": { 
       "1-run-dcpromo": { 
       "command": { 
        "Fn::Join": ["", [ 
        "C:\\cfn\\RunCommand.bat \"dcpromo /unattend /ReplicaOrNewDomain:Domain /NewDomain:Forest /NewDomainDNSName:", { 
         "Ref": "DomainDNSName" 
        }, 
        " /ForestLevel:4 /DomainNetbiosName:", { 
         "Ref": "DomainNetBIOSName" 
        }, 
        " /DomainLevel:4 /InstallDNS:Yes /ConfirmGc:Yes /CreateDNSDelegation:No /DatabasePath:\"C:\\Windows\\NTDS\" /LogPath:\"C:\\Windows\\NTDS\" /SYSVOLPath:\"C:\\Windows\\SYSVOL\" /SafeModeAdminPassword=", { 
         "Ref": "RestoreModePassword" 
        }, 
        " /RebootOnCompletion:Yes\"" 
        ]] 
       }, 
       "waitAfterCompletion": "forever" 
       }, 
       "2-signal-success": { 
       "command": { 
        "Fn::Join": ["", [ 
        "cfn-signal.exe -e 0 \"", { 
         "Fn::Base64": { 
         "Ref": "DomainControllerWaitHandle" 
         } 
        }, "\"" 
        ]] 
       } 
       } 
      }, 

      "services": { 
       "windows": { 
       "cfn-hup": { 
        "enabled": "true", 
        "ensureRunning": "true", 
        "files": ["c:\\cfn\\cfn-hup.conf", "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf"] 
       } 
       } 
      } 
      } 
     } 
     }, 

     "Properties": { 
     "ImageId": { 
      "Fn::FindInMap": ["AWSRegion2AMI", { 
      "Ref": "AWS::Region" 
      }, "Windows2008r2"] 
     }, 
     "InstanceType": { 
      "Ref": "InstanceType" 
     }, 
     "NetworkInterfaces": [{ 
      "AssociatePublicIpAddress": "false", 
      "DeviceIndex": "0", 
      "SubnetId": { 
      "Ref": "SubnetId" 
      } 
     }], 

     "KeyName": { 
      "Ref": "KeyName" 
     }, 

     "UserData": { 
      "Fn::Base64": { 
      "Fn::Join": ["", [ 
       "<script>\n", 

       "cfn-init.exe -v -s ", { 
       "Ref": "AWS::StackId" 
       }, 
       " -r DomainController ", 
       " --region ", { 
       "Ref": "AWS::Region" 
       }, "\n", 

       "</script>" 
      ]] 
      } 
     } 
     } 
    }, 

    "DomainControllerWaitCondition": { 
     "Type": "AWS::CloudFormation::WaitCondition", 
     "DependsOn": "DomainController", 
     "Properties": { 
     "Handle": { 
      "Ref": "DomainControllerWaitHandle" 
     }, 
     "Timeout": "1500" 
     } 
    }, 

    "DomainControllerWaitHandle": { 
     "Type": "AWS::CloudFormation::WaitConditionHandle" 
    } 

回答

0

傳中,代理通過增加這些參數來CFN-signal.exe:

--http-proxy 
An HTTP proxy (non-SSL). Use the following format: http://user:[email protected]:port 

--https-proxy 
An HTTPS proxy. Use the following format: https://user:[email protected]:port 

的信號被髮送到一個S3桶。您可以加入白名單是這樣的:

https://cloudformation-waitcondition-*.s3.amazonaws.com 

注意:您還可以使用S3 VPC終點功能允許私人子網內資源訪問S3。 http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-endpoints.html