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?

Cloud9の実行環境を構築する

Posted at

AWS CDKの学習環境としてCloud9の構築を実施したのでメモ

ネットワークの構築

Cloud9のインスタンスを動かすためのネットワークを構築します。
今回は以下のリソースをCloudFormationで作成するため、テンプレートファイルを作成します。

  • VPC(10.0.0.0/16)
  • PublicSubnet(10.0.0.0/24)
  • PrivateSubnet(10.0.1.0/24)
  • PublicRouteTable
  • PrivateRouteTable
  • InternetGateway
  • ElasticIP
  • NATGateway
networkForCloud9.yaml
AWSTemplateFormatVersion: 2010-09-09
Description: Deploy Cloud9 VPC

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsHostnames: true
      Tags:
      - Key: Name
        Value: Cloud9 VPC

  InternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
      - Key: Name
        Value: Cloud9 Internet Gateway

  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref VPC
      InternetGatewayId: !Ref InternetGateway

  PublicSubnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      CidrBlock: 10.0.0.0/24
      AvailabilityZone: !Select 
        - '0'
        - !GetAZs ''
      Tags:
        - Key: Name
          Value: Public Subnet 1

  PrivateSubnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      CidrBlock: 10.0.1.0/24
      AvailabilityZone: !Select 
        - '0'
        - !GetAZs ''
      Tags:
        - Key: Name
          Value: Private Subnet 1

  PublicRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: Public Route Table

  PublicRoute:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PublicRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway

  PublicSubnetRouteTableAssociation1:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PublicSubnet1
      RouteTableId: !Ref PublicRouteTable

  NATGatewayEIP:
    Type: AWS::EC2::EIP
    Properties: 
      Domain: vpc

  NATGateway:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId: !GetAtt NATGatewayEIP.AllocationId
      ConnectivityType: public
      SubnetId: !Ref PublicSubnet1
      Tags:
      - Key: Name
        Value: Cloud9 NATGateway

  PrivateRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
      - Key: Name
        Value: Private Route Table

  PrivateRoute:
    DependsOn: NATGateway
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PrivateRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref NATGateway

  PrivateSubnetRouteTableAssociation1:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PrivateSubnet1
      RouteTableId: !Ref PrivateRouteTable

CloudFormationでテンプレートファイルをアップロードして環境を構築します。

Cloud9-1.png

Cloud9-2.png

Cloud9の構築

AWS コンソール上でCloud9を構築します。
VPCとサブネットには、先ほどCloudFormationで構築したVPCとPrivateSubnetを指定します。

Cloud9-3.png
Cloud9-4.png

しばらくしたあとに、環境が構築されたことを確認します。
コンソールからCloud9に接続します。

Cloud9-5.png
Cloud9-6.png

参考

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?