AWS EC2 autoscaling

0

I want to sync data between existing main ec2 instance and newer aws autoscaling instance automatic using userdata in launch template. I have created launch template using ami of existing ec2 instance. Please suggest what can i write in user data that sync latest data from existing ec2 instance. I want to deploy latest deployment on upcoming newer instances through autoscaling.

Mangu
已提問 10 個月前檢視次數 262 次
2 個答案
3
已接受的答案

More information about your specific use case would be helpful, but something I have used in this scenario is an EFS filesystem which is mounted on all EC2 instances which are provisioned from the launch template.

In the user data just echo a row into /etc/fstab and then mount -a, and the new instance has a view of the same data as the existing instance(s).

But like I said at the start, your use case means this might not be practical.

profile picture
專家
Steve_M
已回答 10 個月前
profile picture
專家
已審閱 10 個月前
profile picture
專家
已審閱 10 個月前
  • please suggest userdata script for this

  • Here's an example, you need to put the actual IP (or DNS name) for the EFS mountpoint in place of the terraform resource that I used in my code, as well as having an EFS filesystem and mountpoint(s) already created:

    mkdir /uploads
    echo "${aws_efs_mount_target.EFS_Mountpoint.ip_address}:/ /uploads nfs4 rw,vers=4.1 0 0" >> /etc/fstab
    mount -a
    while [[ `mount | grep uploads | cut -d ' ' -f5` != "nfs4" ]]; do sleep 5; mount -a; done
    

    About 1 time in 20 I found that the EFS filesystem wouldn't mount when the instance was provisioned, the while loop is to guard against this and re-try if it happens.

1

Hi, an alternative to EFS is to use Amazon EBS Multi-Attach volumes that you can attach simultaneously to several EC2 instances. It may be a bit simpler to manage than EFS

See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volumes-multi.html

Best,

Didier

profile pictureAWS
專家
已回答 10 個月前
profile picture
專家
已審閱 10 個月前
  • I want to use this in autoscaling group not manual

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南