在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'
Type: AWS::CloudFormation::WaitCondition
DependsOn: WikiDatabase
Properties:
Handle: {Ref: WaitHandle}
Count: '1'
Timeout: '600'
Database:
Type: AWS::EC2::Instance
Type: AWS::EC2::Instance
Properties:
UserData:
Fn::Base64:
Fn::Join:
- /opt/aws/bin/cfn-signal -e 0 -r "Wiki server setup complete" '
- {Ref: WaitHandle}
- '''
'
- {Ref: WaitHandle}
- '''
'
WebServer:
Type: AWS::EC2::Instance
Type: AWS::EC2::Instance
DependsOn: WaitCondition