我可以在 AWS CDK 中复制 DependsOn 行为吗?

tkw*_*rgs 8 amazon-web-services aws-cloudformation aws-cdk

我使用 AWS CDK (python) 创建一个具有隔离子网和多个接口终端节点的 VPC。

我还推出了带有关联 Codecommit 存储库的Sagemaker 笔记本

我为 Codecommit 和 Git Codecommit 创建接口端点,但当我的 Sagemaker 笔记本开始部署时,接口端点仍在创建,因此 Cloudformation 堆栈失败并出现错误

fatal: unable to access 'https://git-codecommit.us-east-1.amazonaws.com/v1/repos/SomeRepo/': Failed to connect to git-codecommit.us-east-1.amazonaws.com port 443: Connection timed out
Run Code Online (Sandbox Code Playgroud)

如果我注释掉我的 Sagemaker 笔记本,运行cdk deploy myStack,创建端点,然后我可以取消注释我的笔记本,它会毫无问题地启动,因为 Codecommit 接口端点已经存在。

CDK 中有没有办法将 a 添加DependsOn到我使用 CDK 创建的资源中?

相关代码如下

fatal: unable to access 'https://git-codecommit.us-east-1.amazonaws.com/v1/repos/SomeRepo/': Failed to connect to git-codecommit.us-east-1.amazonaws.com port 443: Connection timed out
Run Code Online (Sandbox Code Playgroud)

Mau*_*ein 7

不确定Python的语法如何,因为我使用CDK的Typescript,但CDK构造最终在CloudFormation资源中解析,所以它实际上是可能的。

这是一个使用 Typescript 的示例:

const api = new apigateway.LambdaRestApi(this, "apigw", {...})
const function = new lambda.Function(this, "lambda", {...})

// "function" will be deployed before "api"
api.node.addDependency(function)
Run Code Online (Sandbox Code Playgroud)

因此,在了解如何从 CDK 构造访问内部节点之后,就非常简单了