วิธีทำให้ endpoint เป็นตัวเดียวกับ instance ดั้งเดิม เมื่อกู้คืน RDS instance ด้วย snapshot

ใน Amazon RDS, หากมี identifier เดียวกันก็จะมี endpoint เดียวกันด้วย หากต้องการ restore ตัว RDS instance ด้วย snapshot โดยไม่เปลี่ยนแปลง endpoint สามารถทำได้โดยการเปลี่ยน identifier ของ instance ที่มีอยู่แล้ว และ ระบุ identifier ของ instance เดิมในขั้นตอนทำการ restore

ปัญหาที่เกิดขึ้น

ในการตั้งค่าของฝั่งแอปพลิเคชันมีเงื่อนไขว่าไม่ต้องการเปลี่ยนชื่อ endpoint ในการเชื่อมต่อ

และจำเป็นต้องทำการ restore จาก snapshot ของ RDS instance

เราสามารถตั้งค่า endpoint ในฝั่งแอปพลิเคชัน ให้เป็น endpoint ของ instance ที่ทำการ Restore ได้หรือไม่

ความรู้เบื้องต้น

ชื่อ endpoint ใน RDS จะอยู่ในรูปแบบทางด้านล่างนี้

< instance identifier >.<identifier ที่ระบุ region ของ account >.< ชื่อ region >.rds.amazonaws.com

ตัวอย่าง: endpoint ที่สร้างในชื่อ "sample" ใน Singapore Region

sample.abcd1234cdef.ap-sourtheast-1.rds.amazonaws.com

ด้วยเหตุนี้ หากอยู่ในบัญชีเดียวกัน ใน region เดียวกัน และ identifier เดียวกัน ก็จะมี endpoint เดียวกัน

วิธีแก้ปัญหา

ในระหว่างทำการ restore จาก snapshot จะไม่สามารถระบุตัวระบุ instance identifier ได้

แต่เราสามารถเปลี่ยน instance identifier ที่มีอยู่แล้วได้

โดยการทำตามขั้นตอนดังต่อไปนี้ จะสามารถระบุ endpoint ของ instance ที่มีอยู่แล้วด้วย RDS instance ที่ทำการ restore จาก snapshot ได้

1. เปลี่ยน identifier(ชื่อ) ของ RDS instance ที่ใช้งานอยู่

2.จากนั้นทำการ restore จาก snapshot โดยทำการระบุ identifier เดิมในขั้นตอนที่เราทำการ restore

คำเตือน : ในขั้นตอนการเปลี่ยน RDS instance identifier จนถึง การ restore จาก snapshot จะมีการหยุดทำงานชั่วคราว (downtime)

ทดสอบ

สร้าง RDS instance ด้วย identifier ชื่อ "sample"

จากนั้นทำการสร้าง snapshot

เมื่อลองทดสอบ restore จาก snapshot ด้วย "sample" จะไม่สามารถ restore ได้เนื่องจากมี identifier เดียวกันอยู่

ให้เปลี่ยน identifier จาก sample เป็น sample-namechanged (หลังจากการเปลี่ยงแปลงการตั้งค่านี้จะไม่สามารถเชื่อมต่อจากแอปพลิเคชันไปยัง RDS instance ได้)

ชื่อ endpoint ของ instance จะเปลี่ยนเป็น
sample-namechanged.■■■■■■■■■■■■.ap-southeast-1.rds.amazonaws.com

และทำการ restore จาก snapshot ด้วย identifier ชื่อ sample

หลังจาก restore แล้ว endpoint ของ instance จะเปลี่ยนเป็น
sample.■■■■■■■■■■■■.ap-southeast-1.rds.amazonaws.com

บทความอ้างอิง

บทความต้นฉบับ