2017-09-29 28 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