How do I go about creating Elastic Beanstalk configuration files? - amazon-web-services

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.

Related

Upadate Elastic Beanstalk environment and ebextensions files

I have an elastic beanstalk environment that the first upload I used with ebextensions to configure all the configurations.
Now, If I want to update the environment again (only change the code) the ebextensions stay the same,
I need to insert the ebextensions into the zip file that I upload to update the beanstalk environment?
Or I can ignore the ebextensions and upload the zip as is?
I create the zip file using Visual Studio and I put the ebextensions inside the code.
Thanks
It depends on what is in your .ebextensions. For example, if you just install some rpm packages, then they will still be installed. But generally you would always include the config files anyway, as EB can deploy your application to new instances and then entire configuration has to be re-done from scratch.

How to move/clone an Elastic Beanstalk Environment between (Elastic Beanstalk) Applications

I'm new to AWS. For simplicity I have been working with a number of separate Elastic Beanstalk Environments, within the same Elastic Beanstalk Application
I have come to understand that Applications are just folders for Environments.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.html
I'm just trying to get more organized. Is it even possible?
First of all, applications are not literally folders for environments, according to the documentation an application is "a logical collection of Elastic Beanstalk components".
The idea behind it is to have a single codebase that get deployed to several environments with different configuration depending on your needs. You can have several application versions (or the same version if you want it that way) deployed in several scenarios (environments) with varying configurations, let's say different environment variables, or different values for them, different infrastructure, etc. So, from my point of view there's not much logic in cloning an environment to a different application, since usually different applications would require different configurations.
But, if for your particular needs, you have very similar applications (they use the same platform, consume some of the same resources and basically you wanna deploy them in a very similar way infrastructure-wise) I think a good idea could be writing configuration files for your desired environment and just add those to your different application's code (you can find the official documentation on .ebextensions here, they even give you this link with several common configuration files). Another approach could be directly using CloudFormation templates as discussed here and just recreate the entire application from a CF template.
I hope this helped
Just for someone like me who came here for solutions...
Actually you can clone a environment from one Application to another Application with some steps.
Just follow this AWS - How do I migrate my Elastic Beanstalk environment from one AWS account to another AWS account?
This doc tells you how to do it between 2 AWS accounts but you can do it in just one account. The idea is just:
Save Config in one Application
Load Config in another Application

Elastic Beanstalk environment variable that points to file

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.

Boto3 Deploy to Elastic-beanstalk not reading Config files

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.

Elastic Beanstalk maintain the changes made directly via ssh for new instances?

When the app autoscale, the previous modifications made in first instance will be kept in new instances?
You will need to add configuration settings to your application archive so that each instance is configured the same way when it is brought online. This is done by creating a folder in your application called .ebextensions. You place files in that folder with the .config extenstion. These should be yaml format.
Check these docs for more information:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
Linux specific (I assume Linux since you mention SSH):
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
No, elastic beanstalk will start a new server using a fresh AMI and your latest deployed application code.
It is considered bad practice to change the instance using SSH login, as it may be replaced at any time by Elastic Beanstalk.
If you'd like to change something in the instance, you can either use a custom AMI (not fun) or create an .ebextensions folder and put some configuration shell scripts there (see documentation).