AWS-CDK:需要将管道中生成的资源传递给创建的堆栈

AWS-CDK: Need to pass resource generated in pipeline to a created stack

我目前正在研究跨账户部署管道。

我正在使用 4 个不同的堆栈:

最后两个堆栈都有 props,其中包括生成的 Layer 和构建的 JS 文件(针对不同的 Lambda)。

我的 cdk.ts 看起来像这样:

import * as cdk from "@aws-cdk/core"
import { BackendPipelineStack } from "../lib/backend-pipeline"
import { BusinessAssetAPIStack } from "../lib/business-asset-api-stack"
import { projectConfig } from "../config/config"
import { AssetDeploymentStack } from "../lib/asset-deployment-stack"
import { CommonInfrastructureStack } from "../lib/common-infrastructure-stack"
const app = new cdk.App()
const commonInfraStack = new CommonInfrastructureStack(app, "CommonInfrastructureStack", {
  stackName: `${projectConfig.resourcePrefix}-common-infrastructure-stack`,
})
const apiStack = new BusinessAssetAPIStack(app, "BusinessAssetAPIStack", {
  stackName: `${projectConfig.resourcePrefix}-business-asset-api-stack`,
  ...,
  installationUserEmailIndexName: commonInfraStack.installationTechnicalAssetUserEmailIndexName,
})
const deploymentStack = new AssetDeploymentStack(app, "AssetDeploymentStack", {
  stackName: `${projectConfig.resourcePrefix}-asset-deployment-stack`,
  ...,
  installationAccountRegionIndexName: commonInfraStack.installationAccountRegionIndexName,
})

new BackendPipelineStack(app, "BackendPipelineStack", {
  nonProdAccountId: "nonProdAccountId",
  apiStack,
  commonInfraStack,
  deploymentStack,
})

我的 BackendPipelineStack 堆栈是生成 codepipeline.Artifacts 的堆栈,它存储构建的 JS 文件和 Layers。

//backend-pipeline.ts
export class BackendPipelineStack extends Stack {
   ...
   const lambdaBuildOutput = new Artifact("DistArtifact")
   const lambdaLayer = new Artifact("LayerArtifact")
   ...

我希望能够将两者 Artifacts 传递给通过 PipelineStack 构造函数传递的其他堆栈。

有办法吗?

我为那些和我一样陷入困境的人找到了答案。

查看管道操作,有一个名为 CloudFormationCreateOrUpdateStack 的操作允许通过 CfnParametersCode (here's a python example).

覆盖 Lambda 堆栈中提供的参数