简体   繁体   English

依赖和Cloudformation定制资源

[英]DependsOn and Cloudformation Custom Resources

From my understanding a resource that has DependsOn specified should be updated if the resource it depends on is updated. 据我了解,如果指定了DependsOn的资源被更新,则应该对其进行更新。 I see this for some resources, but it doesn't seem to be working for a custom resource. 我看到了一些资源,但似乎不适用于自定义资源。

I'm working with APIGateway and trying to use a custom resource to deploy the a stage when the resources related to the stage are updated. 我正在使用API​​Gateway,并尝试在与阶段相关的资源更新时使用自定义资源来部署阶段。 This is because the included AWS::ApiGateway::Stage & AWS::ApiGateway::Deployment don't seem to work very well when needed to deploy an update. 这是因为所包含的AWS::ApiGateway::StageAWS::ApiGateway::Deployment在需要部署更新时似乎无法很好地工作。

I have the following template (snipped for easy reference): 我有以下模板(已删除以方便参考):

<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>

When I update the pipelineMgrStateMachine resource I see that the webhookEndPointMethod is updated even though nothing changes in the webhookEndPointMethod . 当我更新pipelineMgrStateMachine资源我看到webhookEndPointMethod即使没有什么变化更新webhookEndPointMethod As expected. 如预期的那样。

But, pipelineMgrStageDeployer is not updated. 但是, pipelineMgrStageDeployer未更新。 This is even the case when I make pipelineMgrStageDeployer dependent directtly on pipelineMgrStateMachine . 甚至在我使pipelineMgrStageDeployer依赖于pipelineMgrStateMachine的情况下也是如此。

Any ideas on why the custom resource is not be updated when a resource it DependssOn is updated? 关于自定义资源DependssOn的资源更新时为何不更新的任何想法? Any other thoughts or insights that might be useful? 还有其他有用的想法或见解吗?

Thanks, Joe 谢谢乔

There seems to be a misunderstanding on what DependsOn is for. DependsOn的用途似乎存在误解。

What's going on 这是怎么回事

From the CloudFormation DependsOn documentation 来自CloudFormation DependsOn文档

With the DependsOn attribute you can specify that the creation of a specific resource follows another. 使用DependsOn属性,您可以指定特定资源的创建紧随另一个资源。 When you add a DependsOn attribute to a resource, that resource is created only after the creation of the resource specified in the DependsOn attribute. 当您向资源添加DependsOn属性时,仅在创建DependsOn属性中指定的资源之后才创建该资源。

The reason that your webhookEndPointMethod is likely updated when your pipelineMgrStateMachine is updated, is because it has an implicit dependency in your RequestTemplates 更新pipelineMgrStateMachine时,可能会更新webhookEndPointMethod的原因是,因为它在RequestTemplates具有隐式依赖性

"stateMachineArn": "${pipelineMgrStateMachine}"

How can you make your custom resource get updated 如何使您的自定义资源得到更新

As for how to have your deployer custom resource update when the state manager updates, you could add a property into your Custom resource that you don't actually use in it, like PipelineMgStateMachine: !Ref pipelineMgrStateMachine , for example: 至于在状态管理器更新时如何使部署者的自定义资源更新,您可以在您的自定义资源中添加一个实际上并不使用的属性,例如PipelineMgStateMachine: !Ref pipelineMgrStateMachine ,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM