且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 AWS ECS 容器上挂载 S3 存储桶作为文件系统

更新时间:2022-11-07 14:00:54

您使用 rexray/s3fs 驱动程序的方法是正确的.

Your approach of using the rexray/s3fs driver is correct.

这些是我在 Amazon Linux 1 上运行的步骤.

These are the steps I followed to get things working on Amazon Linux 1.

首先您需要安装 s3fs.

First you will need to install s3fs.

yum install -y gcc libstdc+-devel gcc-c+ fuse fuse-devel curl-devel libxml2-devel mailcap automake openssl-devel git gcc-c++
git clone https://github.com/s3fs-fuse/s3fs-fuse
cd s3fs-fuse/
./autogen.sh
./configure --prefix=/usr --with-openssl
make
make install

现在安装驱动程序.这里有一些您可能想要修改的选项,例如使用 IAM 角色而不是访问密钥和 AWS 区域.

Now install the driver. There are some options here you might want to modify such as using an IAM role instead of Access Key and AWS region.

docker plugin install rexray/s3fs:latest S3FS_REGION=ap-southeast-2 S3FS_OPTIONS="allow_other,iam_role=auto,umask=000" LIBSTORAGE_INTEGRATION_VOLUME_OPERATIONS_MOUNT_ROOTPATH=/ --grant-all-permissions

现在是重启ECS代理非常重要的一步.我也会更新以进行良好的衡量.

Now the very important step of restarting the ECS agent. I also update for good measure.

yum update -y ecs-init
service docker restart && start ecs

您现在应该可以创建您的任务定义了.重要的部分是您的音量配置,如下所示.

You should now be ready to create your task definition. The important part is your volume configuration which is shown below.

"volumes": [
  {
    "name": "name-of-your-s3-bucket",
    "host": null,
    "dockerVolumeConfiguration": {
      "autoprovision": false,
      "labels": null,
      "scope": "shared",
      "driver": "rexray/s3fs",
      "driverOpts": null
    }
  }
]

现在你只需要在容器定义中指定挂载点:

Now you just need to specify the mount point in the container definition:

"mountPoints": [
  {
    "readOnly": null,
    "containerPath": "/where/ever/you/want",
    "sourceVolume": "name-of-your-s3-bucket"
  }
]

现在,只要您拥有访问 s3 存储桶的适当 IAM 权限,您的容器就应该启动,并且您可以继续使用 s3 作为卷.

Now as long as you have appropriate IAM permissions for accessing the s3 bucket your container should start and you can get on with using s3 as a volume.

如果您在运行ATTRIBUTE"任务时遇到错误,请仔细检查插件是否已成功安装在 ec2 实例上并且 ecs 代理已重新启动.还要仔细检查您的驱动程序名称是rexray/s3fs".

If you get an error running the task that says "ATTRIBUTE" double check that the plugin has been successfully installed on the ec2 instance and the ecs agent has been restarted. Also double check your driver name is "rexray/s3fs".