LoginSignup
0
2

More than 3 years have passed since last update.

AWS EC2のWindowsをCloudFormationを使ってミニマム構築

Posted at

はじめに

AWS CloudFormation を使い Windows EC2 を構築します。他の記事で応用テクニックはいっぱいあるのですが、どれが基本的な部分なのか分からず苦労しました。今回は初心者向けのミニマム構築を紹介します。

以前書いた記事
AWS EC2のWindowsかんたん構築手順 - Qiita

用語解説

  • CloudFormation
    AWSを構築するスクリプトです。Windowsでコマンドをまとめたバッチファイルみたいなものです。
  • スタック
    実行するたびに新しいスタックが作成されます。結果は残り続けます。
  • テンプレート
    スクリプトのことです。
  • YAML
    JSONとYAMLを選べます。YAMLはPythonチックな文法で改行とインデントを使います。 JSONのカッコとダブルクオートが無くなり便利です(今回初めて使いました)

テンプレートの作成

AWS CloudFormation [スタックの作成] [テンプレートを作成] を開きます。
言語をYAMLに切り替えます。

template1
AWSTemplateFormatVersion: '2010-09-09'
Description: This CloudFormation template to create EC2 instances.

Parameters:
  AmiId:
    Type: String
    Default: ami-xxxx
  SubnetId:
    Type: AWS::EC2::Subnet::Id
    Default: subnet-xxxx
  SecurityGroupId: 
    Type: AWS::EC2::SecurityGroup::Id
    Default: sg-xxxx
  KeyName:
    Type: AWS::EC2::KeyPair::KeyName
    Default: Key
  TagName:
    Type: String
    Default: CloudFormation-EC2

Resources:
  Ec2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.small
      ImageId: !Ref AmiId
      KeyName: !Ref KeyName
      BlockDeviceMappings:
        - DeviceName: /dev/sda1
          Ebs:
            VolumeType: gp2
            VolumeSize: 30
            DeleteOnTermination: true
      NetworkInterfaces:
        - SubnetId: !Ref SubnetId
          AssociatePublicIpAddress: true
          GroupSet:
             - !Ref SecurityGroupId
          DeviceIndex: 0
          DeleteOnTermination: true
      DisableApiTermination: true
      Tags:
        - Key: Name
          Value: !Ref TagName

注意:Idは、IDでなくIdです(ハマりました)

パラメーターの指定


ここでパラメータを変更できます。Defaultを指定することができます。

  • AMI
    Amazon マシンイメージ。
  • Key
    拡張子 pem ファイル。構築後のWindowsパスワードの取得で必要になります。
  • SecurityGroup
    AWS EC2 セキュリティグループ。リモートデスクトップ RDP 3389 は危険なので、 自宅や会社のグローバルIPだけアクセスできるようにしましょう。
  • Subnet
    AWS VPC サブネット。VPCはざっくりいうと社内LANに当たります。アベイラビリティーゾーンAZ(1bや1c)というのは東京や大阪になります。 2つ以上分散させて構築します。仮に東京の建物に障害があっても大阪で起動します。
  • TagName
    構築後に表示される名前です。

イベント結果


イベントを開きます。エラーがある場合はここに表示されます。

まとめ

持論ですが知識を反復させたものが技術です。これだけでも5回くらいやらないと身に付かないです。次から応用パターンに挑戦していきたいと思います(これからが本番や!)

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