Amazon EFS ボリュームを Elastic Beanstalk 環境のアプリケーションディレクトリにマウントする方法を教えてください。

所要時間2分
0

Amazon Elastic File System (Amazon EFS) ボリュームを AWS Elastic Beanstalk 環境のアプリケーションディレクトリにマウントしようと思います。

簡単な説明

以下の解決策では、Amazon Linux 1 ベースのプラットフォームに Amazon EFS ボリュームをマウントする一般的な手順を示します。解決には PHP ソリューションスタックを使用します。
別のソリューションスタックを使用する場合は、次のオプションからソリューションスタックに適したアプリケーションディレクトリとステージングディレクトリを選択してください。

-----------------------------------------------------
Solution stack             Application directory                    Staging directory
Nodejs                     /var/app/current                         /tmp/deployment/application
PHP                        /var/app/current                         /var/app/ondeck
Ruby (Passenger)           /var/app/current                         /var/app/ondeck
Ruby (Puma)                /var/app/current                         /var/app/ondeck
Java with Tomcat           /usr/share/tomcat*/webapps/ROOT          /tmp/deployment/application/ROOT
Java SE                    /var/app/current                         /var/app/staging
Python                     /opt/python/current/app                  /opt/python/ondeck/app
Go                         /var/app/current                         /var/app/staging
Single Container Docker    /var/app/current                         /var/app/staging
Multi-Container Docker     /var/app/current                         /var/app/staging
-----------------------------------------------------

重要:Elastic Beanstalk アプリケーションをデプロイすると、/var/app/current のコンテンツが /var/app/current.old に移動します。Amazon EFS ボリュームをアプリケーションディレクトリに直接マウントすることはできません。現在デプロイされているソースバンドルは、アプリケーションディレクトリに移動します。Amazon EFS ボリュームを /var/app/current にマウントすると、デプロイが完了した後に、そのボリュームは /var/app/current.old に移動します。

eb-activity.log 出力の例:

===============================
[2020-02-12T02:28:18.237Z] INFO  [3159]  - [Application deployment Sample Application@1/StartupStage1/AppDeployEnactHook/01_flip.sh] : Starting activity...
[2020-02-12T02:28:18.431Z] INFO  [3159]  - [Application deployment Sample Application@1/StartupStage1/AppDeployEnactHook/01_flip.sh] : Completed activity. Result:
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
  + EB_APP_STAGING_DIR=/var/app/ondeck
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir
  + EB_APP_DEPLOY_DIR=/var/app/current
  + '[' -d /var/app/current ']'
  + mv /var/app/current /var/app/current.old
  + mv /var/app/ondeck /var/app/current
  + nohup rm -rf /var/app/current.old
===============================

解決策

Amazon EFS ボリュームを Elastic Beanstalk 環境のアプリケーションディレクトリにマウントするには、次の手順を実行します。

  1. ソースバンドルがステージングディレクトリに解凍されていることを確認します。詳細については、「Elastic Beanstalk 環境の Amazon Elastic Compute Cloud (Amazon EC2) インスタンスからのログの表示」を参照してください。
    eb-activity.log 出力の例:
    ===============================
    [2020-02-12T02:28:16.336Z] INFO  [3159]  - [Application deployment Sample Application@1/StartupStage0/AppDeployPreHook/01_unzip.sh] : Starting activity...
    [2020-02-12T02:28:16.631Z] INFO  [3159]  - [Application deployment Sample Application@1/StartupStage0/AppDeployPreHook/01_unzip.sh] : Completed activity. Result:
      ++ /opt/elasticbeanstalk/bin/get-config container -k app_user
      + EB_APP_USER=webapp
      ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
      + EB_APP_STAGING_DIR=/var/app/ondeck
      ++ /opt/elasticbeanstalk/bin/get-config container -k source_bundle
      + EB_SOURCE_BUNDLE=/opt/elasticbeanstalk/deploy/appsource/source_bundle
      + rm -rf /var/app/ondeck
      + /usr/bin/unzip -d /var/app/ondeck /opt/elasticbeanstalk/deploy/appsource/source_bundle
      Archive:  /opt/elasticbeanstalk/deploy/appsource/source_bundle
         creating: /var/app/ondeck/.ebextensions/
        inflating: /var/app/ondeck/.ebextensions/logging.config
         inflating: /var/app/ondeck/scheduled.php
         inflating: /var/app/ondeck/index.php
         inflating: /var/app/ondeck/cron.yaml
         inflating: /var/app/ondeck/styles.css
        extracting: /var/app/ondeck/logo_aws_reduced.gif
       + chown -R webapp:webapp /var/app/ondeck
      + chmod 775 /var/app/ondeck
    ===============================
    注: /opt/elasticbeanstalk/hooks/appdeploy/pre/ および .ebextensions にあるすべてのappdeploy pre フックは、ステージングディレクトリで実行されます。
  2. ソースバンドルのルートディレクトリに .ebextensions フォルダを作成します。
  3. Amazon EFS ボリューム/efs などの特定のディレクトリにマウントするには、フォーマットされた設定ファイル (YAML または JSON) をディレクトリに追加します。
  4. Amazon EFS ボリュームをアプリケーションディレクトリにマウントするには、ステージングディレクトリへのシンボリックリンクを作成します。ステージングディレクトリを指すシンボリックリンクを /efs から作成するには、container_commands を使用して .ebextensions フォルダーに .config ファイルを作成します。
    例:
    container_commands:
      01_symlink:
        command: ln -s /efs /var/app/ondeck/
    **注:**Elastic Beanstalk 環境でデプロイ中に appdeploy enact フックを実行すると、ステージングディレクトリの内容がアプリケーションディレクトリに移動します。たとえば、PHP ソリューションでは、flip.sh スクリプトはステージングディレクトリの内容がアプリケーションディレクトリに移動します。flip.sh スクリプトは /opt/elasticbeanstalk/hooks/appdeploy/enact/ にある AppDeployEnactHook の最初のスクリプトです。
AWS公式
AWS公式更新しました 3ヶ月前
コメントはありません

関連するコンテンツ