2

I've recently started using AdonisJS for API development. I'm using AWS Elastic Beanstalk together with AWS CodeCommit and AWS CodePipeline to deploy new code on each git push. Since .env file is not present in git repository, I've added env variables through Elastic Beanstalk web console. But deployment failed when I tried to run node ace migration:run command.

Activity execution failed, because: 
  Error: ENOENT: no such file or directory, open '/tmp/deployment/application/.env'


  1 Env.load
  /tmp/deployment/application/node_modules/@adonisjs/framework/src/Env/index.js:110

  2 new Env
  /tmp/deployment/application/node_modules/@adonisjs/framework/src/Env/index.js:42

  3 Object.app.singleton [as closure]
  /tmp/deployment/application/node_modules/@adonisjs/framework/providers/AppProvider.js:29

  4 Ioc._resolveBinding
  /tmp/deployment/application/node_modules/@adonisjs/fold/src/Ioc/index.js:231

  5 Ioc.use
  /tmp/deployment/application/node_modules/@adonisjs/fold/src/Ioc/index.js:731

  6 AppProvider.boot
  /tmp/deployment/application/node_modules/@adonisjs/framework/providers/AppProvider.js:337

  7 _.filter.map
  /tmp/deployment/application/node_modules/@adonisjs/fold/src/Registrar/index.js:147

  8 arrayMap
  /tmp/deployment/application/node_modules/lodash/lodash.js:639

   (ElasticBeanstalk::ExternalInvocationError)

Then I've tried to add ENV_SILENT=true flag before each command as stated in AdonisJS documentation. But that did not help.

So then, I've tried to upload .env file on S3 bucket, and copy its contents during deployment. But it seems it does not work, since I'm getting the same error (no .env file).

These are my 2 config files from .ebextensions folder

01_copy_env.config (I'm using x-xxxxxxxxxxxx here for security)

Resources:
  AWSEBAutoScalingGroup:
    Metadata:
      AWS::CloudFormation::Authentication:
        S3Auth:
          type: "s3"
          buckets: ["elasticbeanstalk-us-east-x-xxxxxxxxxxxx"]
          roleName:
            "Fn::GetOptionSetting":
              Namespace: "aws:autoscaling:launchconfiguration"
              OptionName: "IamInstanceProfile"
              DefaultValue: "aws-elasticbeanstalk-ec2-role"
files:
  "/tmp/deployment/application/.env":
    mode: "000755"
    owner: root
    group: root
    authentication: "S3Auth"
    source: https://elasticbeanstalk-us-east-x-xxxxxxxxxxxx.s3.us-east-2.amazonaws.com/variables.txt

02_init.config

container_commands:
    01_node_binary:
        command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-v10* | head -1`/bin/node /bin/node"
        leader_only: true
    02_migration:
        command: "node ace migration:run"
    03_init_seed:
        command: "node ace seed"

The only time the whole thing works is when I add .env file to git and deploy it with the rest of the code. But that is not the way to go, so if anyone knows a solution to my problem I would really appreciate it. Thanks!

Zoka
  • 291
  • 2
  • 8
  • 1
    Try to add new variable : `ENV_SILENT = true` – crbast Nov 26 '19 at 15:15
  • 1
    I actually solved it by adding that flag to package.json -> scripts -> start. And then in elastic beanstalk environment configuration I've added npm run start as node command to start nodejs app. – Zoka Nov 26 '19 at 15:46
  • Okay nice. I add answer for next viewers. Can you validate or change it? – crbast Nov 26 '19 at 16:02

1 Answers1

2

Add new variable ENV_SILENT = true on your global variables (Elastic Beanstalk)

Adonis documentation

crbast
  • 1,750
  • 1
  • 7
  • 16