AWS Builder Center: Learn, Build and Connect with builders in the AWS community
AWS Builder Center is the official home for builders on AWS. Share and read what others are working on, follow people who inspire you, explore training and workshops, and find tools to support what you're building.
Amazon EFS ボリュームを Elastic Beanstalk 環境のアプリケーションディレクトリにマウントする方法を教えてください。
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 環境のアプリケーションディレクトリにマウントするには、次の手順を実行します。
- ソースバンドルがステージングディレクトリに解凍されていることを確認します。詳細については、「Elastic Beanstalk 環境で Amazon Elastic Compute Cloud (Amazon EC2) インスタンスのログを確認する」を参照してください。
eb-activity.log 出力の例:
注: /opt/elasticbeanstalk/hooks/appdeploy/pre/ および .ebextensions にあるすべてのappdeploy pre フックは、ステージングディレクトリで実行されます。=============================== [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 =============================== - ソースバンドルのルートディレクトリに .ebextensions フォルダを作成します。
- Amazon EFS ボリュームを /efs などの特定のディレクトリにマウントするには、YAML または JSON 形式の設定ファイルをそのディレクトリに追加します。
- Amazon EFS ボリュームをアプリケーションディレクトリにマウントするには、ステージングディレクトリへのシンボリックリンクを作成します。ステージングディレクトリを指すシンボリックリンクを /efs から作成するには、container_commands を使用して .ebextensions フォルダに .config ファイルを作成します。
例:
**注:**Elastic Beanstalk 環境でデプロイ中に appdeploy enact フックを実行すると、ステージングディレクトリの内容がアプリケーションディレクトリに移動します。たとえば、PHP ソリューションでは、flip.sh スクリプトはステージングディレクトリの内容がアプリケーションディレクトリに移動します。flip.sh スクリプトは /opt/elasticbeanstalk/hooks/appdeploy/enact/ にある AppDeployEnactHook の最初のスクリプトです。container_commands: 01_symlink: command: ln -s /efs /var/app/ondeck/
関連するコンテンツ
質問済み 3年前

