【AWS CLI】Auroraクラスタ関連の情報取得編

記事タイトルとURLをコピーする

こんにちは。AWS CLIが好きな福島です。

今回は、AWS CLIを使ってAuroraのクラスタ関連の情報を取得するコマンドをブログに記載いたします。

過去にRDS編も記載しているため、ご興味がある方は、以下をご参照ください。

blog.serverworks.co.jp

実行環境

今回、コマンドを実行した環境は、以下の通りとなります。
(本記事でご紹介しているコマンドの中には、Linuxのコマンドを利用している箇所があります。)

# uname -a
Linux LAPTOP-CNM26HN6 4.4.0-18362-Microsoft #1049-Microsoft Thu Aug 14 12:01:00 PST 2020 x86_64 x86_64 x86_64 GNU/Linux
#

クラスタ内のインスタンスの情報(3台のみ表示)

コマンド(ヘッダー無し)

aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,\
DBClusterMembers[0].DBInstanceIdentifier,\
DBClusterMembers[1].DBInstanceIdentifier,\
DBClusterMembers[2].DBInstanceIdentifier]" \
--output text | column -t
  • 実行結果
fk-test-aurora-dev         fk-test-aurora-dev-instance-1         None  None
fk-test-aurora-postgresql  fk-test-aurora-postgresql-instance-1  None  None
fk-test-aurora-prod        fk-test-aurora-prod-instance-1        None  None

コマンド(ヘッダー有り)

echo "DBClusterIdentifier DBInstanceIdentifier[1] DBInstanceIdentifier[2] DBInstanceIdentifier[3]" > /tmp/awscli.tmp;\
aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,\
DBClusterMembers[0].DBInstanceIdentifier,\
DBClusterMembers[1].DBInstanceIdentifier,\
DBClusterMembers[2].DBInstanceIdentifier]" \
--output text  >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier        DBInstanceIdentifier[1]               DBInstanceIdentifier[2]  DBInstanceIdentifier[3]
fk-test-aurora-dev         fk-test-aurora-dev-instance-1         None                     None
fk-test-aurora-postgresql  fk-test-aurora-postgresql-instance-1  None                     None
fk-test-aurora-prod        fk-test-aurora-prod-instance-1        None                     None

エンジンバージョン情報

コマンド(ヘッダー無し)

aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,Engine,EngineVersion]" --output text | column -t
  • 実行結果
fk-test-aurora-dev         aurora             5.6.mysql_aurora.1.19.5
fk-test-aurora-postgresql  aurora-postgresql  9.6.11
fk-test-aurora-prod        aurora             5.6.mysql_aurora.1.19.5

コマンド(ヘッダー有り)

echo "DBClusterIdentifier Engine EngineVersion" > /tmp/awscli.tmp;\
aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,Engine,EngineVersion]" --output text  >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier        Engine             EngineVersion
fk-test-aurora-dev         aurora             5.6.mysql_aurora.1.19.5
fk-test-aurora-postgresql  aurora-postgresql  9.6.11
fk-test-aurora-prod        aurora             5.6.mysql_aurora.1.19.5

補足

以下のコマンドでAurora(それ以外も含む)で利用できるバージョン情報を取得できます。

aws rds describe-db-engine-versions --query "DBEngineVersions[].[Engine,EngineVersion,DBParameterGroupFamily]" --output text | sort
  • 実行結果
aurora  5.6.10a aurora5.6
aurora  5.6.10a aurora5.6
aurora  5.6.10a aurora5.6
aurora  5.6.10a aurora5.6
aurora  5.6.10a aurora5.6
aurora  5.6.mysql_aurora.1.17.9 aurora5.6
aurora  5.6.mysql_aurora.1.19.0 aurora5.6
 : 省略

エンドポイント情報

コマンド(ヘッダー無し)

aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,Endpoint,ReaderEndpoint,Port,MasterUsername]" --output text | column -t
  • 実行結果
fk-test-aurora-dev         fk-test-aurora-dev.cluster-xxxxxxxxxxxxap-northeast-1.rds.amazonaws.com         fk-test-aurora-dev.cluster-xxxxxxxxxxxxfn.ap-northeast-1.rds.amazonaws.com         3306  admin
fk-test-aurora-postgresql  fk-test-aurora-postgresql.cluster-xxxxxxxxxxxxap-northeast-1.rds.amazonaws.com  fk-test-aurora-postgresql.cluster-xxxxxxxxxxxxfn.ap-northeast-1.rds.amazonaws.com  5432  master
fk-test-aurora-prod        fk-test-aurora-prod.cluster-xxxxxxxxxxxxap-northeast-1.rds.amazonaws.com        fk-test-aurora-prod.cluster-xxxxxxxxxxxxfn.ap-northeast-1.rds.amazonaws.com        3306  admin

コマンド(ヘッダー有り)

