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?

More than 3 years have passed since last update.

CloudFormation ネットワークの作成まで

Posted at

#AWSのリファレンスを見ながらやったらできた
webコンソールで一度ネットワークを構築した人向けです。

##参考にしたリファレンス一覧
###VPC作成リファレンス
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html
###サブネットの作成
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
###インターネットゲートウェイ作成
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-internetgateway.html
###インターネットゲートウェイのアタッチ
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc-gateway-attachment.html
###ルートテーブルの作成
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route-table.html
#####DependsOn 属性(ルートテーブルの作成で利用)
DependsOn 属性を使用すると、特定のリソースが他のリソースに続けて作成されるように指定できます。DependsOn 属性をリソースに追加した場合、そのリソースの作成は必ず、DependsOn 属性で指定したリソースの作成後に行われます。
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html
###サブネットとルートテーブルの関連付け
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet-route-table-assoc.html
###セキュリティグループの作成
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html

##結果

AWSTemplateFormatVersion: "2010-09-09"
Resources:
  MemosVPC:
    Type: AWS::EC2::VPC
    Properties: 
      CidrBlock: 10.0.0.0/16
      Tags:
      - Key: "Name"
        Value: "MemosVpc"
  MemosPubSubnet1a:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: 
        Ref: MemosVPC
      CidrBlock: 10.0.10.0/24
      AvailabilityZone: "ap-northeast-1a"
      Tags:
      - Key: "Name"
        Value: "MemosPubSubnet1a"
  MemosPriSubnet1a:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: 
        Ref: MemosVPC
      CidrBlock: 10.0.20.0/24
      AvailabilityZone: "ap-northeast-1a"
      Tags:
      - Key: "Name"
        Value: "MemosPriSubnet1a"
  MemosIgw:
    Type: AWS::EC2::InternetGateway
    Properties: 
      Tags:
      - Key: "Name"
        Value: "MwmosIgw"
  MemosIgwAttach:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId:
        Ref: MemosVPC
      InternetGatewayId:
        Ref: MemosIgw
  MemosRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId:  
        Ref: MemosVPC
      Tags:
      - Key: "Name"
        Value: "MemosRouteTable"
  MemosRouteInterNet:
    Type: AWS::EC2::Route
    DependsOn: MemosIgwAttach
    Properties:
      RouteTableId:
        Ref: MemosRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId:
        Ref: MemosIgw
  MemosSubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId:
        Ref: MemosPubSubnet1a
      RouteTableId:
        Ref: MemosRouteTable
  MemosInstanceSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
        GroupDescription: Allow http to client host
        VpcId: 
          Ref: MemosVPC
        SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0
        Tags: 
        - Key: "Name"
          Value: "MemosInstanceSecurityGrou"
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?