1

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

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

显然,只要创建 Pipeline,CustomResource 就会运行。但是我需要等待它的第一次功能部署才能在自定义资源中使用它。认为属性RestartExecutionOnUpdate: trueAWS::CodePipeline::Pipeline添加DependsOnCustom::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 创建;还有它的初始部署?

4

0 回答 0