Comment puis-je monter un volume Amazon EFS dans un répertoire d'application dans un environnement Elastic Beanstalk ?

Lecture de 3 minute(s)
0

Je souhaite monter un volume Amazon Elastic File System (Amazon EFS) dans un répertoire d'application dans un environnement AWS Elastic Beanstalk.

Brève description

La résolution suivante fournit des instructions générales pour monter un volume Amazon EFS sur des plateformes basées sur Amazon Linux 1. La résolution utilise la pile de solutions PHP.
Si vous utilisez une autre pile de solutions, choisissez le répertoire d'application et le répertoire intermédiaire appropriés à votre pile de solutions parmi les options suivantes :

-----------------------------------------------------
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
-----------------------------------------------------

Important : lorsque vous déployez une application Elastic Beanstalk, le contenu de /var/app/current est déplacé vers /var/app/current.old. Vous ne pouvez pas monter directement un volume Amazon EFS dans le répertoire d'application. Le groupe source actuellement déployé est déplacé dans le répertoire d'application. Si vous montez le volume Amazon EFS sur /var/app/current, ce volume est déplacé vers /var/app/current.old une fois le déploiement terminé.

Exemple de sortie 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
===============================

Résolution

Pour monter un volume Amazon EFS dans un répertoire d'application dans un environnement Elastic Beanstalk, procédez comme suit :

  1. Vérifiez que le groupe source est décompressé dans le répertoire intermédiaire. Pour plus d'informations, consultez la page Affichage des journaux d’instances Amazon Elastic Compute Cloud (Amazon EC2) dans un environnement Elastic Beanstalk.
    Exemple de sortie 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
    ===============================
    Remarque : tous les hooks appdeploy pre dans /opt/elasticbeanstalk/hooks/appdeploy/pre/ et .ebextensions sont exécutés dans le répertoire intermédiaire.
  2. Créez un dossier .ebextensions dans le répertoire racine du groupe source.
  3. Pour monter un volume Amazon EFS dans un répertoire spécifique, tel que /efs, ajoutez un fichier de configuration formaté (YAML ou JSON) au répertoire.
  4. Pour monter un volume Amazon EFS dans un répertoire d'application, créez un lien symbolique vers le répertoire intermédiaire. Pour créer un lien symbolique depuis /efs qui pointe vers le répertoire intermédiaire, utilisez container_commands pour créer un fichier .config dans le dossier .ebextensions.
    Exemple :
    container_commands:
      01_symlink:
        command: ln -s /efs /var/app/ondeck/
    Remarque : lorsque les hooks appdeploy enact sont exécutés au cours d'un déploiement dans un environnement Elastic Beanstalk, le contenu du répertoire intermédiaire est déplacé vers le répertoire d’application. Par exemple, dans une solution PHP, le script flip.sh déplace le contenu du répertoire intermédiaire vers le répertoire d'application. Le script flip.sh est le premier script de AppDeployEnactHook dans /opt/elasticbeanstalk/hooks/appdeploy/enact/.
AWS OFFICIEL
AWS OFFICIELA mis à jour il y a 3 mois