Reputation: 12455
I try to create RDS on already existing subnet. There are three subnet.
subnet-0b5985476dee1f20c public on 1d
subnet-085c85398f27adbfd isolated on 1c
subnet-0fdd37150bfff91f0 isolated on 1d
So, I want to use second and third subnet as subnet group/
My code is here below.
const VPCID='vpc-0867d6797e6XXXXXb';
const vpc = ec2.Vpc.fromLookup(this, "VPC", {
vpcId:VPCID
});
const mySecurityGroup = new ec2.SecurityGroup(this, 'sg-allfordevelop', {
vpc,
description: 'Allow sql access to database',
allowAllOutbound: true,
securityGroupName: `cdk-st-${targetEnv}-sg`
});
mySecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(3306),'allow mysql port');
const dbInstance = new rds.DatabaseInstance(this, 'Instance', {
engine: rds.DatabaseInstanceEngine.mysql({
version: rds.MysqlEngineVersion.VER_8_0_19,
}),
vpc,
securityGroups:[mySecurityGroup],
instanceIdentifier:`cdk-${targetEnv}-rds`,
vpcSubnets: {
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
removalPolicy: cdk.RemovalPolicy.DESTROY,
databaseName:`st${targetEnv}`,
credentials: rds.Credentials.fromPassword('django',new cdk.SecretValue("mypass"))
});
However it makes template here below.
There are not existed ids here.
Does it mean trying to make new subnet ?
How can I indicate to use already existed subnets?
"InstanceSubnetGroupF2CBA54F": {
"Type": "AWS::RDS::DBSubnetGroup",
"Properties": {
"DBSubnetGroupDescription": "Subnet group for Instance database",
"SubnetIds": [
"subnet-0b5985476dee1f20c",
"subnet-0d7c1590c61b62782"
]
},
"Metadata": {
"aws:cdk:path": "st-dev-base-stack/Instance/SubnetGroup/Default"
}
},
Upvotes: 1
Views: 1287
Reputation: 12455
Solved.
There are old information cached in cdk.context.json.
I delete this file, it works.
Upvotes: 1