A script to manage EC2 instances, in particular, to start/stop an instance, update the instance's SG ingress rules with your IP, and get the instance's state.
In order to use the script, you must populate a configuration file called .servers
.
[rdp_server]
instance_id = <instance id>
region = ca-central-1
sg_id = <sg id>
range_description = Christopher home
[vpn_server]
instance_id = <instance id>
region = us-east-2
sg_id = <sg id>
range_description = Christopher
Start the instance, wait for it to go into running
state, and then output
the public DNS name.
./server start rdp_server
ec2-<ip>.ca-central-1.compute.amazonaws.com
Stop the instance.
./server stop rdp_server
Output the instance's current state.
./server get_state rdp_server
stopped
Scope all IP ranges with a description matching the description in the configuration file to your current public IP address, and then output the security group's ingress rules.
./server update_sg_ingress vpn_server
[
{
"FromPort": 1701,
"IpProtocol": "udp",
"IpRanges": [
{
"CidrIp": "<some other ip>/32",
"Description": "Amy"
},
{
"CidrIp": "<my ip>/32",
"Description": "Christopher"
}
],
"Ipv6Ranges": [],
"PrefixListIds": [],
"ToPort": 1701,
"UserIdGroupPairs": []
},
{
"FromPort": 4500,
"IpProtocol": "udp",
"IpRanges": [
{
"CidrIp": "<some other ip>/32",
"Description": "Amy"
},
{
"CidrIp": "<my ip>/32",
"Description": "Christopher"
}
],
"Ipv6Ranges": [],
"PrefixListIds": [],
"ToPort": 4500,
"UserIdGroupPairs": []
},
{
"FromPort": 500,
"IpProtocol": "udp",
"IpRanges": [
{
"CidrIp": "<some other ip>/32",
"Description": "Amy"
},
{
"CidrIp": "<my ip>/32",
"Description": "Christopher"
}
],
"Ipv6Ranges": [],
"PrefixListIds": [],
"ToPort": 500,
"UserIdGroupPairs": []
}
]