Help us understand the problem. What is going on with this article?

EC2インスタンスをAWS CLIで起動する

More than 3 years have passed since last update.

AWSCLIの初期設定

実行コマンド
aws configure

IAMであらかじめユーザーを作成しておく必要があります。
アクセスキーやシークレットアクセスキーは作成したユーザーのものを利用します。

起動

実行コマンド
aws ec2 start-instances --instance-ids "i-xxxxxxxxxxxxxxxxx"
処理結果
{
    "StartingInstances": [
        {
            "InstanceId": "i-xxxxxxxxxxxxxxxxx", 
            "CurrentState": {
                "Code": 0, 
                "Name": "pending"
            }, 
            "PreviousState": {
                "Code": 80, 
                "Name": "stopped"
            }
        }
    ]
}

状態表示(起動後)

実行コマンド
aws ec2 describe-instance-status --instance-ids "i-xxxxxxxxxxxxxxxxx"
処理結果
{
    "InstanceStatuses": [
        {
            "InstanceId": "i-xxxxxxxxxxxxxxxxx", 
            "InstanceState": {
                "Code": 16, 
                "Name": "running"
            }, 
            "AvailabilityZone": "ap-northeast-1a", 
            "SystemStatus": {
                "Status": "initializing", 
                "Details": [
                    {
                        "Status": "initializing", 
                        "Name": "reachability"
                    }
                ]
            }, 
            "InstanceStatus": {
                "Status": "initializing", 
                "Details": [
                    {
                        "Status": "initializing", 
                        "Name": "reachability"
                    }
                ]
            }
        }
    ]
}

起動完了待ち

; で区切ってコマンド指定することで、起動完了後に処理することができます。

実行コマンド
aws ec2 wait instance-running --instance-ids "i-xxxxxxxxxxxxxxxxx"; echo "next command"

停止

実行コマンド
aws ec2 stop-instances --instance-ids "i-xxxxxxxxxxxxxxxxx"
処理結果
{
    "StoppingInstances": [
        {
            "InstanceId": "i-xxxxxxxxxxxxxxxxx", 
            "CurrentState": {
                "Code": 64, 
                "Name": "stopping"
            }, 
            "PreviousState": {
                "Code": 16, 
                "Name": "running"
            }
        }
    ]
}

状態表示(停止中)

停止状態でdescribe-instance-statusすると、結果のjsonが空値で返ってきます。

実行コマンド
aws ec2 describe-instance-status --instance-ids "i-xxxxxxxxxxxxxxxxx"
処理結果
{
    "InstanceStatuses": []
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした