Simple ruby script for deploying applications to AWS Elastic Beanstalk
Usable:
deploy_to_elastic [options]
where [options] are:
--aws-config, -w <s>: The path to the aws config file (default: ./aws_config.yml)
--bucket-name, -b <s>: Name of the bucket to upload war or deployable application
--deploy-file, -d <s>: Path to the deployable application such as a .war file
--version-label, -l <s>: Label of the version you are deploying
--application-name, -a <s>: Name of the application to create or use to deploy
--environment-name, -e <s>: Name of the environment to deploy the new version to
--help, -h: Show this message
Currently, this script will take a deployable application in my case a .war file and uploads it to S3. Then it will create a new application version with the source of the new application of the file that was just uploaded to S3. The last step is that it will update the environment to deploy the new version that you just created.
The tool will use the bucket name as configured in either the command line or in the configuration property. If the bucket does not exist, it will attempt to create it and then continue on wards. The file name that this tool uploads the deployable file as is: ..
In order to run this script you must have ruby install. Currently running this script on v 1.9.2. You also must have the following gems installed:
- yaml - used for configuration files
- aws-sdk - SDK used to connect and use AWS web services
- trollop - used for the command line options
You may also make the need to make deploy_to_elastic.rb runable by performing the following:
chmod +x deploy_to_elastic.rb
I tried to make the tool pretty configurable. There are two main files that you can configure: aws_config.yml and config.yml. Currently, the configuration files take precedent over the command line options for now.
###aws_config.yml
Currently the default location that the tool will look in is the root directory of the application. You can also specify on the command line a different file location or you can override it in the config.yml file that I will explain later. The two main configuration properties needed to run this tool are:
- access_key_id:
- secret_access_key:
This property file gets feed in to AWS.config() method, so in theory you can also configure any other property that is supported by the AWS ruby SDK.
###config.yml
This is a convenience configuration file for the tool. Most of the time you will be working on one application at time and maybe even one environement, etc. In this file you can specify all of the parameters used in the command line options, so that you don't have to keep doing it everytime you wanna run the tool. The configuration file has the "real" names of the command line arguments used in the application and explains what each one does.
Feel free to fork and hack on this as much as you want. I'll probably be modifying it as well as I get more involved with Elastic Beanstalk, or feel free to suggest features that you want to add to this. I'm not sure if there are other tools out there that does exactly this. I know you can deploy from eclipse and other places, but I couldn't find a configurable script to do what I wanted. I am also a beginner when it comes to Ruby, so if there are suggestions or best practices that I should follow me, I encourage the feedback.
Please note that using AWS incurs costs to you. Creating S3 buckets, uploading files, starting up EB instances, etc all cost something. I am not responsible for these costs when using this script. Just wanted to make sure you were aware of these costs before using this script.
- Add more options such as setting the description and whether or not to auto create the application if none exists
- Include subcommands so that the user can perform any of the steps instead of going through the entire process
- Add better logging/output, also find a way of implementing a status bar when uploading the file, so that the user has some indication that the file is still being upload.
- Add a MakeFile so that a user can install the script pretty easily