OSDN Git Service

Regular updates
[twpd/master.git] / ec2.md
1 ---
2 title: EC2 API tools
3 category: Devops
4 ---
5
6 ### Install
7
8     $ sudo apt-get install ec2-api-tools ec2-ami-tools
9     $ brew install ec2-api-tools ec2-ami-tools
10
11 ### Pem files
12
13     $ brew info ec2-api-tools
14
15  * Before you can use these tools you must export some variables to your $SHELL
16    and download your X.509 certificate and private key from Amazon Web Services.
17
18  * Your certificate and private key are available at
19    [aws-portal.amazon.com](http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key).
20
21  * Download two `.pem` files, one starting with `pk-`, and one starting with `cert-`.
22    You need to put both into a folder in your home directory, `~/.ec2`.
23
24 ### Key pair
25
26     # To use public images (AMI's), you need an SSH keypair from EC2.
27       ec2-add-keypair my-keypair > ~/.ec2/my-keypair.pem
28       chmod 600 ec2-keypair.pem
29
30 ### Start an instance
31
32     # Start an instance using a given AMI image:
33     # (Use the Ubuntu locator, or ec2-describe-images)
34       ec2-run-instances ami-xxxxxx -k ec2-keypair
35
36     # Open up ports (in the 'default' security group):
37       ec2-authorize default -p 22
38       ec2-authorize default -p 80
39
40     # Connect
41       ssh -i ~/.ec2/my-keypair.pem root@ec2-xxx.amazonaws.com
42
43 ### Management
44
45     # Show running instances
46       ec2-describe-instances
47
48     # Kill an instance
49       ec2-terminate-instances i-yourinstance
50
51 ### Misc
52
53     # Create a security group
54       ec2-add-group group_name -d "Description"
55
56     # Show images (AMI's) owned by amazon, or me
57       ec2-describe-images -o self -o amazon
58
59 ### Ubuntu images
60
61  * [Ubuntu EC2 AMI locator](http://cloud-images.ubuntu.com/locator/ec2/)
62
63 ### Change certificates
64
65     EC2_CERT_PATH="$HOME/.ec2"
66     export EC2_PRIVATE_KEY="$(/bin/ls $EC2_CERT_PATH/pk-*.pem | /usr/bin/head -1)"
67     export EC2_CERT="$(/bin/ls $EC2_CERT_PATH/cert-*.pem | /usr/bin/head -1)"