在heat中,一个instance的创建成功信号是在这个instance状态成为active之后发出的,这时候user-data可能还没有执行。但是heat已经认为这个resource创建成功了,开始调度下一个resource的创建。
如果我们要建立一个webserver,这个webserver需要在databaseServer执行完user-data之后才开始创建,就需要使用AWS的waitcondition通讯机制。
- 整个流程如下:
Create WaitHandler ->
WaitHandler Done ->
Create "Database" (Dependon WaitHandler) ->
Database Done ->
Create "WaitCondition" (Dependon Database) ->
Wait for Database signal ->
Database send signal to WaitHandler ->
WaitCondition Done ->
Create WebServer (Dependon WaitCondition)->
WebServer Done
- Template例子:
WaitHandle: {Type: ‘AWS::CloudFormation::WaitConditionHandle‘}
WaitCondition:
Type: AWS::CloudFormation::WaitCondition
DependsOn: WikiDatabase
Properties:
Handle: {Ref: WaitHandle}
Count: ‘1‘
Timeout: ‘600‘
Database:
Type: AWS::EC2::Instance
Properties:
UserData:
Fn::Base64:
Fn::Join:
- /opt/aws/bin/cfn-signal -e 0 -r "Wiki server setup complete" ‘
- {Ref: WaitHandle}
- ‘‘‘
‘
WebServer:
Type: AWS::EC2::Instance
DependsOn: WaitCondition
Heat中的AWS::WaitCondition的使用