AWS EFS becomes empty when auto scaling

I’m new to AWS and configured a scalable WordPress website by following this guide:

I added this script to my .ebextension folder,

    nfs-utils: []
    jq: []
  "/tmp/" :
    mode: "000755"
    content: |
      #!/usr/bin/env bash
      mkdir -p /mnt/efs
      EFS_NAME=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_NAME')
      mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $EFS_NAME:/ /mnt/efs || true
      mkdir -p /mnt/efs/uploads
      chown webapp:webapp /mnt/efs/uploads
    command: "/tmp/"
    command: rm -rf /var/app/ondeck/wp-content/uploads
    command: ln -snf /mnt/efs/uploads /var/app/ondeck/wp-content/uploads

Everything worked well except that every time I started a new EC2 instance, /mnt/efs/uploads would become empty. I can’t figure out what’s wrong with my configuration.

I followed this process:

  1. Used db deploy to deploy my fully configured WordPress folder onto the Elastic Beanstalk environment.

  2. Uploaded some images from the upload folder of my previous WordPress website (size: 700mb) onto /mnt/efs/uploads. (So now the new WordPress website will be the same with my previous one)

  3. Terminate this EC2 so that with auto-scaling, a new EC2 will be created. Everything in this EC2 will be the same with the terminated one, however, all the things in /mnt/efs/uploads disappeared.

Is there anything wrong with this configuration?

Thanks for helping me!

Read more here: AWS EFS becomes empty when auto scaling

Leave a Reply

Your email address will not be published. Required fields are marked *