[[TOC]]
Demo - Implementing EFS
- Log into AWS into the N. Virginia region
- Click the deployment link
- Create the stack and wait for it to complete
- This has created two EFS instances that we will use to mount an EFS share on both instances.
- Navigate to the EFS console.
- Create a file system
- Give it a name, select our VPC and then click Customize to get us to a more advanced settings page.
- Review these settings as per the notes and then give it a couple tags and click Next.
- On the network access page, you should see 3 mount targets automatically configured. Let's remove all of the security groups to start.
- For us-east-1a, select App A, for us-east-1b select App B, for us-east-1c, select App C
- Select the pre-created security group
- Review the policy options, we won't add any of these here for the demo. Click Next and Create.
- Wait until the 3 mount targets are in a Ready state.
Mount the EFS shares to your EC2 instances
- Navigate back to the EC2 console and duplicate the tab so you can connect into Instance A and Instance B simultaneously
- In instance A, run a
df -k
to look at the mounted drives. There won't be a drive listed here. You can test Instance B if you want, but believe me, it's not there either. - Make a new dir called /efs/wp-content.
sudo mkdir -p /efs/wp-content
a. You might see where we're going with this. - Run
sudo yum install -y amazon-efs-utils
- Add the mount to the file system by changing directory to the etc folder and editing the fstab.
cd /etc
andsudo nano fstab
- In a different tab, navigate to the EFS console and get the id of the EFS share and copy it. fs-1234567
- Paste in the following line:
fs-1234567:/ /efs/wp-content efs _netdev,tls,iam 0 0
- Save the file and then run a
df -k
to see the mountpoints that have been loaded - Run
sudo mount /efs/wp-content
to mount the EFS endpoint to the foldere. - Run
df -k
to view the mount. cd /efs/wp-content
into the folder- Create a file by running
sudo touch mytestfile.txt
- Repeat all of these steps on Instance B, only to find that once you mount the drive, the
mytestfile.txt
will already exist by runningls -la
when the folder has been mounted - You can play around with creating files and viewing files across these two instances if you'd like.
Clean up
Delete the EFS share Delete the stack.
Demo - Using EFS with Wordpress
You will need the two snapshots from earlier demos for this demo.
- Log into AWS in the N. Virginia region
- Apply this CF template and paste in the name of the snapshot that has the aurora-cluster-randomchars for the DB instance and wait for it to complete.
- Apply this CF template.
- Wait for this to get into the Create Complete state
- Navigate to the EC2 instance once created and then open the public IPv4 Address in the browser
- Notice that the site loads, but the images are still broken.
- Login to the admin console of the Wordpress site
- Update the block to add in the images and upload the images.
- Yeah, we probably could have done this all those times we were missing the file, but we really wanted to get this into it's final state before we added them.
- Connect to the EC2 instance, navigate down into the wp-content/../../ and you should see the images that you've uploaded.
- Run a
df -k
and notice that the wp-content folder is mounted from the EFS share. - Delete the 2nd stack with the EC2 instance
- Apply this stack and wait for it to complete.
- Once this is completed, open the EC2 console and look at the new instance and copy the new public IPv4 IP, open it in the browser, you will see that we can load a new EC2 instance with the images working.
- Reapply the first stack.
- Navigate to EC2, grab that IPv4 IP addresses and then access that in the browser.
- All we really need to do is add a load balancer (spoilers!) and we'll be set, but we won't do that. You have 2 EC2 instances that connect to one EFS filesystem.
Clean up
Delete 2, 1, and then the first stack.