2017-09-29 51 views
0

根據我的理解,如果更新依賴的資源,應該更新DependsOn指定的資源。我看到這是一些資源,但它似乎不適用於自定義資源。DependsOn和Cloudformation自定義資源

我正在使用API​​Gateway,並嘗試使用自定義資源來部署與舞臺相關的資源更新時的階段。這是因爲在需要部署更新時,包含的AWS::ApiGateway::Stage & AWS::ApiGateway::Deployment似乎不能很好地工作。

我有以下模板(剪斷,以供參考):

<snip> 
pipelineMgrStateMachine: 
    Type: AWS::StepFunctions::StateMachine 
    Properties: 
    <snip> 

webhookEndPointMethod: 
    Type: AWS::ApiGateway::Method 
    DependsOn: pipelineMgrStateMachine 
    Properties: 
    RestApiId: !Ref pipelineMgrGW 
    ResourceId: !Ref webhookEndPointResource 
    HttpMethod: POST 
    AuthorizationType: NONE 
    Integration: 
     Type: AWS 
     IntegrationHttpMethod: POST 
     Uri: !Sub arn:aws:apigateway:${AWS::Region}:states:action/StartExecution 
     Credentials: !GetAtt pipelineMgrGWRole.Arn 
     PassthroughBehavior: WHEN_NO_TEMPLATES 
     RequestTemplates: 
     application/json: !Sub | 
      { 
      "input": "$util.escapeJavaScript($input.json('$'))", 
      "name": "$context.requestId", 
      "stateMachineArn": "${pipelineMgrStateMachine}" 
      } 
     IntegrationResponses: 
     - StatusCode: 200 
    MethodResponses: 
     - StatusCode: 200 

pipelineMgrStageDeployer: 
    Type: Custom::pipelineMgrStageDeployer 
    DependsOn: webhookEndPointMethod 
    Properties: 
    ServiceToken: !GetAtt apiGwStageDeployer.Arn 
    StageName: pipelinemgr 
    RestApiId: !Ref pipelineMgrGW 
<snip> 

當我更新pipelineMgrStateMachine資源我看到,即使沒有在webhookEndPointMethod改變webhookEndPointMethod被更新。如預期。

但是,pipelineMgrStageDeployer未更新。當我使pipelineMgrStageDeployer直接依賴於pipelineMgrStateMachine時,情況更是如此。

任何想法爲什麼自定義資源不會更新資源它DependssOn更新時?任何其他可能有用的想法或見解?

謝謝, 喬

回答

2

似乎是一場誤會什麼DependsOn是。

這是怎麼回事

從CloudFormation DependsOn documentation

隨着DependsOn屬性你可以指定特定資源的創建接踵而來。將DependsOn屬性添加到資源時,僅在創建DependsOn屬性中指定的資源後才創建該資源。

webhookEndPointMethod當你pipelineMgrStateMachine更新時,可能會更新,究其原因,是因爲它在你的RequestTemplates

一個隱含的依賴"stateMachineArn": "${pipelineMgrStateMachine}"

你怎麼可以讓你自定義資源得到更新

至於如何在狀態管理器更新時讓您的部署者自定義資源更新,您可以添加適當的ty進入您的自定義資源,您實際上並未使用它,例如:PipelineMgStateMachine: !Ref pipelineMgrStateMachine,例如:

pipelineMgrStageDeployer: 
    Type: Custom::pipelineMgrStageDeployer 
    DependsOn: webhookEndPointMethod 
    Properties: 
    ServiceToken: !GetAtt apiGwStageDeployer.Arn 
    StageName: pipelinemgr 
    RestApiId: !Ref pipelineMgrGW 
    PipelineMgStateMachine: !Ref pipelineMgrStateMachine 
+0

感謝您澄清和參考運作良好! 我很困惑,因爲我在DependsOn文檔中看到這個註釋: _堆棧更新時,依賴更新資源的資源會自動更新。 AWS CloudFormation不會更改自動更新的資源,但是,如果堆棧策略與這些資源相關聯,則您的帳戶必須有權更新它們。_ 但顯然這確實意味着我的意思。 – NimbusScale