So hit a roadblock about code deploy. This was taken considering we update the files. Later realized that we might have user generated content/content added by admin via the Drupal CMS backened. In that case those files for example images will be saved on the one particular EC2 and during a scale down the instance could go down, or may not be available in the newly booted up instance.
Luckily Amazon have another service called Elastic File System used for such cases! I now moved the sites folder of drupal to EFS.
So basic Drupal core files on the EC2 AMI image i created, plus sites folder on EFS, with auto enabling that on each loaded instance by adding the below script:
#cloud-config package_upgrade: true packages: - nfs-utils runcmd: - mkdir -p /var/www/html/efs-mount-point/ - chown ec2-user:ec2-user /var/www/html/efs-mount-point/ - echo "$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).file-system-id.efs.aws-region.amazonaws.com:/ /var/www/html/efs-mount-point nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0" >> /etc/fstab - mount -a -t nfs4I am hoping to do a video tutorial this weekend about the whole setup