0
- Create :capsize_config_dir
0
- Create :capsize_secure_config_dir
0
- Copy capsize.yml.template to :capsize_config_dir/capsize.yml unless it already exists
0
- - Copy secure.yml.template to :capsize_secure_config_dir/secure.yml unless it already exists
0
- - Instruct user to add AWS keys to secure.yml or capsize.yml
0
+ - Automatically generate :capsize_secure_config_dir/secure.yml unless it already exists
0
- Instruct user to test configuration with "cap ec2:images:describe"
0
- Instruct user how to create a new keypair
0
- Instruct user how to setup a new security group.
0
# copy the standard config file template, unless the dest file alread exists
0
- unless File.exists?("#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}")
0
- FileUtils.cp("#{fetch(:capsize_examples_dir)}/capsize.yml.template", "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}", :verbose => true)
0
- puts "Warning : The following file was not copied over since it already exists: " + "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}"
0
- # copy the secure config file template, unless the dest file alread exists
0
unless File.exists?("#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}")
0
- FileUtils.cp("#{fetch(:capsize_examples_dir)}/secure.yml.template", "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}", :verbose => true)
0
- puts "Warning : The following file was not copied over since it already exists: " + "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}"
0
+ puts "Please enter your EC2 account information."
0
+ puts "We'll then write it to a config file at #{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}"
0
+ set :aws_access_key_id, proc { Capistrano::CLI.ui.ask("AWS Access Key ID : ") }
0
+ set :aws_secret_access_key, proc { Capistrano::CLI.ui.ask("AWS Secret Access Key : ") }
0
-
Capsize Config Setup Instructions:0
+ # Populate production element
0
+ yaml['common']['aws_access_key_id'] = aws_access_key_id
0
+ yaml['common']['aws_secret_access_key'] = aws_secret_access_key
0
- Your Capsize config files have been created. You should now add your
0
- Amazon Web Services 'Access Key ID' and 'Secret Access Key' to the secure.yml
0
- file we created for you in your config dir.
0
+ yaml = YAML::dump(yaml).split("\n").collect { |line| line == "common: " ? line += "&common" : line }.join("\n")
0
- Once you have done this you should be able to test out your ability to use
0
- Capsize by running the following command:
0
- If you receive a congratulatory response then you are ready to continue using Capsize.
0
- If you receive an Exception message please use that to help you troubleshoot further.
0
+ # Uncomment and I only apply to the dev environment
0
+ # or overwrite a common value
0
- Once you have succesfully tested your connection to EC2, please continue with the next
0
- Step 2 : Create a new key pair (highly recommended but optional):
0
- Once you have completed the first step successfully, the next recommended step
0
- is to create a an Amazon EC2 keypair that is specifically tailored for use
0
- with your application. This keypair will be used to allow you to create new
0
- EC2 instances that can accept public key authentication for passwordless login.
0
- By default the keypair created will be named the same as the :application setting
0
- in your deploy.rb file (run 'cap -e ec2:keypairs:create' for more info.).
0
- Setting up a new keypair in this fashion does not preclude you from using a
0
- different keypair of your choice in the future.
0
+ # Uncomment and I only apply to the production environment
0
+ # or overwrite a common value
0
-
Run the following command to create a new keypair for your application:0
+ File.open("#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}", 'w') do |file|
0
+ File.chmod 0664, "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}"
0
+ puts "Warning : The following file was not copied over since it already exists: " + "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}"
0
- cap ec2:keypairs:create
0
+ unless File.exists?("#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}")
0
+ FileUtils.cp("#{fetch(:capsize_examples_dir)}/capsize.yml.template", "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}", :verbose => true)
0
+ puts "Warning : The following file was not copied over since it already exists: " + "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}"
0
- Once you successfully create your keypair, guard your new private key carefully
0
- as it allows the holder of that key to access EC2 instances started using that key.
0
-
Step 3 : Create a new security group + open ports (highly recommended but optional):0
- Security groups contain a set of firewall rules that apply to any
0
- EC2 instance started that is configured to use that specific security
0
- group. Running the command below will create a new security group
0
- that is named after your :application setting in deploy.rb which you can
0
- use instead of the 'default' security group that EC2 creates for you.
0
+ ec2.security_groups.create_with_standard_ports
0
- This command will also open firewall ports for your new group that match the standard
0
- web ports most applications need (22-SSH, 80-HTTP, 443-HTTPS). If this is
0
- not suitable for you then please read the docs for 'ec2:security_groups:create'
0
- and 'ec2:security_groups:authorize_ingress'
0
+
Next up: Pick an Amazon Machine Image and Run it!0
- cap ec2:security_groups:create_with_standard_ports
0
- -------------------------------------------------------------------------------
0
- At this point your configuration is complete and we can get down to running and
0
- using Amazon EC2 instances. In most cases, you should not have to repeat any
0
- of the previous commands again.
0
- -------------------------------------------------------------------------------
0
- Step 4 : Pick an Amazon Machine Image and Run it!
0
Now you need to select an Amazon EC2 image ID that you want to start as a new
0
instance. The easiest way to do that is to get a list of available images from EC2.
0
# Show ALL registered images
0
- cap ec2:images:
describe0
# Show MY registered images
0
- cap ec2:images:
describe OWNER_ID='self'
0
+ cap ec2:images:
show OWNER_ID='self'
0
# Show the AMAZON registered images
0
- cap ec2:images:
describe OWNER_ID='amazon'
0
+ cap ec2:images:
show OWNER_ID='amazon'
0
- Select an 'imageId' from the results,
it will look like: 'ami-2bb65342'0
+ Select an 'imageId' from the results,
and run it:0
cap ec2:instances:run IMAGE_ID='ami-2bb65342'
0
You should see some progress information scroll by and finally you should see
0
Now lets connect to it with SSH (this may take a few tries, sometimes it takes a
0
minute for the new instance to respond to SSH):
0
- RUN (replace instance ID with the one reported in the previous step):
0
cap ec2:instances:ssh INSTANCE_ID='i-xxxxxx'
0
- TADA! You should be connected to your new instance in an SSH terminal. When you are
0
- done looking around type ^d (control-d) to exit the SSH shell.
0
If you want to terminate your instance...
0
- RUN (replace the instance ID with the one reported in the previous step):
0
cap ec2:instances:terminate INSTANCE_ID='i-xxxxxx'
0
- You're done with your first amazon-ec2 and Capsize tutorial!
Comments
No one has commented yet.