我有一个数据库堆栈,然后传递给另一个堆栈:
class DbStack extends cdk.Stack {
public dbSocket: string;
public dbReadSocket: string;
constructor(scope: cdk.Construct, id: string, props: { vpc: ec2.Vpc }) {
super(scope, id);
const { vpc } = props;
const db = new DatabaseCluster(this, "Database", {
engine: rds.DatabaseClusterEngine.AuroraPostgresql,
....
});
this.dbSocket = db.clusterEndpoint.socketAddress;
this.dbReadSocket = db.clusterReadEndpoint.socketAddress;
}
}
const dbStack = new DbStack(app, "db", { vpc });
new MyStack(app, "mystack", {
vpc,
dbSocket: dbStack.dbSocket,
dbReadSocket: dbStack.dbReadSocket,
}
在另一个堆栈中,我将这些套接字传递给 ECS 环境变量:
export class PpfStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: MyStackProps) {
super(scope, id, props);
const { vpc, dbSocket, dbReadSocket } = props;
new MyService(this, "svc", {
vpc,
...
environment: {
NODE_ENV: "production",
DATABASE_RO_SOCKET: dbReadSocket,
DATABASE_RW_SOCKET: dbSocket,
},
});
不幸的是,环境变量最终变成:
db-databasec2aad89b-1t1yxzplxjsvu.cluster-cppalohfw5gz.us-east-2.rds.amazonaws.com:{IndirectPort}
更新这看起来像一个错误:https ://github.com/awslabs/aws-cdk/issues/2711