Mountpoint for Amazon S3の検証

サービス概要

Mountpoint for Amazon S3 は、ファイル対応の Linux アプリケーションが S3バケットに簡単に直接接続できるようにするオープンソースのファイルクライアントで、S3 バケットをローカルファイルシステムとしてマウントするための Rust 製ファイルクライアントです。
マウントポイントは、EC2インスタンス、ECSまたはEKSコンテナ内で使用できます。また、既存のオンプレミスシステムにインストールすることもでき、直接、または AWS PrivateLink for S3 を介した Direct Connect 接続経由で S3 にアクセスすることもできます。

 目的・やりたいこと

LinuxをいじりながらディレクトリのようにS3にアクセスしたいと思ったことはありませんか?
今回扱うこのMountpoint for S3は、実際にLinux上でS3をマウントして使えるようにするというものです。
ということで、これが提案できるレベルのサービスか確認するうえで検証してみます!

 対象者

Linuxを操作しながらディレクトリの一部としてS3への操作が必要な場合(初級〜中級者レベル)

 対象となる技術

 参考URL

 事前作業

S3をマウントするには専用のマウントコマンドmount-s3が必要で、そのツールはwgetで取ってこれます。
wgetしたらyum installするだけ。

# wget https://s3.amazonaws.com/mountpoint-s3-release/latest/x86_64/mount-s3.rpm
--2023-08-22 01:12:35--  https://s3.amazonaws.com/mountpoint-s3-release/latest/x86_64/mount-s3.rpm
Resolving s3.amazonaws.com (s3.amazonaws.com)... 52.216.41.24, 52.216.53.88, 52.216.109.61, ...
Connecting to s3.amazonaws.com (s3.amazonaws.com)|52.216.41.24|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10432224 (9.9M) [binary/octet-stream]
Saving to: ‘mount-s3.rpm’

100%[====================================================>] 10,432,224  4.56MB/s   in 2.2s

2023-08-22 01:12:38 (4.56 MB/s) - ‘mount-s3.rpm’ saved [10432224/10432224]

# ls
app.py   install.1   mount-s3.rpm

# yum install ./mount-s3.rpm
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Examining ./mount-s3.rpm: mount-s3-1.0.0-1.x86_64
Marking ./mount-s3.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mount-s3.x86_64 0:1.0.0-1 will be installed
--> Processing Dependency: fuse for package: mount-s3-1.0.0-1.x86_64
amzn2-core                                                             | 3.7 kB  00:00:00
amzn2extra-docker                                                      | 3.0 kB  00:00:00
amzn2extra-kernel-5.10                                                 | 3.0 kB  00:00:00
amzn2extra-php7.4                                                      | 3.0 kB  00:00:00
snapd-amzn2                                                            | 3.0 kB  00:00:00
(1/3): amzn2-core/2/x86_64/group_gz                                    | 2.5 kB  00:00:00
(2/3): amzn2-core/2/x86_64/updateinfo                                  | 677 kB  00:00:00
(3/3): amzn2-core/2/x86_64/primary_db                                  |  76 MB  00:00:01
--> Running transaction check
---> Package fuse.x86_64 0:2.9.2-11.amzn2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================
 Package             Arch              Version                    Repository             Size
==============================================================================================
Installing:
 mount-s3            x86_64            1.0.0-1                    /mount-s3              53 M
Installing for dependencies:
 fuse                x86_64            2.9.2-11.amzn2             amzn2-core             86 k

Transaction Summary
==============================================================================================
Install  1 Package (+1 Dependent package)

Total size: 53 M
Total download size: 86 k
Installed size: 53 M
Is this ok [y/d/N]: y
Downloading packages:
fuse-2.9.2-11.amzn2.x86_64.rpm                                         |  86 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : fuse-2.9.2-11.amzn2.x86_64                                                 1/2
  Installing : mount-s3-1.0.0-1.x86_64                                                    2/2
  Verifying  : mount-s3-1.0.0-1.x86_64                                                    1/2
  Verifying  : fuse-2.9.2-11.amzn2.x86_64                                                 2/2

Installed:
  mount-s3.x86_64 0:1.0.0-1

Dependency Installed:
  fuse.x86_64 0:2.9.2-11.amzn2

Complete!

# mount
mount       mount.fuse  mount.nfs   mount.nfs4  mountpoint  mount-s3    mountstats

動作確認バージョン

# mount-s3 -V
mount-s3 1.0.0
Mountpoint for Amazon S3

Usage: mount-s3 [OPTIONS] <BUCKET_NAME> <DIRECTORY>

Arguments:
  <BUCKET_NAME>  Name of bucket to mount
  <DIRECTORY>    Directory to mount the bucket at

Options:
  -f, --foreground  Run as foreground process
  -h, --help        Print help
  -V, --version     Print version

