Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download S3 and Add to App Directory

I have an elastic beanstalk Node app that I'm trying to setup. I'm trying to load an environment file from S3 into /var/app/ondeck/src/ so the file is available when the Node app is started. I've tried as many things as I can think of but the production.env file never shows up. If I change the location to something like /home/ec2-user the file appears so I know that I have the file part correct. What am I missing?

files:
  "/var/app/ondeck/src/production.env":
    mode: "000777"
    user: nodejs
    group: nodejs
    source: https://s3.amazonaws.com/bucket-name/file.env

Resources:
  AWSEBAutoScalingGroup:
    Metadata:
      AWS::CloudFormation::Authentication:
        S3Access:
          type: S3
          roleName: aws-elasticbeanstalk-ec2-role
          buckets: bucket-name

========

A last resort idea was to run a container_command that would just copy the file from /home/ec2-user into /var/app/current/src/ or /var/app/ondeck/src/ but that didn't seem to work either. I prefer to get the top example to work if at all possible.

container_commands:
  command: "/bin/cp /home/ec2-user/production.env /var/app/ondeck/production.env"
like image 708
adam8810 Avatar asked Oct 24 '25 04:10

adam8810


1 Answers

Your latter option seems to be working for me with some modifications. Note the following:

  • I use mv instead of cp
  • in my case I have an owner and group of webapp instead of nodejs, but probably that's just because of me using Beanstalk for PHP rather than Node
  • I have a name for my container command
  • I'm using a relative path for the container command's destination file
  • I haven't tested with authentication since my particular use case involves a file that is public

It'd be something like:

files:
  "/home/ec2-user/production.env":
    mode: "000644"
    owner: nodejs
    group: nodejs
    source: https://s3.amazonaws.com/bucket-name/file.env

container_commands:
  01_mv_to_app_dir:
    command: "mv /home/ec2-user/production.env ./production.env"
like image 57
jmq Avatar answered Oct 25 '25 19:10

jmq