echo "DBClusterIdentifier Endpoint ReaderEndpoint Port MasterUsername" > /tmp/awscli.tmp;\
aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,Endpoint,ReaderEndpoint,Port,MasterUsername]" --output text >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier        Endpoint                                                                         ReaderEndpoint                                                                      Port  MasterUsername
fk-test-aurora-dev         fk-test-aurora-dev.cluster-xxxxxxxxxxxxap-northeast-1.rds.amazonaws.com         fk-test-aurora-dev.cluster-xxxxxxxxxxxxfn.ap-northeast-1.rds.amazonaws.com         3306  admin
fk-test-aurora-postgresql  fk-test-aurora-postgresql.cluster-xxxxxxxxxxxxap-northeast-1.rds.amazonaws.com  fk-test-aurora-postgresql.cluster-xxxxxxxxxxxxfn.ap-northeast-1.rds.amazonaws.com  5432  master
fk-test-aurora-prod        fk-test-aurora-prod.cluster-xxxxxxxxxxxxap-northeast-1.rds.amazonaws.com        fk-test-aurora-prod.cluster-xxxxxxxxxxxxfn.ap-northeast-1.rds.amazonaws.com        3306  admin

ステータスチェック

コマンド(ヘッダー無し)

aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,Status]" --output text | column -t
  • 実行結果
fk-test-aurora-dev         stopped
fk-test-aurora-postgresql  stopping
fk-test-aurora-prod        stopped

コマンド(ヘッダー有り)

echo "DBClusterIdentifier Status" > /tmp/awscli.tmp;\
aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,Status]" --output text >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier        Status
fk-test-aurora-dev         stopped
fk-test-aurora-postgresql  stopping
fk-test-aurora-prod        stopped

セキュリティグループ情報

コマンド(ヘッダー無し)

aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,\
VpcSecurityGroups[0].VpcSecurityGroupId,\
VpcSecurityGroups[1].VpcSecurityGroupId,\
VpcSecurityGroups[2].VpcSecurityGroupId,\
VpcSecurityGroups[3].VpcSecurityGroupId,\
VpcSecurityGroups[4].VpcSecurityGroupId]" \
--output text | column -t
  • 実行結果
fk-test-aurora-dev         sg-xxxxxxxxxxxxxxxxx  None  None  None  None
fk-test-aurora-postgresql  sg-xxxxxxxxxxxxxxxxx  None  None  None  None
fk-test-aurora-prod        sg-xxxxxxxxxxxxxxxxx  None  None  None  None

コマンド(ヘッダー有り)

echo "DBClusterIdentifier SecurityGroupId[1] SecurityGroupId[2] SecurityGroupId[3] SecurityGroupId[4] SecurityGroupId[5]" > /tmp/awscli.tmp;\
aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,\
VpcSecurityGroups[0].VpcSecurityGroupId,\
VpcSecurityGroups[1].VpcSecurityGroupId,\
VpcSecurityGroups[2].VpcSecurityGroupId,\
VpcSecurityGroups[3].VpcSecurityGroupId,\
VpcSecurityGroups[4].VpcSecurityGroupId]" \
--output text >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier        SecurityGroupId[1]    SecurityGroupId[2]  SecurityGroupId[3]  SecurityGroupId[4]  SecurityGroupId[5]
fk-test-aurora-dev         sg-xxxxxxxxxxxxxxxxx  None                None                None                None
fk-test-aurora-postgresql  sg-xxxxxxxxxxxxxxxxx  None                None                None                None
fk-test-aurora-prod        sg-xxxxxxxxxxxxxxxxx  None                None                None                None

パラメーターグループ情報

コマンド(ヘッダー無し)

aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,DBClusterParameterGroup]" --output text | column -t
  • 実行結果
fk-test-aurora-dev         default.aurora5.6                        
fk-test-aurora-postgresql  fk-test-aurora-postgresql-cluster-xxxxxxxxxx
fk-test-aurora-prod        default.aurora5.6                      

コマンド(ヘッダー有り)

echo "DBClusterIdentifier DBClusterParameterGroup" > /tmp/awscli.tmp;\
aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,DBClusterParameterGroup]" --output text >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier        DBClusterParameterGroup                  
fk-test-aurora-dev         default.aurora5.6                        
fk-test-aurora-postgresql  fk-test-aurora-postgresql-cluster-xxx
fk-test-aurora-prod        default.aurora5.6             

スナップショット情報

コマンド(ヘッダー無し)

aws rds describe-db-cluster-xxxxxxxxxxxxuery "DBClusterSnapshots[].[DBClusterIdentifier,DBClusterSnapshotIdentifier,SnapshotCreateTime]" --output text
  • 実行結果
fk-test-aurora-prod     rds:fk-test-aurora-prod-2020-11-29-14-32        2020-11-29T14:32:19.147000+00:00

コマンド(ヘッダー有り)

echo "DBClusterIdentifier DBClusterSnapshotIdentifier SnapshotCreateTime" > /tmp/awscli.tmp;\
aws rds describe-db-cluster-xxxxxxxxxxxxuery "DBClusterSnapshots[].[DBClusterIdentifier,DBClusterSnapshotIdentifier,SnapshotCreateTime]" --output text >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier  DBClusterSnapshotIdentifier               SnapshotCreateTime
fk-test-aurora-prod  rds:fk-test-aurora-prod-2020-11-29-14-32  2020-11-29T14:32:19.147000+00:00

タグ情報(10個だけ表示)

コマンド(ヘッダー無し)

aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,\
TagList[0].Key,TagList[0].Value,\
TagList[1].Key,TagList[1].Value,\
TagList[2].Key,TagList[2].Value,\
TagList[3].Key,TagList[3].Value,\
TagList[4].Key,TagList[4].Value,\
TagList[5].Key,TagList[5].Value,\
TagList[6].Key,TagList[6].Value,\
TagList[7].Key,TagList[7].Value,\
TagList[8].Key,TagList[8].Value,\
TagList[9].Key,TagList[9].Value]" \
--output text | column -t
  • 実行結果
fk-test-aurora-dev         Control  CloudAutomator  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None
fk-test-aurora-postgresql  Control  CloudAutomator  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None
fk-test-aurora-prod        Control  CloudAutomator  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None  None

コマンド(ヘッダー有り)

echo "DBClusterIdentifier \
key[1] value[1] \
key[2] value[2] \
key[3] value[3] \
key[4] value[4] \
key[5] value[5] \
key[6] value[6] \
key[7] value[7] \
key[8] value[8] \
key[9] value[9] \
key[10] value[10]" > /tmp/awscli.tmp;\
aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,\
TagList[0].Key,TagList[0].Value,\
TagList[1].Key,TagList[1].Value,\
TagList[2].Key,TagList[2].Value,\
TagList[3].Key,TagList[3].Value,\
TagList[4].Key,TagList[4].Value,\
TagList[5].Key,TagList[5].Value,\
TagList[6].Key,TagList[6].Value,\
TagList[7].Key,TagList[7].Value,\
TagList[8].Key,TagList[8].Value,\
TagList[9].Key,TagList[9].Value]" \
--output text >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier        key[1]   value[1]        key[2]  value[2]  key[3]  value[3]  key[4]  value[4]  key[5]  value[5]  key[6]  value[6]  key[7]  value[7]  key[8]  value[8]  key[9]  value[9]
fk-test-aurora-dev         Control  CloudAutomator  None    None      None    None      None    None      None    None      None    None      None    None      None    None      None    None      None  None
fk-test-aurora-postgresql  Control  CloudAutomator  None    None      None    None      None    None      None    None      None    None      None    None      None    None      None    None      None  None
fk-test-aurora-prod        Control  CloudAutomator  None    None      None    None      None    None      None    None      None    None      None    None      None    None      None    None      None  None

その他設定値

その他設定値は、
・マルチAZ
・バックアップウィンドウ
・バックアップ保持期間
・メンテナスウィンドウ
・データベース認証オプション ・ストレージの暗号化有無
・KMSID
・削除保護の有無 の情報を表示しております。

コマンド(ヘッダー無し)

aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,MultiAZ,PreferredBackupWindow,BackupRetentionPeriod,PreferredMaintenanceWindow,IAMDatabaseAuthenticationEnabled,StorageEncrypted,KmsKeyId,DeletionProtection]" --output text | column -t
  • 実行結果
fk-test-aurora-dev         False  16:54-17:24  1  sat:18:25-sat:18:55  False  True  arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  False
fk-test-aurora-postgresql  False  17:50-18:20  7  mon:00:00-mon:00:30  False  True  arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  False
fk-test-aurora-prod        False  14:31-15:01  1  sat:18:38-sat:19:08  False  True  arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  True

コマンド(ヘッダー有り)

echo "DBClusterIdentifier MultiAZ PreferredBackupWindow BackupRetentionPeriod PreferredMaintenanceWindow IAMDatabaseAuthenticationEnabled StorageEncrypted KmsKeyId DeletionProtection" > /tmp/awscli.tmp;\
aws rds describe-db-clusters --query "DBClusters[].[DBClusterIdentifier,MultiAZ,PreferredBackupWindow,BackupRetentionPeriod,PreferredMaintenanceWindow,IAMDatabaseAuthenticationEnabled,StorageEncrypted,KmsKeyId,DeletionProtection]" --output text >> /tmp/awscli.tmp;\
column -t /tmp/awscli.tmp;\
rm /tmp/awscli.tmp
  • 実行結果
DBClusterIdentifier        MultiAZ  PreferredBackupWindow  BackupRetentionPeriod  PreferredMaintenanceWindow  IAMDatabaseAuthenticationEnabled  StorageEncrypted  KmsKeyId                                                                          DeletionProtection
fk-test-aurora-dev         False    16:54-17:24            1                      sat:18:25-sat:18:55         False                             True              arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  False
fk-test-aurora-postgresql  False    17:50-18:20            7                      mon:00:00-mon:00:30         False                             True              arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  False
fk-test-aurora-prod        False    14:31-15:01            1                      sat:18:38-sat:19:08         False                             True              arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  True

おわりに

今回は、Aurora関連のリソース情報を取得するコマンドをご紹介いたしました。
次回は、ELB関連のリソース情報を取得するコマンドをご紹介したいと思います。

福島 和弥 (記事一覧)

2019/10 入社

AWS CLIが好きです。

AWS資格12冠。2023 Japan AWS Partner Ambassador/APN ALL AWS Certifications Engineer。