Bucket options:
      --prefix <PREFIX>
          Prefix inside the bucket to mount, ending in '/' [default: mount the entire bucket]
      --region <REGION>
          AWS region of the bucket [default: auto-detect region]
      --endpoint-url <ENDPOINT_URL>
          S3 endpoint URL [default: auto-detect endpoint]
      --force-path-style
          Force path-style addressing
      --transfer-acceleration
          Use S3 Transfer Acceleration when accessing S3. This must be enabled on the bucket.
      --dual-stack
          Use dual-stack endpoints when accessing S3
      --requester-pays
          Set the 'x-amz-request-payer' to 'requester' on S3 requests
      --storage-class <STORAGE_CLASS>
          Set the storage class for new objects
      --expected-bucket-owner <AWS_ACCOUNT_ID>
          Account ID of the expected bucket owner. If the bucket is owned by a different account, S3 requests fail with an access denied error.

AWS credentials options:
      --no-sign-request    Do not sign requests. Credentials will not be loaded if this argume
nt is provided.
      --profile <PROFILE>  Use a specific profile from your credential file.

Mount options:
      --read-only              Mount file system in read-only mode
      --allow-delete           Allow delete operations on file system
      --auto-unmount           Automatically unmount on exit
      --allow-root             Allow root user to access file system
      --allow-other            Allow other non-root users to access file system
      --uid <UID>              Owner UID [default: current user's UID]
      --read-only              Mount file system in read-only mode
      --allow-delete           Allow delete operations on file system
      --auto-unmount           Automatically unmount on exit
      --allow-root             Allow root user to access file system
      --allow-other            Allow other non-root users to access file system
      --uid <UID>              Owner UID [default: current user's UID]
      --gid <GID>              Owner GID [default: current user's GID]
      --dir-mode <DIR_MODE>    Directory permissions [default: 0755]
      --file-mode <FILE_MODE>  File permissions [default: 0644]

Client options:
      --maximum-throughput-gbps <N>  Maximum throughput in Gbps [default: auto-detected on EC2
 instances, 10 Gbps elsewhere]
      --max-threads <N>              Maximum number of FUSE daemon threads [default: 16]
      --part-size <PART_SIZE>        Part size for multi-part GET and PUT [default: 8388608]

Logging options:
  -l, --log-directory <DIRECTORY>  Write log files to a directory [default: logs written to sy
slog]
      --log-metrics                Enable logging of summarized performance metrics
  -d, --debug                      Enable debug logging for Mountpoint
      --debug-crt                  Enable debug logging for AWS Common Runtime
      --no-log                     Disable all logging

 検証手順

ここではS3にある以下のnozaki-codedeploybucketをマウントしようと思います。

1.nozaki-codedeploybucketというバケット名と同じ名前のディレクトリを作成

# mkdir nozaki-codedeploybucket

2.mount-s3コマンドを使って1.のディレクトリにS3のnozaki-codedeploybucketをマウント

# mount-s3 nozaki-codedeploybucket nozaki-codedeploybucket
bucket nozaki-codedeploybucket is mounted at nozaki-codedeploybucket

3.実際にマウントしたディレクトリに移動し、中身もあることを確認

# cd nozaki-codedeploybucket
# ls
aaa  client_certificate.pfx  index.html

4.念のためファイルの内容を表示

# more index.html
<html>
<head>
 <title>Test</title>
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<h2>Cognito二要素認証突破</h2>
<h3>こちらはCloudFront経由のS3ページです。</h3>
〜〜〜
</body>
</html>

5.実際にディレクトリ階層をさらに掘ってみる

# cd aaa
# ls
AWSCLIV2 (1).msi  FederationMetadata (2).xml  Pictures  WordPressApp.zip
AWSLogs           HelloWorld_App.zip          s3upload

こちらと同じものが表示できている。

6.ファイルを作成してみる

[root@ip-10-0-17-180 aaa]# touch aaaa.txt
[root@ip-10-0-17-180 aaa]# ls
aaaa.txt          AWSLogs                     HelloWorld_App.zip  s3upload
AWSCLIV2 (1).msi  FederationMetadata (2).xml  Pictures            WordPres

こちらと同じものが表示できている。

7.しかし確かに新規ファイルの作成はできるが、そのファイルに後から追記したり、既存のファイルに何か上書きができないようになっているようだ。

# echo bbb > s3upload
bash: s3upload: Operation not permitted
# vi aaaa.txt
# more aaaa.txt
#

 所要時間

30分

 ユースケース

EC2インスタンスからS3バケットへの大規模なデータの保存や参照
(現時点ではサポート OS は Linux のみで 読み込み操作専用)

 ロードマップ

https://github.com/orgs/awslabs/projects/84
(実施済み)

新しいオブジェクト/ファイルのストレージ クラスの構成をサポート
新しいファイルの作成 (順次書き込み)
unlink/rm のサポート
mkdirのサポート
ネットワーク インターフェイス カード (NIC) スループットの自動構成
UbuntuサーバーまたはDebianベースのLinuxで実行

(評価中)

CloudWatchの統合
マウントポイントを通じて読み取られた S3 オブジェクト キーをログに記録します
Kubernetes およびその他のコンテナ オーケストレーター用の CSI (コンテナ ストレージ インターフェイス) ドライバー
Windowsのサポート
繰り返しのアクセスにかかるコストを削減