[Alibaba Cloud] VPC + ECS作成ハンズオン

## 目標

**主だったコマンドを使ってみる**

サービスごとに[ Create ]から[ Delete ]まで複数のコマンドが存在しています。
さらにサービスの利用には他のサービスのリソースが必要でだったりと、
CLIを使うことはサービスの理解に繋がっているとも考えられます。
各種のサービスをコマンドを使いながらECSが起動するところまでやっていきましょう。

**同じ内容のものを Terraform で作ったものが下記の URL にありますので、こちらもご参照ください**

https://qiita.com/n_watanabe/items/ef64d95014e47864c440#_reference-9bf5a3f804799c3e3fdf

## 事前準備

[Alibaba Cloud] CLI の始め方

https://qiita.com/n_watanabe/items/1ca89c3a3cf5dc650305

## 構成図

![image.png](https://qiita-image-store.s3.amazonaws.com/0/161922/0f884f0e-eee7-6344-78cc-092d699d3d24.png)

**[作成していく順番]**

```:目次
1. VPCの作成
   1-1. 環境変数の設定
   1-2. VPCの作成
   1-3. VPCの確認

2. VSwitchの作成
   2-1. 環境変数の設定
   2-2. VSwitchの作成
   2-3. VSwitchの確認

3. EIPの作成
   3-1. 環境変数の設定
   3-2. EIPの作成
   3-3. EIPの確認

4. SecurityGroupの作成
   4-1. 環境変数の設定
   4-2. SecurityGroupの作成
   4-3. SecurityGroupの確認

5. SecurityGroupの受信ルール追加
   5-1. 環境変数の設定
   5-2. SecurityGroupのルール関連付け
   5-3. SecurityGroupの確認

6. Instance(ECS)の作成
   6-1:a. データの用意
   6-1:b. 環境変数の設定
   6-2. Instanceの作成
   6-3. Instanceの確認

7. InstanceとEIPの紐付け
   7-1.環境変数の設定
   7-2. InstanceとEIPの紐付け
   7-3. 紐付けの確認

8. インスタンスの起動
   8-1.環境変数の設定
   8-2. Instanceの起動
   8-3. 起動確認

9. 画面確認
   9-1.環境変数の設定
   9-2. curlで確認
   9-2:おまけ. ブラウザでも確認
```

```
10.後片付け
   10-1.環境変数の設定

   10-2:a. Instanceの停止
   10-2:b. Instanceの確認
   10-2:c. Instanceの削除
   10-2:d. Instanceの確認

   10-3:a SecurityGroupの削除
   10-3:b SecurityGroupの確認

   10-4:a. EIPの確認
   10-4:b. EIPの削除

   10-5:a. VSwitchの削除
   10-5:b. VSwitchの確認

   10-6:a. VPCの削除
   10-6:b. VPCの確認
```


## 1. VPCの作成

### VPC とは？

Alibaba Cloudに設置されたプライベートネットワーク。
VPCはAlibaba Cloudの他の仮想ネットワークと論理的に分離されており、
プライベートCIDRブロック、VRouter、及びVSwitchで構成されます。 

VPCのドキュメントはこちら

> https://jp.alibabacloud.com/help/doc-detail/34217.htm?spm=a21mg.p38356.b99.3.ba06354cEh1JZq

#### 1-1.環境変数の設定

```:設定
VPC_NAME="VPC"
VPC_DESC="Aliyun VPC"
VPC_CIDR_BLOCK="172.16.0.0/16"
REGION_ID="ap-northeast-1"
```

```:確認
cat << EOF

  REGION_ID="ap-northeast-1"
  REGION_ID="${REGION_ID}"

  VPC_NAME="VPC"
  VPC_NAME="${VPC_NAME}"

  VPC_DESC="Aliyun VPC"
  VPC_DESC="${VPC_DESC}"

  VPC_CIDR_BLOCK="172.16.0.0/16"
  VPC_CIDR_BLOCK="${VPC_CIDR_BLOCK}"

EOF
```

#### 1-2. VPCの作成

> https://jp.alibabacloud.com/help/doc-detail/35737.htm?spm=a21mg.p38356.b99.55.715731c7Rs4pFJ

<img width="729" alt="1.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/2005dc1f-cbf2-e72f-cb49-4e3013fba8b8.jpeg">


```:CreateVpc
aliyun vpc CreateVpc \
  --VpcName ${VPC_NAME} \
  --Description "${VPC_DESC}" \
  --CidrBlock ${VPC_CIDR}
```

```:応答
{
        "RequestId": "003639D9-3078-468B-80D7-79091989722D",
        "ResourceGroupId": "rg-XXXXXXXXXXXXXXX",
        "RouteTableId": "vtb-XXXXXXXXXXXXXXXXXXXXX",
        "VpcId": "vpc-XXXXXXXXXXXXXXXXXXXXX",
        "VRouterId": "vrt-XXXXXXXXXXXXXXXXXXXXX"
}
```

#### 1-3. VPCの確認

> https://jp.alibabacloud.com/help/doc-detail/35739.htm?spm=a21mg.p38356.b99.57.1eaa457brARskO

<img width="725" alt="2.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/c7e3ba0f-3bf1-dcaa-b7ce-93a6e8942e50.jpeg">


```:DescribeVpcs
aliyun vpc DescribeVpcs \
  --VpcName ${VPC_NAME}
```

```:応答
{
	"PageNumber": 1,
	"Vpcs": {
		"Vpc": [
			{
				"VpcName": "VPC",
				"Description": "Aliyun VPC",
				"IsDefault": false,
				"NatGatewayIds": {
					"NatGatewayIds": []
				},
				"ResourceGroupId": "rg-XXXXXXXXXXXXXXX",
				"UserCidrs": {
					"UserCidr": []
				},
				"NetworkAclNum": 0,
				"RouterTableIds": {
					"RouterTableIds": [
						"vtb-XXXXXXXXXXXXXXXXXXXXX"
					]
				},
				"VpcId": "vpc-XXXXXXXXXXXXXXXXXXXXX",
				"VRouterId": "vrt-XXXXXXXXXXXXXXXXXXXXX",
				"CreationTime": "2019-05-11T06:19:28Z",
				"Status": "Available",
				"CidrBlock": "172.16.0.0/16",
				"VSwitchIds": {
					"VSwitchId": []
				},
				"RegionId": "ap-northeast-1",
				"Ipv6CidrBlock": ""
			}
		]
	},
	"TotalCount": 1,
	"PageSize": 10,
	"RequestId": "003639D9-3078-468B-80D7-79091989722D"
}
```

<img width="1440" alt="3.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/1c0a9513-75b4-665f-82b3-3cf343d5caeb.jpeg">



2. VSwitchの作成

### VSwitch とは？

VSwitchはVPCネットワーク内の基本的なネットワークモジュールで、
VPC内の様々なクラウド製品のインスタンスへ接続するに使用される。

**<font color="red">VSwitch は AWS で言うところの Subnet</font>**

VSwitchのドキュメントはこちら

> https://jp.alibabacloud.com/help/doc-detail/65387.htm?spm=a21mg.p38356.b99.15.2bd33278HB4Rdb


#### 2-1.環境変数の設定

```:設定
VPC_ID=$( \
  aliyun vpc DescribeVpcs \
    --VpcName ${VPC_NAME} \
    | jq '.Vpcs.Vpc[].VpcId' \
    | sed 's/"//g'
)
ZONE_ID="ap-northeast-1a"
VSWITCH_NAME="VSw"
VSWITCH_DESC="Aliyun VSwitch"
VSWITCH_CIDR="172.16.1.0/24"
```

```:確認
cat << EOF

  VPC_ID="vpc-XXXXXXXXXXXXXXXXXXXXX"
  VPC_ID="${VPC_ID}"

  ZONE_ID="ap-northeast-1a"
  ZONE_ID="${ZONE_ID}"

  VSWITCH_NAME="VSw"
  VSWITCH_NAME="${VSWITCH_NAME}"

  VSWITCH_DESC="Aliyun VSwitch"
  VSWITCH_DESC="${VSWITCH_DESC}"

  VSWITCH_CIDR="172.16.1.0/24"
  VSWITCH_CIDR="${VSWITCH_CIDR}"

EOF
```

#### 2-2.VSwitchの作成

> https://jp.alibabacloud.com/help/doc-detail/35745.htm?spm=a21mg.p38356.b99.60.74bd34812ACAMj

<img width="731" alt="4.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/8daf2eb1-d765-9b36-9a31-e71cef8830f3.jpeg">


```:CreateVSwitch
aliyun vpc CreateVSwitch \
  --VpcId ${VPC_ID} \
  --ZoneId ${ZONE_ID} \
  --VSwitchName ${VSWITCH_NAME} \
  --Description "${VPC_DESC}" \
  --CidrBlock ${VSWITCH_CIDR}
```

```:応答
{
	"RequestId": "4A295D33-A5A2-40E5-96B8-FD680148EEEE",
	"VSwitchId": "vsw-XXXXXXXXXXXXXXXXXXXXX"
}
```

#### 2-3.VSwitchの確認

> https://jp.alibabacloud.com/help/doc-detail/35748.htm?spm=a21mg.p38356.b99.62.15103278Eb0FXc

<img width="724" alt="5.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/e206aa43-4ade-9b60-58a1-14aad8c04365.jpeg">


```:DescribeVSwitches
aliyun vpc DescribeVSwitches \
  --VSwitchName ${VSWITCH_NAME} | jq .
```

```:応答
{
	"PageNumber": 1,
	"VSwitches": {
		"VSwitch": [
			{
				"RouteTable": {
					"RouteTableId": "vtb-XXXXXXXXXXXXXXXXXXXXX",
					"RouteTableType": "System"
				},
				"Description": "Aliyun VPC",
				"IsDefault": false,
				"AvailableIpAddressCount": 252,
				"ResourceGroupId": "rg-XXXXXXXXXXXXXXX",
				"ZoneId": "ap-northeast-1a",
				"VSwitchId": "vsw-XXXXXXXXXXXXXXXXXXXXX",
				"NetworkAclId": "",
				"VpcId": "vpc-XXXXXXXXXXXXXXXXXXXXX",
				"CreationTime": "2019-05-11T13:24:43Z",
				"Status": "Available",
				"CidrBlock": "172.16.1.0/24",
				"VSwitchName": "VSw",
				"Ipv6CidrBlock": ""
			}
		]
	},
	"TotalCount": 1,
	"PageSize": 10,
	"RequestId": "4A295D33-A5A2-40E5-96B8-FD680148EEEE"
}
```

<img width="1440" alt="6.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/3bc4490d-fd71-d513-d9ac-6d43236380d0.jpeg">



## 3. EIPの関連付け

### EIP とは？

個別に購入できるパブリック IP アドレスリソース。
VPCネットワーク の ECS、SLB インスタンスや、NATゲートウェイに EIP をバインドできる。

EIPのドキュメントはこちら

> https://jp.alibabacloud.com/help/doc-detail/32321.htm?spm=a21mg.l28256.a3.2.541b483fdcq9wC

#### 3-1.環境変数の設定

```:設定
EIP_BANDWIDTH="1"
EIP_INTERNET_CHARGE_TYPE="PayByTraffic"
EIP_INSTANCE_CHARGE_TYPE="PostPaid"
```

```:確認
cat << EOF

  EIP_BANDWIDTH="1"
  EIP_BANDWIDTH="${EIP_BANDWIDTH}"

  EIP_INTERNET_CHARGE_TYPE="PayByTraffic"
  EIP_INTERNET_CHARGE_TYPE="${EIP_INTERNET_CHARGE_TYPE}"

  EIP_INSTANCE_CHARGE_TYPE="PostPaid"
  EIP_INSTANCE_CHARGE_TYPE="${EIP_INSTANCE_CHARGE_TYPE}"

EOF
```

#### 3-2.EIPの作成

> https://jp.alibabacloud.com/help/doc-detail/36016.htm?spm=a21mg.p38356.b99.137.38214153UlZJRz

<img width="745" alt="7.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/121cc490-f748-18c7-642f-86c3e359855d.jpeg">


```:AllocateEipAddress
aliyun vpc AllocateEipAddress \
  --Bandwidth ${EIP_BANDWIDTH} \
  --InternetChargeType ${EIP_INTERNET_CHARGE_TYPE} \
  --InstanceChargeType ${EIP_INSTANCE_CHARGE_TYPE} | jq .
```

```:応答
{
	"ResourceGroupId": "rg-XXXXXXXXXXXXXXX",
	"RequestId": "F175D5ED-AB55-4D48-8B13-97E318D97187",
	"EipAddress": "XXX.XXX.XXX.XXX",
	"AllocationId": "eip-XXXXXXXXXXXXXXXXXXXXX"
}
```

#### 3-3.EIPの確認

> https://jp.alibabacloud.com/help/doc-detail/36018.htm?spm=a21mg.p38356.b99.142.2757701addDjwM

<img width="747" alt="8.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/26f85ee0-c3b6-df38-2170-825f243ef607.jpeg">


```:DescribeEipAddresses
aliyun vpc DescribeEipAddresses | jq .
```

```:応答
{
	"PageNumber": 1,
	"EipAddresses": {
		"EipAddress": [
			{
				"BandwidthPackageBandwidth": "",
				"HasReservationData": false,
				"HDMonitorStatus": "OFF",
				"InstanceId": "",
				"ISP": "BGP",
				"InternetChargeType": "PayByTraffic",
				"BandwidthPackageType": "",
				"PrivateIpAddress": "",
				"SecondLimited": false,
				"Bandwidth": "1",
				"ChargeType": "PostPaid",
				"ResourceGroupId": "rg-XXXXXXXXXXXXXXX",
				"AllocationTime": "2019-05-11T13:31:40Z",
				"Descritpion": "",
				"IpAddress": "XXX.XXX.XXX.XXX",
				"AllocationId": "eip-XXXXXXXXXXXXXXXXXXXXX",
				"Mode": "NAT",
				"InstanceType": "",
				"Name": "",
				"Status": "Available",
				"InstanceRegionId": "",
				"BandwidthPackageId": "",
				"RegionId": "ap-northeast-1",
				"OperationLocks": {
					"LockReason": []
				},
				"AvailableRegions": {
					"AvailableRegion": [
						"ap-northeast-1"
					]
				},
				"ExpiredTime": ""
			}
		]
	},
	"TotalCount": 1,
	"PageSize": 10,
	"RequestId": "F175D5ED-AB55-4D48-8B13-97E318D97187"
}
```

**ポイント:**
この作成した EIP を使い画面を表示します

<img width="1439" alt="9.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/fceccdc6-06d9-ae47-d8ed-28433bf6800b.jpeg">



## 4. SecurityGroupの作成

### SecurityGroup とは？

同じセキュリティ要件と相互信頼を持つ同じリージョンのインスタンスをグループ化する論理グループ。
セキュリティの分離の重要な手段として、セキュリティグループは
クラウド上のセキュリティドメインを分割するために使用される。 

SecurityGroupのドキュメントはこちら

> https://jp.alibabacloud.com/help/doc-detail/25387.htm?spm=a21mg.p38356.b99.129.5dda2f99bpdh1N


#### 4-1.環境変数の設定

```:設定
VPC_ID=$( \
  aliyun vpc DescribeVpcs \
  --VpcName ${VPC_NAME} \
  | jq '.Vpcs.Vpc[].VpcId' \
  | sed 's/"//g'
)
ECS_SG_NAME="SG"
ECS_SG_DESC="Aliyun SG"
```

```:確認
cat << EOF

  VPC_ID="vpc-XXXXXXXXXXXXXXXXXXXXX"
  VPC_ID="${VPC_ID}"

  ECS_SG_NAME="SG"
  ECS_SG_NAME="${ECS_SG_NAME}"

  ECS_SG_DESC="Aliyun SG"
  ECS_SG_DESC="${ECS_SG_DESC}"

EOF
```

#### 4-2.SecurityGroupの作成

> https://jp.alibabacloud.com/help/doc-detail/25553.htm?spm=a21mg.l28256.b99.265.7fb958a7JwaeUe

<img width="745" alt="10.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/40c2a62e-a0b7-0bcd-0c45-99dc864a4f47.jpeg">


```:CreateSecurityGroup
aliyun ecs CreateSecurityGroup \
  --VpcId ${VPC_ID} \
  --SecurityGroupName ${ECS_SG_NAME} \
  --Description "${ECS_SG_DESC}" | jq .
```

```:応答
{
	"SecurityGroupId": "sg-XXXXXXXXXXXXXXXXXXXX",
	"RequestId": "B07D892F-0100-46CB-8F32-E1BB36552447"
}
```

#### 4-3.SecurityGroupの確認

> https://jp.alibabacloud.com/help/doc-detail/25556.htm?spm=a21mg.p38356.b99.274.13af1e909EgZVT

<img width="743" alt="11.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/9f4c4081-7876-96ab-fa7b-927d20262751.jpeg">


```:DescribeSecurityGroups
aliyun ecs DescribeSecurityGroups \
  --SecurityGroupName ${ECS_SG_NAME} | jq .
```

```:応答
{
	"PageNumber": 1,
	"TotalCount": 1,
	"PageSize": 10,
	"RegionId": "ap-northeast-1",
	"RequestId": "C99C9DB4-4A38-4989-B488-6826D5C8AC3D",
	"SecurityGroups": {
		"SecurityGroup": [
			{
				"CreationTime": "2019-05-11T13:44:08Z",
				"Tags": {
					"Tag": []
				},
				"SecurityGroupId": "sg-XXXXXXXXXXXXXXXXXXXX",
				"SecurityGroupName": "SG",
				"Description": "Aliyun SG",
				"ResourceGroupId": "",
				"SecurityGroupType": "normal",
				"VpcId": "vpc-XXXXXXXXXXXXXXXXXXXXX"
			}
		]
	}
}
```

<img width="1440" alt="12.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/f2f28b17-d040-920e-0bbd-816f9265dc73.jpeg">



## 5. SecurityGroupのルールの追加

#### 5-1.環境変数の設定

```:設定
SG_ID=$( \
  aliyun ecs DescribeSecurityGroups \
    --SecurityGroupName ${SG_GROUP_NAME} \
    | jq '.SecurityGroups.SecurityGroup[].SecurityGroupId' \
    | sed 's/"//g'
)
SG_DESC="Aliyun SG"
IP_PROTOCOL="tcp"
PORT_RANGE="80/80"
NIC_TYPE="intranet"
POLICY="accept"
DEST_CIDR_IP="0.0.0.0/0"
```

```:確認
cat << EOF

  SG_ID="sg-XXXXXXXXXXXXXXXXXXXX"
  SG_ID="${SG_ID}"

  SG_DESC="Aliyun SG"
  SG_DESC="${SG_DESC}"

  IP_PROTOCOL="tcp"
  IP_PROTOCOL="${IP_PROTOCOL}"

  PORT_RANGE="80/80"
  PORT_RANGE="${PORT_RANGE}"

  NIC_TYPE="intranet"
  NIC_TYPE="${NIC_TYPE}"

  POLICY="accept"
  POLICY="${POLICY}"

  DEST_CIDR_IP="0.0.0.0/0"
  DEST_CIDR_IP="${DEST_CIDR_IP}"

EOF
```

#### 5-2.SecurityGroupの受信ルール追加

> https://jp.alibabacloud.com/help/doc-detail/25554.htm?spm=a21mg.p38356.b99.266.71fc141cuulF0d

<img width="786" alt="13.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/0405640e-fd8c-9c88-cc1a-2d3988b45d10.jpeg">


```:AuthorizeSecurityGroup
aliyun ecs AuthorizeSecurityGroup \
  --SecurityGroupId ${SG_ID} \
  --Description "${SG_DESC}" \
  --IpProtocol ${IP_PROTOCOL} \
  --PortRange ${PORT_RANGE} \
  --NicType ${NIC_TYPE} \
  --Policy ${POLICY} \
  --SourceCidrIp ${DEST_CIDR_IP} | jq .
```

```:応答
{"RequestId": "BE7592D8-3FB2-4EED-B3DB-67637EE00DD7"}
```

#### 5-3.SecurityGroupのルール確認

> https://jp.alibabacloud.com/help/doc-detail/25555.htm?spm=a21mg.p38356.b99.273.666c30cfq8eIJP

<img width="795" alt="14.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/f7c538c2-b8aa-681a-89ba-fcb75a41c963.jpeg">


```:DescribeSecurityGroupAttribute
aliyun ecs DescribeSecurityGroupAttribute \
  --SecurityGroupId ${SG_ID} | jq .
```

```:応答
{
	"SecurityGroupId": "sg-XXXXXXXXXXXXXXXXXXXX",
	"InnerAccessPolicy": "Accept",
	"SecurityGroupName": "SG",
	"Description": "Aliyun SG",
	"RegionId": "ap-northeast-1",
	"RequestId": "BE7592D8-3FB2-4EED-B3DB-67637EE00DD7",
	"Permissions": {
		"Permission": [
			{
				"SourceCidrIp": "0.0.0.0/0",
				"Description": "Aliyun SG",
				"DestCidrIp": "",
				"NicType": "intranet",
				"DestGroupName": "",
				"PortRange": "80/80",
				"DestGroupId": "",
				"Ipv6DestCidrIp": "",
				"Direction": "ingress",
				"Priority": 1,
				"IpProtocol": "TCP",
				"SourcePortRange": "",
				"SourceGroupOwnerAccount": "",
				"Policy": "Accept",
				"CreateTime": "2019-05-11T13:54:06Z",
				"SourceGroupId": "",
				"DestGroupOwnerAccount": "",
				"Ipv6SourceCidrIp": "",
				"SourceGroupName": ""
			}
		]
	},
	"VpcId": "vpc-XXXXXXXXXXXXXXXXXXXXX"
}
```

<img width="1440" alt="15.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/5b053e24-d19a-c49f-77a3-4a8b39b05b41.jpeg">



## 6. Instance(ECS)の作成

### ECS とは？

ECS インスタンスは、CPU、メモリ、およびその他の基本的な
コンピューティングコンポーネントを含む仮想コンピューティング環境。

ECSのドキュメントはこちら

> https://jp.alibabacloud.com/help/doc-detail/25367.htm?spm=a21mg.l28256.a3.2.3da858a7KBNJv4


#### 6-1:a. データの用意

> <font color=red>今回は事前に Apache を起動する UserData を[Base64]にエンコードしたものを用意しました。</font>

UserDataを用いる場合は公式で「平文のまま送信する」ことを推奨していないためです。

<img width="904" alt="UserData.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/cf83d184-927a-0dd1-f06e-7d1e46f8cd44.jpeg">


**元データは以下の通りです。**

```:Data
#!/bin/sh
yum install -y httpd
systemctl start httpd
systemctl enable httpd
```

#### 6-1:b. 環境変数の設定

```:設定
INSTANCE_NAME="INSTANCE"
ECS_DESC="Alicloud CLI INSTANCE"
ZONE_ID="ap-northeast-1a"

VSWITCH_ID=$( \
  aliyun ecs DescribeVSwitches \
    --VpcId ${VPC_ID} \
    | jq ".VSwitches.VSwitch[].VSwitchId" \
    | sed 's/"//g'
)
SG_ID=$( \
  aliyun ecs DescribeSecurityGroups \
    --SecurityGroupName ${SG_GROUP_NAME} \
    | jq '.SecurityGroups.SecurityGroup[].SecurityGroupId' \
    | sed 's/"//g'
)

IMAGE_ID="alinux_17_01_64_20G_cloudinit_20171222.vhd"
INSTANCE_TYPE="ecs.n4.small"
INTERNET_CHARGE_TYPE="PayByTraffic"
INSTANCE_CHARGE_TYPE="PostPaid"

SYSTEM_DISK_CATEGORY="cloud_efficiency"
SYSTEM_DISK_SIZE=40
SYSTEM_DISK_NAME="SYS_DISK"
SYSTEM_DISK_DESC="AliCloud CLI System Disk"

USER_DATA="IyEvYmluL3NoDQp5dW0gaW5zdGFsbCAteSBodHRwZA0Kc3lzdGVtY3RsIHN0YXJ0IGh0dHBkDQpzeXN0ZW1jdGwgZW5hYmxlIGh0dHBk"
```

```:確認
cat << EOF

  INSTANCE_NAME="INSTANCE"
  INSTANCE_NAME="${INSTANCE_NAME}"

  ECS_DESC="Alicloud CLI INSTANCE"
  ECS_DESC="${ECS_DESC}"

  ZONE_ID="ap-northeast-1a"
  ZONE_ID="${ZONE_ID}"

  VSWITCH_ID="vsw-XXXXXXXXXXXXXXXXXXXXX"
  VSWITCH_ID="${VSWITCH_ID}"

  SG_ID="sg-XXXXXXXXXXXXXXXXXXXX"
  SG_ID="${SG_ID}"

  IMAGE_ID="alinux_17_01_64_20G_cloudinit_20171222.vhd"
  IMAGE_ID="${IMAGE_ID}"

  INSTANCE_TYPE="ecs.n4.small"
  INSTANCE_TYPE="${INSTANCE_TYPE}"

  INTERNET_CHARGE_TYPE="PayByTraffic"
  INTERNET_CHARGE_TYPE="${INTERNET_CHARGE_TYPE}"

  INSTANCE_CHARGE_TYPE="PostPaid"
  INSTANCE_CHARGE_TYPE="${INSTANCE_CHARGE_TYPE}"

  SYSTEM_DISK_CATEGORY="cloud_efficiency"
  SYSTEM_DISK_CATEGORY="${SYSTEM_DISK_CATEGORY}"

  SYSTEM_DISK_SIZE=40
  SYSTEM_DISK_SIZE=${SYSTEM_DISK_SIZE}

  SYSTEM_DISK_NAME="SYS_DISK"
  SYSTEM_DISK_NAME="${SYSTEM_DISK_NAME}"

  SYSTEM_DISK_DESC="AliCloud CLI System Disk"
  SYSTEM_DISK_DESC="${SYSTEM_DISK_DESC}"

  USER_DATA="IyEvYmluL3NoDQp5dW0gaW5zdGFsbCAteSBodHRwZA0Kc3lzdGVtY3RsIHN0YXJ0IGh0dHBkDQpzeXN0ZW1jdGwgZW5hYmxlIGh0dHBk"
  USER_DATA="${USER_DATA}"

EOF
```

#### 6-2. Instanceの作成

> https://jp.alibabacloud.com/help/doc-detail/25499.htm?spm=a21mg.p38356.b99.203.3ffa1cc86ZS4x6

<img width="733" alt="16.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/9d8d889c-298c-5bfe-ab22-d8c908d31b78.jpeg">


```:CreateInstance
aliyun ecs CreateInstance \
  --InstanceName ${INSTANCE_NAME} \
  --Description "${ECS_DESC}" \
  --ZoneId ${ZONE_ID} \
  --VSwitchId ${VSWITCH_ID} \
  --SecurityGroupId ${SG_ID} \
  --ImageId ${IMAGE_ID} \
  --InstanceType ${INSTANCE_TYPE} \
  --InternetChargeType ${INTERNET_CHARGE_TYPE} \
  --SystemDisk.Category ${SYSTEM_DISK_CATEGORY} \
  --SystemDisk.Size ${SYSTEM_DISK_SIZE} \
  --SystemDisk.DiskName ${SYSTEM_DISK_NAME} \
  --SystemDisk.Description "${SYSTEM_DISK_DESC}" \
  --UserData ${USER_DATA} | jq .
```

```:応答
{
	"InstanceId": "i-XXXXXXXXXXXXXXXXXXXX",
	"RequestId": "673749DF-E556-4081-9CDA-A5EEE50CF51D"
}
```

#### 6-3. Instanceの確認

> https://jp.alibabacloud.com/help/doc-detail/25507.htm?spm=a21mg.p38356.b99.207.455f27e06fvYvv

<img width="768" alt="17.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/533be1a0-cfda-6603-a27b-836f0ec0e297.jpeg">


```:DescribeInstances
aliyun ecs DescribeInstances \
  --InstanceName ${INSTANCE_NAME} | jq .
```

```:応答
{
	"PageNumber": 1,
	"TotalCount": 1,
	"PageSize": 10,
	"RequestId": "75DEBB7E-28E4-4C02-831F-5A9FABE51C79",
	"Instances": {
		"Instance": [
			{
				"ImageId": "alinux_17_01_64_20G_cloudinit_20171222.vhd",
				"VlanId": "",
				"EipAddress": {
					"IpAddress": "",
					"AllocationId": "",
					"InternetChargeType": ""
				},
				"ZoneId": "ap-northeast-1a",
				"IoOptimized": true,
				"SerialNumber": "65658306-2fe9-4fb5-a8f8-8590981cecb4",
				"Cpu": 1,
				"Memory": 2048,
				"DeviceAvailable": true,
				"SecurityGroupIds": {
					"SecurityGroupId": [
						"sg-XXXXXXXXXXXXXXXXXXXX"
					]
				},
				"SaleCycle": "",
				"AutoReleaseTime": "",
				"ResourceGroupId": "",
				"OSType": "linux",
				"OSName": "Aliyun Linux  17.1 64位",
				"InstanceNetworkType": "vpc",
				"HostName": "iZ6we5c4xroi7inustzcxzZ",
				"CreationTime": "2019-05-11T14:05Z",
				"EcsCapacityReservationAttr": {
					"CapacityReservationPreference": "",
					"CapacityReservationId": ""
				},
				"RegionId": "ap-northeast-1",
				"DeletionProtection": false,
				"OperationLocks": {
					"LockReason": []
				},
				"ExpiredTime": "2099-12-31T15:59Z",
				"InnerIpAddress": {
					"IpAddress": []
				},
				"InstanceTypeFamily": "ecs.n4",
				"InstanceId": "i-XXXXXXXXXXXXXXXXXXXX",
				"NetworkInterfaces": {
					"NetworkInterface": [
						{
							"MacAddress": "00:16:3e:00:40:9d",
							"PrimaryIpAddress": "172.16.1.11",
							"NetworkInterfaceId": "eni-XXXXXXXXXXXXXXXX"
						}
					]
				},
				"InternetMaxBandwidthIn": 0,
				"CreditSpecification": "",
				"InternetChargeType": "PayByTraffic",
				"SpotStrategy": "NoSpot",
				"StoppedMode": "KeepCharging",
				"InternetMaxBandwidthOut": 0,
				"VpcAttributes": {
					"NatIpAddress": "",
					"PrivateIpAddress": {
						"IpAddress": [
							"172.16.1.11"
						]
					},
					"VSwitchId": "vsw-XXXXXXXXXXXXXXXXXXXXX",
					"VpcId": "vpc-XXXXXXXXXXXXXXXXXXXXX"
				},
				"SpotPriceLimit": 0,
				"StartTime": "2019-05-11T14:05Z",
				"InstanceName": "INSTANCE",
				"Description": "Alicloud CLI INSTANCE",
				"OSNameEn": "Aliyun Linux 17.1 64 bit",
				"PublicIpAddress": {
					"IpAddress": []
				},
				"InstanceType": "ecs.n4.small",
				"Status": "Stopped",
				"Recyclable": false,
				"ClusterId": "",
				"GPUSpec": "",
				"InstanceChargeType": "PostPaid",
				"GPUAmount": 0,
				"DedicatedHostAttribute": {
					"DedicatedHostId": "",
					"DedicatedHostName": ""
				},
				"DedicatedInstanceAttribute": {
					"Affinity": "",
					"Tenancy": ""
				},
				"DeploymentSetId": ""
			}
		]
	}
}
```

<img width="1440" alt="18.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/d19146de-1fe8-d676-fc8a-00d9f67722bd.jpeg">


> **ポイント:**
この作業はあくまで作成です。
<font color=red>起動はしていません</font>



## 7. InstanceとEIPの紐付け

#### 7-1.環境変数の設定

```:設定
EIP_ID=$( \
  aliyun vpc DescribeEipAddresses \
    --RegionId ${REGION_ID} \
    | jq ".EipAddresses.EipAddress[].AllocationId" \
    | sed 's/"//g'
)
INSTANCE_ID=$( \
  aliyun ecs DescribeInstances \
    --InstanceName ${INSTANCE_NAME} \
    | jq ".Instances.Instance[].InstanceId" \
    | sed 's/"//g'
)
INSTANCE_TYPE="EcsInstance"
REGION_ID="ap-northeast-1"
```

```:確認
cat << EOF

  EIP_ID="eip-XXXXXXXXXXXXXXXXXXXXX"
  EIP_ID="${EIP_ID}"

  INSTANCE_ID="i-XXXXXXXXXXXXXXXXXXXX"
  INSTANCE_ID="${INSTANCE_ID}"

  INSTANCE_TYPE="EcsInstance"
  INSTANCE_TYPE="${INSTANCE_TYPE}"

EOF
```

#### 7-2. InstanceとEIPの紐付け

> https://jp.alibabacloud.com/help/doc-detail/36016.htm?spm=a21mg.p38356.a3.1.4efb47a6avi26i

<img width="791" alt="19.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/b86d2837-932d-7aff-675c-7017cd3cc1a7.jpeg">


```:AssociateEipAddress
aliyun vpc AssociateEipAddress \
  --AllocationId ${EIP_ID} \
  --InstanceId ${INSTANCE_ID} \
  --InstanceType ${INSTANCE_TYPE} | jq .
```

```:応答
{"RequestId":"67EA281F-4167-4541-8047-51F219EC3AED"}
```

#### 7-3. 紐付けの確認

<img width="782" alt="20.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/c15b3c37-c96e-7ce8-351e-baeb07745069.jpeg">

```:DescribeInstances
aliyun vpc DescribeEipAddresses \
  --RegionId ${REGIO_ID} \
  --AssociatedInstanceId ${INSTANCE_ID} \
  --AssociatedInstanceType ${INSTANCE_TYPE} \
  | jq ".EipAddresses.EipAddress[].InstanceId" \
  | sed 's/"//g'
```

```:応答
i-XXXXXXXXXXXXXXXXXXXX
```

<img width="1440" alt="21.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/2592877a-1b67-e27a-5494-e3db8e777ddc.jpeg">



## 8. インスタンスの起動

#### 8-1.環境変数の設定

```:設定
INSTANCE_ID=$( \
  aliyun ecs DescribeInstances \
    --InstanceName ${INSTANCE_NAME} \
    | jq ".Instances.Instance[].InstanceId" \
    | sed 's/"//g'
)
REGION_ID="ap-northeast-1"
```

```:確認
cat << EOF

  INSTANCE_ID="i-XXXXXXXXXXXXXXXXXXXX"
  INSTANCE_ID="${INSTANCE_ID}"

EOF
```

#### 8-2. Instanceの起動

> https://jp.alibabacloud.com/help/doc-detail/25500.htm?spm=a21mg.p38356.b99.204.3c6f3fd6lNLbeK

<img width="739" alt="22.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/508d23eb-cdca-b956-c79a-e4e64408857f.jpeg">


```:StartInstance
aliyun ecs StartInstance \
  --InstanceId ${INSTANCE_ID} | jq .
```

```:応答
{"RequestId":"1A4A6334-19AE-45C8-B40B-33FA4A37128B"}
```

#### 8-3. 起動確認

> ##### DescribeInstanceStatusを使ってみる!!!

> https://jp.alibabacloud.com/help/doc-detail/25505.htm?spm=a21mg.p38356.b99.208.33d03f354G0NCX

<img width="745" alt="23.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/f12de87d-a19c-06e0-b792-877b5d5c90fd.jpeg">

```:DescribeInstanceStatus
aliyun ecs DescribeInstanceStatus \
  | jq ".InstanceStatuses.InstanceStatus[].Status" \
  | sed 's/"//g'
```

```:応答
Running

(確認が早いと)
Starting
```

<img width="1440" alt="24.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/c9fd9c04-0cc5-b26a-0790-f679b2a1ee6b.jpeg">


> ちなみに今回はインスタンスの作成・起動を別々で分けましたが、
<font color=red> [ RunInstance ]のコマンドを使えば作成・起動を同時にできます。 </font>

> https://jp.alibabacloud.com/help/doc-detail/63440.htm?spm=a21mg.p38356.b99.202.29aad8b3v47zUd




## 9. 画面確認

最後にサービスが確かに動いていることを確認しましょう。

#### 9-1.環境変数の設定

```:設定
ACCESS_EIP=$( \
  aliyun ecs DescribeInstances \
    --InstanceName ${INSTANCE_NAME} \
    | jq ".Instances.Instance[].EipAddress.IpAddress" \
    | sed 's/"//g'
)
REGION_ID="ap-northeast-1"
```

```:確認
cat << EOF

  ACCESS_EIP="XXX.XXX.XXX.XXX"
  ACCESS_EIP="${ACCESS_EIP}"

EOF
```

#### 9-2. curlで確認

```:curl
curl http://${ACCESS_EIP}
```

```:応答
<!DOCTYPE html PUBLIC ...><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Apache HTTP Server Test Page powered by Alinux</title>
<body>
<p>Hello Apache</p>
</body></html>
```

> <font color=red> **Instance が動いていることを確認できました！！** </font>


#### 9-2:おまけ. ブラウザでも確認

```:DescribeInstances
aliyun ecs DescribeInstances \
  --InstanceName ${INSTANCE_NAME} \
  | jq ".Instances.Instance[].EipAddress.IpAddress" \
  | sed 's/"//g'
```

```:応答
xxx.xxx.xxx.xxx
```

と表示されるので、この[xxx.xxx.xxx.xxx]にアクセスすれば

<img width="522" alt="25.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/5bb92eed-54f9-b8cf-2456-4a798b715aeb.jpeg">


このように表示されます。



## 10.後片付け

最後はしっかり環境を片付けましょう。
アクセスする以外にも、ECSが起動していることで<font color="red">お金がかかります</font>。

ECS は Instance 停止をしていれば課金されないようにも設定できますが、基本的に使い終わったら削除しましょう。

#### 10-1.環境変数の設定

```:設定
VPC_ID=$( \
  aliyun vpc DescribeVpcs \
    --VpcName ${VPC_NAME} \
    | jq '.Vpcs.Vpc[].VpcId' \
    | sed 's/"//g'
)
VSWITCH_ID=$( \
  aliyun vpc DescribeVSwitches \
    --VSwitchName ${VSWITCH_NAME} \
    | jq '.VSwitches.VSwitch[].VSwitchId' \
    | sed 's/"//g'
)
EIP_ID=$( \
  aliyun vpc DescribeEipAddresses \
    --RegionId ${REGION_ID} \
    | jq ".EipAddresses.EipAddress[].AllocationId" \
    | sed 's/"//g'
)
SG_ID=$( \
  aliyun ecs DescribeSecurityGroups \
    --SecurityGroupName ${SG_GROUP_NAME} \
    | jq '.SecurityGroups.SecurityGroup[].SecurityGroupId' \
    | sed 's/"//g'
)
INSTANCE_ID=$( \
  aliyun ecs DescribeInstances \
    --InstanceName ${INSTANCE_NAME} \
    | jq ".Instances.Instance[].InstanceId" \
    | sed 's/"//g'
)
VPC_CIDR_BLOCK="172.16.0.0/16"
REGION_ID="ap-northeast-1"
```

```:確認
cat << EOF

  VPC_ID="vpc-XXXXXXXXXXXXXXXXXXXXX"
  VPC_ID="${VPC_ID}"

  VSWITCH_ID="vsw-XXXXXXXXXXXXXXXXXXXXX"
  VSWITCH_ID="${VSWITCH_ID}"

  EIP_ID="eip-XXXXXXXXXXXXXXXXXXXXX"
  EIP_ID="${EIP_ID}"

  SG_ID="sg-XXXXXXXXXXXXXXXXXXXX"
  SG_ID="${SG_ID}"

  INSTANCE_ID="i-XXXXXXXXXXXXXXXXXXXX"
  INSTANCE_ID="${INSTANCE_ID}"

  DEST_CIDR_IP="0.0.0.0/0"
  DEST_CIDR_IP="${DEST_CIDR_IP}"

EOF
```

#### 10-2:a. Instanceの停止

> <font color=red>まずは停止</font>

> https://jp.alibabacloud.com/help/doc-detail/25501.htm?spm=a21mg.p38356.b99.205.455f27e06fvYvv

<img width="714" alt="26.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/e7a848d2-c820-702d-d816-fa53f5286be3.jpeg">


```:StopInstance
aliyun ecs StopInstance \
  --InstanceId ${INSTANCE_ID} | jq .
```

```:応答
{"RequestId":"9B34901C-5E04-4FA1-BE91-FDDD20A99EB5"}
```

#### 10-2:b. Instanceの確認

```:DescribeInstanceStatus
aliyun ecs DescribeInstanceStatus \
  | jq ".InstanceStatuses.InstanceStatus[].Status" \
  | sed 's/"//g'
```

```:応答
Stopped
```

<img width="1440" alt="28.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/e96ee552-961b-e244-0586-5b8cf0214d22.jpeg">

> **ポイント**
<font color=red>停止したのを確認してから削除</font>



#### 10-2:c. Instanceの削除

> https://jp.alibabacloud.com/help/doc-detail/25507.htm?spm=a21mg.p38356.b99.207.19f41b84kDElB8

<img width="707" alt="27.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/4594bc9a-a701-9f19-1fe2-3282615260ba.jpeg">


```:DeleteInstance
aliyun ecs DeleteInstance \
  --InstanceId ${INSTANCE_ID} | jq .
```

```:応答
{"RequestId":"9AEBAD7F-3C80-4C8E-8C55-2465046D12BD"}
```

#### 10-2:d. Instanceの確認

```:DescribeInstances
aliyun ecs DescribeInstances \
  --InstanceName ${INSTANCE_NAME} \
  | jq ".Instances.Instance[]" | jq .
```

```:応答
何もなければOK!!
```

<img width="1440" alt="29.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/32ae8010-fb46-4660-6e70-e1b99adfb467.jpeg">


----------------------

#### 10-3:a SecurityGroupの受信ルール削除

> https://jp.alibabacloud.com/help/doc-detail/25557.htm?spm=a21mg.p38356.b99.268.4a583070IRAjNC

<img width="786" alt="31.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/10c17fd3-0235-38b9-1ffd-77913fa45012.jpeg">


```:RevokeSecurityGroup
aliyun ecs RevokeSecurityGroup \
  --SecurityGroupId ${SG_ID} \
  --PortRange ${PORT_RANGE} \
  --IpProtocol ${IP_PROTOCOL} \
  --SourceCidrIp "${DEST_CIDR_IP}" | jq .
```

```:応答
{"RequestId":"564ACC57-0AB9-477C-B81C-7ACA2AC69855"}
```

<img width="1440" alt="32.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/2f461448-7c28-3493-6d59-dc87a4cd5e91.jpeg">

> **ポイント**
<font color=red>RevokeSecurityGroup の場合、Source(VPC)関連の
情報が( Optional 設定なのに)ないとエラーが起こるので注意。</font>



#### 10-3:b SecurityGroupのルール確認

```:DescribeSecurityGroupAttribute
aliyun ecs DescribeSecurityGroupAttribute \
  --SecurityGroupId ${SG_ID}  | jq .
```

```:応答
何もなければOK!!
```

#### 10-3:a SecurityGroupの削除

> https://jp.alibabacloud.com/help/doc-detail/25558.htm?spm=a21mg.p38356.b99.272.7ffd20288rU02Z

<img width="776" alt="30.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/9b1affef-2e78-747e-65fd-f6da3f463840.jpeg">

```:DeleteSecurityGroup
aliyun ecs DeleteSecurityGroup \
  --SecurityGroupId ${SG_ID} | jq .
```

```:応答
{"RequestId":"C58C700E-E667-422A-8CAC-E34D9F997268"}
```

#### 10-3:b SecurityGroupの確認

```:DescribeSecurityGroups
aliyun ecs DescribeSecurityGroups \
  --SecurityGroupId ${SG_ID} \
  | jq ".SecurityGroups.SecurityGroup[]"
```

```:応答
何もなければOK!!
```

<img width="1440" alt="33.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/0debdd73-df14-4653-d188-c2053217333c.jpeg">


----------------------

#### 10-4:a. EIPのリリース

> https://jp.alibabacloud.com/help/doc-detail/36020.htm?spm=a21mg.p38356.b99.140.58762e52nOrG31

<img width="751" alt="34.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/81d33e21-aa3e-0c7e-7b7d-be1c0d258e98.jpeg">


```:ReleaseEipAddress
aliyun vpc ReleaseEipAddress \
  --AllocationId ${EIP_ID} | jq .
```

```:応答
{"RequestId":"7EC283AE-874E-41AD-B18C-97D7B464FB75"}
```

#### 10-4:b. EIPの確認

```:DescribeEipAddresses
aliyun vpc DescribeEipAddresses \
  --AllocationId ${EIP_ID} \
  | jq ".EipAddresses.EipAddress[]"
```

```:応答
何もなければOK!!
```

<img width="1440" alt="35.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/d7f0a286-4c8b-b6dc-142a-c2574636a5bb.jpeg">



----------------------

#### 10-5:a. VSwitchの削除

> https://jp.alibabacloud.com/help/doc-detail/35746.htm?spm=a21mg.p38356.b99.61.7fc758c1ochqJr

<img width="711" alt="36.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/abf40117-80b8-1707-562d-14f1399d2a5a.jpeg">


```:DeleteVSwitch
aliyun vpc DeleteVSwitch \
  --VSwitchId ${VSWITCH_ID} | jq .
```

```:応答
{"RequestId":"1CD83405-2DAA-4D13-9A8A-154426C4B8A8"}
```

#### 10-5:b. VSwitchの確認

```:DescribeVSwitches
aliyun vpc DescribeVSwitches \
  --VSwitchName ${VSWITCH_NAME} \
  | jq ".VSwitches.VSwitch[]"
```

```:応答
何もなければOK!!
```

<img width="1440" alt="37.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/7a6f0bc1-e91e-63a3-62b1-2d9ed5b878b3.jpeg">


----------------------

#### 10-6:a. VPCの削除

> https://jp.alibabacloud.com/help/doc-detail/35738.htm?spm=a21mg.p38356.b99.56.2556457bwGZ64s

<img width="724" alt="38.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/65bb3d8d-4826-9b49-f435-8a213efa2442.jpeg">


```:DeleteVpc
aliyun vpc DeleteVpc \
  --VpcId ${VPC_ID} | jq .
```

```:応答
{"RequestId":"42A57098-1027-4D92-B262-408207F4750C"}
```

#### 10-6:b. VPCの確認

```:DescribeVpcs
aliyun vpc DescribeVpcs \
  --VpcName ${VPC_NAME} \
  | jq ".Vpcs.Vpc[]"
```

```:応答
何もなければOK!!
```

<img width="1440" alt="39.jpg" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/161922/f7cd7d22-3596-7489-9594-a080a2917335.jpeg">


----------------------


<font color=red> **作業は以上になります。お疲れ様でした！！** </font>