我有一个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的创建;还有它的初始部署?