我想知道如何导入另一个堆栈中定义的安全组,然后在当前堆栈中使用。
到目前为止我已经尝试过了..
class relayStack extends cdk.Stack {
public sg_relay: ec2.SecurityGroupRefProps
constructor(parent: cdk.App, name: string, props: VPCProps) {
super(parent, name, props);
//#IMPORT VPC PROPS
const vpc = ec2.VpcNetwork.import(this, 'VPC-Hottest100', props.infra.vpc);
//#AUTOSCALING GROUP
const asg_relayServer = new ec2.AutoScalingGroup(this, 'ASG_Relay', {
vpc,
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.T2, ec2.InstanceSize.Small),
minSize: 1,
maxSize: 3,
desiredCapacity: 1,
machineImage: new ec2.GenericLinuxImage({
"ap-southeast-2": "ami-dc361ebf",
}),
keyName: 'icecast-poc',
allowAllOutbound: false,
vpcPlacement: {
usePublicSubnets: false
}
});
//#SECURITY Group
const sg_relay = new ec2.SecurityGroup(this, 'SG_RELAY', {
vpc,
description: "Relay stack security group",
groupName: 'relay-sg'
})
this.sg_relay = sg_relay
}
}
然后从另一个堆栈我想访问导出的安全组 sg_relay
我试过以下
//#SECURITY GROUP
const sg_nginx = new ec2.SecurityGroup(this, "SG_NGINX", {
vpc,
description: "NGINX stack security group",
groupName: 'nginx-sg'
})
const sg_relayImp = new ec2.SecurityGroupRef(this, "SG_RELAY_IMP", {
securityGroupId: new ec2.SecurityGroupId('SG_RELAY')
})
然后使用如下
sg_nginx.addIngressRule(sg_relayImp, wowzaPort, 'asg_RelyToNgn_8000')
显然它不适合我。
我找不到堆栈之间安全组的任何导入功能,就像 vpc 有一个一样。
有人可以帮我解决这种情况吗?