I understand how to set environment variables in Elastic Beanstalk, but how do I make these variables point to files of my choice?
S3, bundling the target file in my JAR, and other AWS services are all options for me.
Context: I am trying to use google-apps-clj, a Clojure library for using certain Google applications. One requirement of using google-apps-clj is that a JSON configuration file exists and that there is an environment variable (GOOGLE_APPLICATION_CREDENTIALS) that points to it (optionally, the file could exist at ~/.config/gcloud/application_default_credentials.json without such an environment variable). My Clojure app is running on AWS Elastic Beanstalk, and I use lein-beanstalk to automate some of the boring stuff.
Related
Im trying to deploy this application on an AWS ECS server using Elastic Beanstalk (EB). I'm loosely following this medium article.
The project is using several environment variables in the docker compose file which are essential for the application. However EB requires Dockerrun.aws.json (equivalent of docker-compose.yml) and one way to add environment variables to Dockerrun json is mentioned here, but I will be passing some credentials to through the environment variables hence exposing those values in the json file will be a security risk.
I have went through the documentation and there wasn't any such feature which allowed the use of environment variable / .env file. Is there a way to add it to the dockerrun file? If not then is there any workaround for using environment variables?
I am using boto3 to deploy my environment to elastic beanstalk using the create_environment function. I have my configuration files in the .elasticbeanstalk folder but the deploy doesn't seem to be using them. When I deploy the same environment using the eb client it works exactly as wanted. Any suggestions?
I figured this out.
boto3 uses the aws api, which does not read the configuration files but rather reads a json configuration option (called option_settings). These allow you to configure all of your post-ec2-deploy settings (Everything you can change from the elastic beanstalk configuration page).
However, if you want to adjust configuration for what your ec2 instance has installed before your application runs (things like package installs, file creation, etc.) then you will have to create an aws image of a ec2 instance you like, and then reference that image id from the option_settings.
obviously the eb client does all of the above for you by reading the configuration files.
I am looking for advice about how I should approach the problem of creating Elastic Beanstalk configuration files.
How do I go about constructing an Elastic Beanstalk configuration files?
How do I know what to include or not include?
Do I construct it by hand using the template reference or are they typically generated by a configuration tool?
You can modify the configuration of Elastic Beanstalk environments in multiple ways.
One way is to place a folder with the name .ebextensions inside your app source zip. Inside this folder you can have one or more files with a .config extension. Files will be processed in the alphabetical order of their name. These files are formatted using YAML syntax.
These files allow you to control lots of configuration options for your beanstalk environments.
This page explains various things you can configure using ebextensions (assuming you are on a linux environment). You can read about ebextensions on Windows here. On this page you will find information on how different parts of your environment configuration can be controlled, e.g. you can install packages on your instances, you can create files, you can run shell commands on your instances during deployment, you can control settings of your environment etc.
You can also control option_settings for your environment using these config files. You can read more details about what option settings are supported here.
You can also modify properties of AWS resources like load balancer, auto scaling groups etc. created by beanstalk or you can create new resources like DynamoDB tables using ebextensions. Documentation on how to create or modify resources is available here.
I've got a Java servlet packaged in a war, and need to deploy it to Elastic Beanstalk. I can roll my own deployment script using Amazonica, but I'd rather leverage Pallet for this.
A Google search for "pallet elastic beanstalk" is not turning up anything useful, other than a "How to deploy a clojure web application to Amazon EC2" question on Stack Overflow. The answer looks quite promising, but it doesn't cover setting environment properties, and I'm not sure whether that group spec would create an Elastic Beanstalk environment or a regular EC2 one with Tomcat.
Has anyone done this? Is there a nice blog post or recipe for it?
Just to be clear, the war itself is not a Clojure app, it is just a war built with Maven from a Java project somewhere.
Since this is not an action that happens to an instance, for instance it does not change a member of a pallet group, I would recommend using clj-action to upload it using amazonica at the appropriate place in the phase.
I'm assuming that some instance (or group) you are deploying with pallet needs this web service to be in place so it can be configured to connect to it. In cases like this it would make sense to define a phase which uploads the war file and saves its configuration into the session. Then later phases on any instance in the deployment can see where the web service is available.
If it's only needed by one instance/group then it's fine to simply call amazonica (through clj-action) in the middle of the configure phase and then configure that instance to use the web service in the same plan-fn.
My Grails application is currently using System.env.MY_SYS_PROP and it does not work when I set the params via Beanstalk Environment Properties which get passed to the Application.
System.getProperty("MY_SYS_PROP") works but I'd like to keep the app as is with access to the properties via System.env.MY_SYS_PROP
How do I set the System Environmental properties on AWS Beanstalk instance via config files?
I would recommend using the Elastic Beanstalk environment properties as this is more flexible since it keeps the configuration external to the WAR package.
However, if you must use environment variables, you can use the Elastic Beanstalk option_settings mechanism to set environment variables when container instances are created.
For Grails you can check out the Grails Elastic Beanstalk plugin (I am the author) that will be supporting this feature in the upcoming 0.3 release.