orenoblog

エンジニアになりたいExcel方眼紙erの物語

[CDP] Stampパターンを試す

今更ながらCDP基礎勉強中です。

Stampパターンを試してみました。

いつものGUIポチーをやめてCLIで実行しました。

1. ベースAMIの起動

巣のAmazon Linuxを起動し、ベースパッケージとしてhttpdをインストールします。

client$ aws ec2 run-instances --image-id=ami-0d13700c ¥
--security-groups=default --key-name=MyAWS ¥
--instance-type=t1.micro
client $ aws ec2 describe-instances --instance-id i-0e951a09| ¥
jq '.Reservations[].Instances[]|{InstanceId, PublicDnsName}'
{
  "PublicDnsName": "ec2-54-248-130-213.ap-northeast-1.compute.amazonaws.com",
  "InstanceId": "i-0e951a09"
}
client$ ssh -i myaws.pem ec2-user@<PublicDnsName>
target$ sudo yum install -y httpd
target$ sudo chkconfig httpd on

2. イメージの作成

起動中のInstanceからAMIを作成します。 --no-rebootオプションを指定することで再起動せずにAMIを作成できますが、 ファイルシステムキャッシュがフラッシュされていないので、作成タイミングによっては 起動できるAMIではないかもしれません。

client$ aws ec2 create-image --instance-id i-0e951a09 --no-reboot --name baseami
{
    "ImageId": "ami-ef640cee"
}
client$ aws ec2 describe-images --image-id ami-ef640cee | ¥
jq '.Images[]|{Name,ImageId}'
{
  "ImageId": "ami-ef640cee",
  "Name": "baseami"
}

3. 起動したイメージの起動と確認

2台起動してみます。 httpdがインストールされており、自動起動が有効になっていたらOKです。

client$ aws ec2 run-instances --image-id=ami-ef640cee --security-groups=default --key-name=MyAWS --instance-type=t1.micro --count=2
client$ aws ec2 describe-instances | \
jq '.Reservations[].Instances[]|{InstanceId, PublicDnsName,ImageId:"ami-ef640cee"'
client$ ssh -i myaws.pem ec2-user@<PublicDnsName> "ps aux |grep httpd"
client$ ssh -i myaws.pem ec2-user@ec2-54-238-2-192.ap-northeast-1.compute.amazonaws.com "ps aux |grep httpd"
root      1223  0.0  0.6 178180  4088 ?        Ss   13:04   0:00 /usr/sbin/httpd
apache    1226  0.0  0.3 178316  2432 ?        S    13:04   0:00 /usr/sbin/httpd
apache    1227  0.0  0.3 178316  2432 ?        S    13:04   0:00 /usr/sbin/httpd
apache    1229  0.0  0.3 178316  2432 ?        S    13:04   0:00 /usr/sbin/httpd
apache    1230  0.0  0.3 178316  2432 ?        S    13:04   0:00 /usr/sbin/httpd
apache    1231  0.0  0.3 178316  2432 ?        S    13:04   0:00 /usr/sbin/httpd
apache    1232  0.0  0.3 178316  2432 ?        S    13:04   0:00 /usr/sbin/httpd
apache    1234  0.0  0.3 178316  2432 ?        S    13:04   0:00 /usr/sbin/httpd
apache    1235  0.0  0.3 178316  2432 ?        S    13:04   0:00 /usr/sbin/httpd
ec2-user  1358  0.0  0.2 108200  1512 ?        Ss   13:11   0:00 bash -c ps aux |grep httpd
ec2-user  1368  0.0  0.1 107644   892 ?        S    13:11   0:00 grep httpd

こんなところ。