如何將 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 官方已更新 2 個月前