Search code examples
amazon-web-servicesamazon-ecsamazon-efs

AWS ECS + EFS + Spot instances


I am thinking about using an ECS cluster based on spot instances. In order to keep containers' data save, I want to use EFS, so all instances will be connected to it and all containers will store their data on EFS. In this case, even if an instance is terminated, the data will be untouched on EFS, When a new instance is relaunched all containers will get their data mounted.

It is just an idea, will it work? Are there any cons?


Solution

  • Yes it will work.

    Steps:

    1. Create an empty ECS cluster
    2. Create an Elastic file system (EFS)
    3. Create a launch template
    4. Set the 'UserData' script to attach each instance to the ECS Cluster and the EFS
    5. Take care of security group rules to allow access to EFS from Cluster EC2 instance

    Example: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/example_user_data_scripts.html