LoginSignup
0
0

More than 3 years have passed since last update.

AWS CLIでWordPress環境を構築する~part1~

Posted at

概要

AWS学習目的で、下記記事のレシピを参考にAWS CLIでの環境構築を行う。
【Amazon3時間クッキング】材料費500円でAWSにWordPress環境を構築するレシピ

この記事では以下の作業を行う。

  • VPCの作成
  • サブネットの作成(パブリックセグメント)
  • インターネットゲートウェイの作成
  • ルートテーブルの作成

環境

  • macOS Catalina

前提条件

  • AWSアカウント
  • AWS CLI
    • aws configureで設定済み

構築

VPCの作成

項目
リージョン アジアパシフィック(東京)
CIDRブロック 10.0.0.0/16
名前 test-VPC
# VPCの作成
$ aws ec2 create-vpc --region ap-northeast-1 --cidr-block 10.0.0.0/16
{
    "Vpc": {
        "CidrBlock": "10.0.0.0/16",
        "DhcpOptionsId": "dopt-81eaa2e6",
        "State": "pending",
        "VpcId": "vpc-07154996e6c851750",
        "OwnerId": "403733593576",
        "InstanceTenancy": "default",
        "Ipv6CidrBlockAssociationSet": [],
        "CidrBlockAssociationSet": [
            {
                "AssociationId": "vpc-cidr-assoc-0a6334afa0f843a96",
                "CidrBlock": "10.0.0.0/16",
                "CidrBlockState": {
                    "State": "associated"
                }
            }
        ],
        "IsDefault": false,
        "Tags": []
    }
}

# 名前の設定
$ aws ec2 create-tags --resources vpc-07154996e6c851750 --tags Key=Name,Value=test-VPC

サブネットの作成(パブリックセグメント)

項目
CIDRブロック 10.0.1.0/24
名前 test-PublicSegment
# サブネットの作成
$ aws ec2 create-subnet --vpc-id vpc-07154996e6c851750 --cidr-block 10.0.1.0/24
{
    "Subnet": {
        "AvailabilityZone": "ap-northeast-1c",
        "AvailabilityZoneId": "apne1-az1",
        "AvailableIpAddressCount": 251,
        "CidrBlock": "10.0.1.0/24",
        "DefaultForAz": false,
        "MapPublicIpOnLaunch": false,
        "State": "pending",
        "SubnetId": "subnet-02558655ff2936296",
        "VpcId": "vpc-07154996e6c851750",
        "OwnerId": "403733593576",
        "AssignIpv6AddressOnCreation": false,
        "Ipv6CidrBlockAssociationSet": [],
        "SubnetArn": "arn:aws:ec2:ap-northeast-1:403733593576:subnet/subnet-02558655ff2936296"
    }
}

# 名前の設定
$ aws ec2 create-tags --resources subnet-02558655ff2936296 --tags Key=Name,Value=test-PublicSegment

インターネットゲートウェイの作成

項目
名前 test-IGW
# ゲートウェイの作成
$ aws ec2 create-internet-gateway
{
    "InternetGateway": {
        "Attachments": [],
        "InternetGatewayId": "igw-069600493ea4658d1",
        "Tags": []
    }
}

# 名前の設定
$ aws ec2 create-tags --resources igw-069600493ea4658d1 --tags Key=Name,Value=test-IGW

# VPCにインターネットゲートウェイをアタッチ
$ aws ec2 attach-internet-gateway --vpc-id vpc-07154996e6c851750 --internet-gateway-id igw-069600493ea4658d1

カスタムルートテーブルの作成

項目
名前 test-PublicRouteTable
送信先 0.0.0.0/0
# カスタムルートテーブルの作成
$ aws ec2 create-route-table --vpc-id vpc-07154996e6c851750
{
    "RouteTable": {
        "Associations": [],
        "PropagatingVgws": [],
        "RouteTableId": "rtb-0e03cccb92108b0d1",
        "Routes": [
            {
                "DestinationCidrBlock": "10.0.0.0/16",
                "GatewayId": "local",
                "Origin": "CreateRouteTable",
                "State": "active"
            }
        ],
        "Tags": [],
        "VpcId": "vpc-07154996e6c851750",
        "OwnerId": "403733593576"
    }
}

# 名前の設定
$ aws ec2 create-tags --resources rtb-0e03cccb92108b0d1 --tags Key=Name,Value=test-PublicRouteTable

# インターネットゲートウェイへのすべてのトラフィック (0.0.0.0/0) をポイントするルートテーブルでルートを作成
$ aws ec2 create-route --route-table-id rtb-0e03cccb92108b0d1 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-069600493ea4658d1
{
    "Return": true
}

ルートテーブル サブネットの関連付け

$ aws ec2 associate-route-table  --subnet-id subnet-02558655ff2936296 --route-table-id rtb-0e03cccb92108b0d1
{
    "AssociationId": "rtbassoc-04f4894cba1ed2dab",
    "AssociationState": {
        "State": "associated"
    }
}

参考

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