Last active
August 23, 2016 15:57
-
-
Save z5ottu/d96724a4bacc731a36ff0334b92f21d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule ErlEC2 do | |
| # elixir aws ec2 run instances ami | |
| # source: http://donpflaster.net/2016/02/09/controlling-amazon-ec2-instances-with-elixir/ | |
| require Record | |
| Record.defrecord :ec2_instance_spec, Record.extract(:ec2_instance_spec, from: "deps/erlcloud/include/erlcloud_ec2.hrl") | |
| @image_id 'ami-xxxxxxxx' | |
| def start_instances(aws_ids) do | |
| :erlcloud_ec2.start_instances(Enum.map(aws_ids, fn x -> to_char_list x end)) | |
| end | |
| def stop_instances(aws_ids) do | |
| :erlcloud_ec2.stop_instances(Enum.map(aws_ids, fn x -> to_char_list x end)) | |
| end | |
| def create_new_instances(number) do | |
| spec = ec2_instance_spec(image_id: @image_id, | |
| instance_type: 't2.micro', | |
| key_name: 'keypair', | |
| group_set: ['SecGroup'], | |
| min_count: number, | |
| max_count: number) | |
| :erlcloud_ec2.run_instances(spec,Configobject.awsconf) | |
| end | |
| def terminate_instances(aws_ids) do | |
| :erlcloud_ec2.terminate_instances(Enum.map(aws_ids, fn x -> to_char_list x end)) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment