0
0

More than 1 year has passed since last update.

#3 AWS CLIでRDSを作成する

Last updated at Posted at 2023-07-05

はじめに

AWS CLIでRDSを構築する手順です。構成図は以下の通りです。
rds.png

手順

1.RDSサブネットグループの作成

設定値の指定

DB_SUBNET_GPNAME='cli-db-subnet'
DB_SUBNET_DESC='cli-db-subnet'

SUBNET_ID_1='subnet-xxxx'
SUBNET_ID_2='subnet-xxxx'

TAG_VALUE='cli-db-subnet'

設定値の確認

cat << END
#DB_SUBNET_GPNAME="cli-db-subnet"
 DB_SUBNET_GPNAME="${DB_SUBNET_GPNAME}"

#DB_SUBNET_DESC="cli-db-subnet"
 DB_SUBNET_DESC="${DB_SUBNET_DESC}"

#SUBNET_ID_1="subnet-xxxx"
 SUBNET_ID_1="${SUBNET_ID_1}"

#SUBNET_ID_2="subnet-xxxx"
 SUBNET_ID_2="${SUBNET_ID_2}"

#TAG_VALUE="cli-db-subnet"
 TAG_VALUE="${TAG_VALUE}"

END

処理の実行

aws rds create-db-subnet-group \
--db-subnet-group-name ${DB_SUBNET_GPNAME} \
--db-subnet-group-description ${DB_SUBNET_DESC} \
--subnet-ids ${SUBNET_ID_1} ${SUBNET_ID_2} \
--tags Key=Name,Value=${TAG_NAME}

2.RDSの作成

設定値の指定


DB_IDENTITY='cli-rds'
DB_CLASS='db.t3.micro'

ENGINE='mysql'
ENGINE_VER='8.0.28'

DB_NAME='cli_rds'
MASTER_NAME='admin'
MASTER_PASS='password'

ALLOW_STORAGE='20'

SEC_GROUP='sg-xxxx'
SUBNET_NAME='cli-db-subnet'

設定値の確認

cat << END

#DB_IDENTITY='cli-rds'
 DB_IDENTITY="${DB_IDENTITY}"
 
#DB_CLASS='db.t3.micro'
 DB_CLASS="${DB_CLASS}"

#ENGINE='mysql'
 ENGINE="${ENGINE}"
 
#ENGINE_VER='8.0.28'
 ENGINE_VER="${ENGINE_VER}"
 
#DB_NAME='cli_rds'
 DB_NAME="${DB_NAME}"
 
#MASTER_NAME='admin'
 MASTER_NAME="${MASTER_NAME}"
 
#MASTER_PASS='password'
 MASTER_PASS="${MASTER_PASS}"
 
#ALLOW_STORAGE='20'
 ALLOW_STORAGE="${ALLOW_STORAGE}"
 
#SEC_GROUP='sg-xxxx'
 SEC_GROUP="${SEC_GROUP}"
 
#SUBNET_NAME='cli-db-subnet'
 SUBNET_NAME="${SUBNET_NAME}"


END

処理の実行

aws rds create-db-instance \
--db-instance-identifier ${DB_IDENTITY} \
--db-instance-class ${DB_CLASS} \
--engine ${ENGINE} \
--engine-version ${ENGINE_VER} \
--db-name ${DB_NAME} \
--master-username ${MASTER_NAME} \
--master-user-password ${MASTER_PASS} \
--allocated-storage ${ALLOW_STORAGE} \
--no-multi-az \
--no-publicly-accessible \
--vpc-security-group-ids ${SEC_GROUP}  \
--db-subnet-group-name ${SUBNET_NAME} \
--no-copy-tags-to-snapshot \
--backup-retention-period 0 \
--tags Key=Name,Value=cli-rds

必要となるオプションコマンドが多いので、一度整理します。

  • --db-instance-identifier
    DBインスタンス識別子(オンプレサーバに名前を割り当てるのと同じ)
  • --db-instance-class
    DBインスタンスのクラス
  • --engine
    仕様するDBエンジンのタイプ
  • --engine-version
    使用するDBのエンジンバージョン
  • --db-name
    初期のDB名。
  • --master-username
    マスターユーザー名。
    DB インスタンスにログオンすることで、DBに関するすべての権限を持つ。
  • --master-user-password
    マスターユーザーアカウントのパスワード設定
  • --allocated-storage
    ストレージの割り当て。DBインスタンスに割り当てるストレージ量。
  • --no-multi-azもしくは--multi-az
    フェイルオーバーサポート用に DB インスタンスのパッシブセカンダリレプリカを別のアベイラビリティーゾーンに作成しない(する)
  • --no-publicly-accessibleもしくはpublicly-accessible
    パブリックIPをDBインスタンスに割り当てない(割り当てる)
  • --vpc-security-group-ids
    DBインスタンスに関連付けるSG
  • --db-subnet-group-name
    DBクラスターで使用するDBサブネットグループ
  • --no-copy-tags-to-snapshotもしくは--copy-tags-to-snapshot
    スナップショット作成時に、DBインスタンスタグをスナップショットにコピーしない(する)
  • --backup-retention-period
    DBインスタンスの自動バックアップを保持する日数
    (重要なインスタンスでは1以上に設定)
  • --tags
    リソースのタグ付け

#4 AWS CLIでELBを作成する

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