I'm using aws-cdk
to run 7 ec2
instances which will be MongoDB
nodes. I'm able to create them with their security group and stuff, but I don't understand how can I map those in private DNS.
for (inst i = 1; inst<8; inst++) {
new ec2.Instance(this, 'mongodb' + i, {
instanceType: new ec2.InstanceType('t3.medium'),
vpc: defaultVpc,
securityGroup: mongoGroup },
)}
After deployment names will be ${mongodb1/InstanceRole.Arn}, ${mongodb2/InstanceRole.Arn},...
How can I set my private DNS
records for those instances in cdk
? I want to create a configuration in which all nodes will be listed like
database1.test.com
database2.test.com
database3.test.com
...
Instead of
ec2-203-3-156-25.compute-1.amazonaws.com
ec2-201-1-191-21.compute-1.amazonaws.com
ec2-208-0-112-03.compute-1.amazonaws.com
...
because if I redeploy or restart, IP will change, and I will need again to change complete configuration, also these names are just not easy to remember. I guess I need to create private hosted zone, and then assign each IP address to CNAME
, but wonder if can be done in cdk automatically?