2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AWSハンズオン実践】AWS 環境のコード管理 AWS CloudFormationで Web システムを構築する

2
Last updated at Posted at 2025-08-23

1. ハンズオン内容

image.png

  • 図には EC2 と RDS が2台ずつ描かれていますが、実際に作成するのは 各1台のみ です。なぜ図が2台構成なのかは不明です。
  • ハンズオンではリソースを段階的に作成していきます。

※Cloud9 環境は VSCode + PowerShell で代用可能
※画像は AWS 公式ページより引用

1.1. 前提条件&注意事項

  • このブログだけでは進められません。AWS公式ハンズオン動画をまず見てください。
  • これらの導入が必要になると思われます。
  • 一部課金が発生します(数十円程度)。終了後は必ず削除しましょう。
  • 親ページ見てない人は見てね

1.2. CloudFormation テンプレート

こちらのリポジトリにある修正版テンプレートを使用してください。公式のテンプレートのまま使うと動きません。またコードにコメント入れています。

2. (Step1)VPC作成

image.png

VPC、サブネット、AZ、インターネットゲートウェイを作成します。
※画像はハンズオンより引用

2.1 (Step1)スタック作成コマンド

cd cfn

# validate
aws cloudformation validate-template --template-body file://01_vpc.yml

# create
aws cloudformation create-stack --stack-name handson-cfn --template-body file://01_vpc.yml

# update
aws cloudformation update-stack --stack-name handson-cfn --template-body file://01_vpc.yml

3. (Step2)EC2作成

image.png

EC2 を1台作成します。
用意しているテンプレートはハンズオンでの最終形の構成です。
サブネットIDや VPCID は VPC スタックでエクスポートした値を利用します。
※画像はハンズオンより引用

3.1 (Step2)スタック作成コマンド

cd cfn

### validate
aws cloudformation validate-template --template-body file://02_ec2.yml

### create
aws cloudformation create-stack --stack-name handson-cfn-ec2 --template-body file://02_ec2.yml

### update
aws cloudformation update-stack --stack-name handson-cfn-ec2 --template-body file://02_ec2.yml

### delete(ハンズオンには記載なし)
aws cloudformation delete-stack --stack-name handson-cfn-ec2

3.1. (Step2)CloudFormation マニュアル参照について

  • AWS 公式マニュアル(例: AWS::EC2::Instance)は、日本語設定にしても 英語で表示されることがあります
  • 理由は「日本語翻訳が一部リソースに追いついていない」ためです。特に CloudFormation のリソースリファレンスは、英語優先で提供されています。
  • ページ上部の言語切替で 日本語 を選んでも翻訳されない部分は仕様です。

4. (Step3)RDS作成

image.png

RDS を 1 台作成します。
テンプレートでは db.t2.micro が指定されていますが、このクラスは利用できずエラーになるため、db.t3.micro に修正して使用します。テンプレートは修正済みです。

4.1 (Step3)スタック作成コマンド

cd cfn

### validate
aws cloudformation validate-template --template-body file://03_rds.yml

### create
aws cloudformation create-stack --stack-name handson-cfn-rds --template-body file://03_rds.yml

### update
aws cloudformation update-stack --stack-name handson-cfn-rds --template-body file://03_rds.yml

### delete(ハンズオンには記載なし)
aws cloudformation delete-stack --stack-name handson-cfn-rds

5. (Step4)ELB作成

image.png

ELB を 1 台作成します。

5.1 (Step4)スタック作成コマンド

cd cfn

### validate
aws cloudformation validate-template --template-body file://04_elb.yml

### create
aws cloudformation create-stack --stack-name handson-cfn-elb --template-body file://04_elb.yml

### update
aws cloudformation update-stack --stack-name handson-cfn-elb --template-body file://04_elb.yml

### delete(ハンズオンには記載なし)
aws cloudformation delete-stack --stack-name handson-cfn-elb

6. (Step5)動作確認

ELB の URL (FrontLBEndpoint)にアクセスしましょう。

image.png

WordPressの画面が出力されれば成功です。この後の設定は必要ないと思います。
image.png

7. (Step6)スタック削除

削除は以下の順番で実行します。
ELB → RDS → EC2 → VPC


8. さいごに。感想とか

  • スタック作成に失敗した場合は、更新ではなく削除して再作成が必要
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?