0
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?

CloudFormationによるインフラ構築 EC2とRDSをテンプレートで作成する

0
Posted at

CloudFormationを利用すると
AWSインフラをコードで自動構築できます。

この記事では次の構成をCloudFormationで作成します。

  • パブリックサブネットにEC2
  • プライベートサブネットにRDS

また、作成したテンプレートを
Gitで管理する方法も紹介します。


① 構築するインフラ構成

今回作成する構成は次の通りです。

VPC
├─ Public Subnet
│ └ EC2

└─ Private Subnet
└ RDS

この構成により

  • Webサーバー → EC2
  • データベース → RDS

という一般的なアーキテクチャを作成できます。


② CloudFormationテンプレート作成

テンプレート例

Resources:

  MyEC2:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      ImageId: ami-xxxxxxxx

  MyRDS:
    Type: AWS::RDS::DBInstance
    Properties:
      DBInstanceClass: db.t3.micro
      Engine: mysql

テンプレートでは

EC2

RDS

などのリソースを定義します。

③ CloudFormationスタック作成

テンプレートを作成したら
CloudFormationでスタックを作成します。

手順

AWSコンソール

CloudFormation

スタック作成

テンプレート指定

すると

テンプレート

CloudFormation

EC2 + RDS作成

という流れでインフラが構築されます。

④ Gitへのpush(まとめ)

CloudFormationテンプレートは
Gitで管理することで変更履歴を管理できます。

基本的なGit操作

git init
git add template.yaml
git commit -m "add cloudformation template"
git push origin main

まとめ

CloudFormationを利用することで

AWSインフラをコードで自動構築することが可能です。

主なポイントは次の通りです。

CloudFormationテンプレートでインフラ構成を定義する

EC2やRDSなどのリソースを自動作成できる

スタックとして環境を管理できる

テンプレートはGitでバージョン管理できる

CloudFormationとGitを組み合わせることで
再現性の高いインフラ環境を構築できます。

0
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
0
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?