AWS CDK 资源创建序列?
AWS CDK resource create sequence?
我正在使用 AWS CDK。当我部署时,根据 AWS 控制台中的 CloudFormation Events,createWorkflow
中的 resources(CfnTrigger)
在 createDDBCrawler
和 createS3Crawler
之前初始化。这是导致 create_failed(Entity not found)
因为 createWorkflow
取决于这两个中的资源。
所以我想知道:
AWS CDK 资源生成序列(因为我在函数中没有看到 async
或 promise
,所以 TypeScript 正在按顺序处理代码。然后是 CDK/CloudFormation行为?)
如何避免这种情况或安排资源创建顺序,但创建两个堆栈除外。
export class QuicksightGlue extends Construct {
constructor(scope: Construct, name: string, props: QuicksightGlueProps) {
super(scope, name);
this.createGlueDb(props.glueDb);
for (let zone of zones) {
const ddbCrawler = this.createDDBCrawler(...);
const etlJob = this.createEtlJob(...);
// crawler for processed data
this.createS3Crawler(...);
// create workflow that use crawler
this.createWorkflow(...);
}
}
private createS3Crawler(...) {
return new glue.CfnCrawler(this, 's3Crawler_' + zone, {
name: 's3Crawler_' + zone,
databaseName: glueDb,
role: roleArn,
targets: {
s3Targets: [{ path: s3 }]
}
});
}
private createWorkflow(...) {
const extracDdbWorkflow = new glue.CfnWorkflow(this, `ExtractDdb_` + zone, {
name: `udhcpExtractDdb_` + zone.toLowerCase(),
description: "Workflow to extract and process data from DDB"
});
const scheduledTriggerDdbCrawler = new glue.CfnTrigger(this, 'DdbTrigger_' + zone, {
workflowName: extracDdbWorkflow.name,
type: "SCHEDULED",
schedule: scheduleCronExpression, //"cron(0 * * * ? *)",
description: "Trigger to start the workflow every hour to update ddb data",
actions: [{
crawlerName: ddbCrawler,
}],
});
...
您可以通过调用构造的 node
属性 上的 addDependency
使构造依赖于另一个构造,如下所示:
// Normally these two constructs would be created in parallel
const construct1 = ...;
const construct2 = ...;
// But with this line, construct2 will not be created until construct 1 is
construct2.node.addDependency(construct1);
Here是一个实际例子。
您可能希望将 createS3Crawler
的 return 值保存到一个变量中,然后将该变量作为参数传递给 createWorkflow
。然后,createWorkflow
将在它内部创建的每个依赖于 S3 爬虫的构造上调用 .node.addDependency(createS3Crawler)
。
我正在使用 AWS CDK。当我部署时,根据 AWS 控制台中的 CloudFormation Events,createWorkflow
中的 resources(CfnTrigger)
在 createDDBCrawler
和 createS3Crawler
之前初始化。这是导致 create_failed(Entity not found)
因为 createWorkflow
取决于这两个中的资源。
所以我想知道:
AWS CDK 资源生成序列(因为我在函数中没有看到
async
或promise
,所以 TypeScript 正在按顺序处理代码。然后是 CDK/CloudFormation行为?)如何避免这种情况或安排资源创建顺序,但创建两个堆栈除外。
export class QuicksightGlue extends Construct {
constructor(scope: Construct, name: string, props: QuicksightGlueProps) {
super(scope, name);
this.createGlueDb(props.glueDb);
for (let zone of zones) {
const ddbCrawler = this.createDDBCrawler(...);
const etlJob = this.createEtlJob(...);
// crawler for processed data
this.createS3Crawler(...);
// create workflow that use crawler
this.createWorkflow(...);
}
}
private createS3Crawler(...) {
return new glue.CfnCrawler(this, 's3Crawler_' + zone, {
name: 's3Crawler_' + zone,
databaseName: glueDb,
role: roleArn,
targets: {
s3Targets: [{ path: s3 }]
}
});
}
private createWorkflow(...) {
const extracDdbWorkflow = new glue.CfnWorkflow(this, `ExtractDdb_` + zone, {
name: `udhcpExtractDdb_` + zone.toLowerCase(),
description: "Workflow to extract and process data from DDB"
});
const scheduledTriggerDdbCrawler = new glue.CfnTrigger(this, 'DdbTrigger_' + zone, {
workflowName: extracDdbWorkflow.name,
type: "SCHEDULED",
schedule: scheduleCronExpression, //"cron(0 * * * ? *)",
description: "Trigger to start the workflow every hour to update ddb data",
actions: [{
crawlerName: ddbCrawler,
}],
});
...
您可以通过调用构造的 node
属性 上的 addDependency
使构造依赖于另一个构造,如下所示:
// Normally these two constructs would be created in parallel
const construct1 = ...;
const construct2 = ...;
// But with this line, construct2 will not be created until construct 1 is
construct2.node.addDependency(construct1);
Here是一个实际例子。
您可能希望将 createS3Crawler
的 return 值保存到一个变量中,然后将该变量作为参数传递给 createWorkflow
。然后,createWorkflow
将在它内部创建的每个依赖于 S3 爬虫的构造上调用 .node.addDependency(createS3Crawler)
。