我有一个类似的用例,我只是使用 Cloudformation 输出来共享表 ARN。
例如
在 StackA 中,我有 Dynamodb 表
import * as cdk from '@aws-cdk/core';
import { Table, AttributeType, BillingMode } from '@aws-cdk/aws-dynamodb';
export class StackA extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const table = new Table(this, 'my-table', {
partitionKey: { name: 'id', type: AttributeType.STRING },
billingMode: BillingMode.PAY_PER_REQUEST,
tableName: 'mytable'
});
new cdk.CfnOutput(this, 'my-table-output', {
value: table.tableArn,
description: 'Data Storage',
exportName: this.stackName + '-tablearn'
});
}
}
在堆栈B中
import * as cdk from '@aws-cdk/core';
import { Table } from '@aws-cdk/aws-dynamodb';
export class StackB extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const stackATable = Table.fromTableArn(this, "stackA-table", cdk.Fn.importValue("StackA-tablearn"));
}
}