如何等待CodePipeline在Cloudformation中部署功能

时间:2019-11-19 18:41:24

标签: python-3.x aws-lambda amazon-cloudformation aws-cloudformation-custom-resource

我有一个Cloudformation模板,我想通过它创建Aurora(MySQL)表。但是,有no built-in resource。因此,我决定构建一个自定义资源函数,以在创建DbCluster时创建表。此外,由于CI / CD管道也可以通过Cloudformation创建,因此我准备了如下模板。但是,它会引发错误:

  

未找到函数:arn:aws:lambda:eu-central-1:xxxxxxxxxxxx:MyFunctionName(服务:AWSLambda;状态代码:404;错误代码:ResourceNotFoundException;请求ID:...)

显然,无论何时创建管道,CustomResource都会运行。但是我需要等待其功能的首次部署才能在自定义资源中使用它。认为RestartExecutionOnUpdate: true中的属性AWS::CodePipeline::Pipeline会有所帮助,而在DependsOn中添加Custom::RdsBootstrap却会有所帮助。

Resources:
  # Serverless Aurora DB Cluster
  MyDbCluster:
    Type: AWS::RDS::DBCluster
    ...

  # Build Project
  MyCustomResourceFunctionBuildProject:
    Type: AWS::CodeBuild::Project
    ...

  # Pipeline for deploying Custom Resource Function Source Code
  MyCustomResourceFunctionPipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      Name: custom-resource-function-pipeline
      RestartExecutionOnUpdate: true
      Stages:
        - Name: Source
          ...
        - Name: Build
          ...
        - Name: Pipeline
          ...

  # Custom Resource Function
  RdsBootstrap:
    Type: Custom::RdsBootstrap
    DependsOn: [MyDbCluster, MyCustomResourceFunctionPipeline]
    Version: '1.0'
    Properties:
      ServiceToken: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:MyFunctionName"

因此,如何使自定义资源不仅要等待CodePipeline的创建;还有它的初始部署?

0 个答案:

没有答案