Magento multiple instances & resource sharing on AWS
Tags: magento, scale, performance
Published: 2020-11-07 16:24:37

(I just move the old blog from Medium to dev.to)

For handling media images & static contents. We were listing the solutions we have to try. What is the ability or not as the options of a team have no knowledge about AWS services stack.

Requirement:
* Fast even data size is small
* Latency is minimal
* Ability to scale Magento instances
* Easy to handle, permission file heed

## Elastic File System (EFS)

No. Very slow if your website has less than 100 GB of data. The time to warm up cache.

EFS always mentions case study with minimum data size is 100 GB. Many blog posts mention it, they're also warning that you only get the good throughput when you have this minimum data size.

[Amazon EFS Performance - Amazon Elastic File System](https://docs.aws.amazon.com/efs/latest/ug/performance.html#throughput-modes)

The related EFS & Magento articles:

1. [AWS EFS, EBS or S3: Comparing Pricing, Performance and More](https://cloud.netapp.com/blog/ebs-efs-amazons3-best-cloud-storage-system)

2. [Magento Multi-Node Implementation on AWS: S3 vs EFS](https://www.eyemaginetech.com/blog/magento-multi-node-implementation-on-aws-s3-vs-efs)

3. [Integrate Magento 2 with EFS - Cloudkul](https://cloudkul.com/blog/how-to-setup-magento-2-with-efs/)

4. [(Poor) EFS Performance for Software Builds - DZone Performance](https://dzone.com/articles/poor-efs-performance-for-software-builds)

We didn’t believe in these articles about minimum data size, we tried and failed.

**In the first case**, we're mounting `generated/`, `var/`, `pub/` with an ambition that we can scale a new instance without warming cache on it. Just provisioning, pull the code, build-and-up our instance.

**In the second case**, we only mount `pub/media`, `pub/static` … (need update)

If you still consider to use with a correct, I hope this post will help you more:

[Improving performance when upgrading Magento 2 with Elastic File System](https://www.maxpronko.com/improving-performance-when-upgrading-magento-2-with-elastic-file-system/)

## Elastic Block System (EBS)
No. Although, it is faster than EFS but EBS just supports mounting to only one EC2 instance. It doesn’t be flexible for scaling.

Yes. If you wouldn’t like to scaling.

## S3 (via AWS SDK — S3 client)
[github.com/thaiphan/magento2-s3](https://github.com/thaiphan/magento2-s3)
Use Amazon S3 as the file storage solution for your Magento 2 application

The concept that we can use the command to syncronize local folder to a specific S3 bucket.

See here: [https://github.com/thaiphan/magento2-s3/blob/master/Console/Command/StorageExportCommand.php](https://github.com/thaiphan/magento2-s3/blob/master/Console/Command/StorageExportCommand.php) This author used AWS SDK, more detail, he used \AWS\S3\S3Client interacting with S3 server through HTTP requests.

Another repository support for S3, ability to configure in Admin panel:

[https://github.com/flagbit/Magento2-Flysystem](https://github.com/flagbit/Magento2-Flysystem)

## S3 & File Gateway (via mounting fundamental)
S3 but no need handing request by plugins. S3 but use a gateway in a middle.

The tutorial to setting up the File Gateway and uses S3 bucket for storing.

[Creating AWS File Gateway as an NFS storage for your EC2 instance](https://medium.com/tensult/creating-aws-file-gateway-as-an-nfs-storage-for-your-ec2-instance-57c141c76409)

This below video will explain more about the big picture for multiple instances mounting:

{% youtube tP5edaxBEEI %}

# Conclusion
S3 is a final one for my team to move forwards on Magento with multiple servers and load balancing. Best for price, good for performance on small project.

I can’t finish this article immediately after my team done the work. So now, just write here for sharing the options and some comments on those after tried them.