presents by IT Consulting 109

AWS – RDSインスタンス情報の取得

概要

RDSのインスタンス情報を取得する方法について記載しています。

Amazon Relational Database Service (RDS)
Amazon Relational Database Service (Amazon RDS) を使用すると、クラウド内でリレーショナルデータベースを簡単に設定、運用、およびスケールできます。ハードウェアのプロビジョニング、データベースのセットアップ、パッチ適用、バックアップなどの時間がかかる管理タスクを自動化しながら、コスト効率とサイズ変更可能なキャパシティーを提供します。これにより、アプリケーションに集中することができ、必要とされる高速なパフォーマンス、高可用性、セキュリティ、互換性をアプリケーションに実装できるようになります。

 

手順

aws rds describe-db-instances

実行結果 TEXT

DBINSTANCES     20      True    ap-northeast-1a 7       rds-ca-2015     False   arn:aws:rds:ap-northeast-1:987654321000:db:project-01-db       db.t2.micro     project-01-db  available       project-01_db  0       db-DOO5RZUZYGHQXDSJDGAQJMFDK*   mysql   5.7.19  arn:aws:logs:ap-northeast-1:987654321000:log-group:RDSOSMetrics:log-stream:db-DOO5RZUZYGHQXDSJDGAQJMFDK*        False   2018-01-01T00:00:00.000Z        2018-01-01T00:00:00Z    general-public-license  dbuser  60      arn:aws:iam::987654321000:role/rds-monitoring-role      False   False   20:00-20:30     mon:17:00-mon:17:30     False   False   gp2
DBPARAMETERGROUPS       dbg-project-01-mysql57 in-sync
DBSUBNETGROUP   project 01 DB Subnet Group     dsub-project-01        Complete        vpc-8db025e*
SUBNETS subnet-a44c06e* Active
SUBNETAVAILABILITYZONE  ap-northeast-1a
SUBNETS subnet-802fa8d* Active
SUBNETAVAILABILITYZONE  ap-northeast-1c
ENDPOINT        project-01-db.c7i33jqceg2*.ap-northeast-1.rds.amazonaws.com    Z7SGTNB24O6O9*  3306
OPTIONGROUPMEMBERSHIPS  opg-project-01-mysql57 in-sync
VPCSECURITYGROUPS       active  sg-fde1a28*

TABLE

----------------------------------------------------------------------------------------------------------------------------------------------------
|                                                                DescribeDBInstances                                                               |
+--------------------------------------------------------------------------------------------------------------------------------------------------+
||                                                                   DBInstances                                                                  ||
|+----------------------------------+-------------------------------------------------------------------------------------------------------------+|
||  AllocatedStorage                |  20                                                                                                         ||
||  AutoMinorVersionUpgrade         |  True                                                                                                       ||
||  AvailabilityZone                |  ap-northeast-1a                                                                                            ||
||  BackupRetentionPeriod           |  7                                                                                                          ||
||  CACertificateIdentifier         |  rds-ca-2015                                                                                                ||
||  CopyTagsToSnapshot              |  False                                                                                                      ||
||  DBInstanceArn                   |  arn:aws:rds:ap-northeast-1:987654321000:db:project-01-db                                                   ||
||  DBInstanceClass                 |  db.t2.micro                                                                                                ||
||  DBInstanceIdentifier            |  project-01-db                                                                                              ||
||  DBInstanceStatus                |  available                                                                                                  ||
||  DBName                          |  project-01_db                                                                                              ||
||  DbInstancePort                  |  0                                                                                                          ||
||  DbiResourceId                   |  db-DOO5RZUZYGHQXDSJDGAQJMFDK*                                                                              ||
||  Engine                          |  mysql                                                                                                      ||
||  EngineVersion                   |  5.7.19                                                                                                     ||
||  EnhancedMonitoringResourceArn   |  arn:aws:logs:ap-northeast-1:987654321000:log-group:RDSOSMetrics:log-stream:db-DOO5RZUZYGHQXDSJDGAQJMFDK*   ||
||  IAMDatabaseAuthenticationEnabled|  False                                                                                                      ||
||  InstanceCreateTime              |  2018-01-01T00:00:00.000Z                                                                                   ||
||  LatestRestorableTime            |  2018-01-01T00:00:00Z                                                                                       ||
||  LicenseModel                    |  general-public-license                                                                                     ||
||  MasterUsername                  |  dbuser                                                                                                     ||
||  MonitoringInterval              |  60                                                                                                         ||
||  MonitoringRoleArn               |  arn:aws:iam::987654321000:role/rds-monitoring-role                                                         ||
||  MultiAZ                         |  False                                                                                                      ||
||  PerformanceInsightsEnabled      |  False                                                                                                      ||
||  PreferredBackupWindow           |  20:00-20:30                                                                                                ||
||  PreferredMaintenanceWindow      |  mon:17:00-mon:17:30                                                                                        ||
||  PubliclyAccessible              |  False                                                                                                      ||
||  StorageEncrypted                |  False                                                                                                      ||
||  StorageType                     |  gp2                                                                                                        ||
|+----------------------------------+-------------------------------------------------------------------------------------------------------------+|
|||                                                               DBParameterGroups                                                              |||
||+------------------------------------------------------------------------------+---------------------------------------------------------------+||
|||  DBParameterGroupName                                                        |  dbg-project-01-mysql57                                       |||
|||  ParameterApplyStatus                                                        |  in-sync                                                      |||
||+------------------------------------------------------------------------------+---------------------------------------------------------------+||
|||                                                                 DBSubnetGroup                                                                |||
||+-----------------------------------------------------------------+----------------------------------------------------------------------------+||
|||  DBSubnetGroupDescription                                       |  project 01 DB Subnet Group                                               |||
|||  DBSubnetGroupName                                              |  dsub-project-01                                                           |||
|||  SubnetGroupStatus                                              |  Complete                                                                  |||
|||  VpcId                                                          |  vpc-8db025e*                                                              |||
||+-----------------------------------------------------------------+----------------------------------------------------------------------------+||
||||                                                                   Subnets                                                                  ||||
|||+-----------------------------------------------------------------------+--------------------------------------------------------------------+|||
||||  SubnetIdentifier                                                     |  subnet-a44c06e*                                                   ||||
||||  SubnetStatus                                                         |  Active                                                            ||||
|||+-----------------------------------------------------------------------+--------------------------------------------------------------------+|||
|||||                                                          SubnetAvailabilityZone                                                          |||||
||||+---------------------------------------+--------------------------------------------------------------------------------------------------+||||
|||||  Name                                 |  ap-northeast-1a                                                                                 |||||
||||+---------------------------------------+--------------------------------------------------------------------------------------------------+||||
||||                                                                   Subnets                                                                  ||||
|||+-----------------------------------------------------------------------+--------------------------------------------------------------------+|||
||||  SubnetIdentifier                                                     |  subnet-802fa8d*                                                   ||||
||||  SubnetStatus                                                         |  Active                                                            ||||
|||+-----------------------------------------------------------------------+--------------------------------------------------------------------+|||
|||||                                                          SubnetAvailabilityZone                                                          |||||
||||+---------------------------------------+--------------------------------------------------------------------------------------------------+||||
|||||  Name                                 |  ap-northeast-1c                                                                                 |||||
||||+---------------------------------------+--------------------------------------------------------------------------------------------------+||||
|||                                                                   Endpoint                                                                   |||
||+------------------------------+---------------------------------------------------------------------------------------------------------------+||
|||  Address                     |  project-01-db.c7i33jqceg2*.ap-northeast-1.rds.amazonaws.com                                                  |||
|||  HostedZoneId                |  Z7SGTNB24O6O9*                                                                                               |||
|||  Port                        |  3306                                                                                                         |||
||+------------------------------+---------------------------------------------------------------------------------------------------------------+||
|||                                                            OptionGroupMemberships                                                            |||
||+----------------------------------------------------------------------+-----------------------------------------------------------------------+||
|||  OptionGroupName                                                     |  opg-project-01-mysql57                                               |||
|||  Status                                                              |  in-sync                                                              |||
||+----------------------------------------------------------------------+-----------------------------------------------------------------------+||
|||                                                               VpcSecurityGroups                                                              |||
||+------------------------------------------------------------------------------------+---------------------------------------------------------+||
|||  Status                                                                            |  active                                                 |||
|||  VpcSecurityGroupId                                                                |  sg-fde1a28*                                            |||
||+------------------------------------------------------------------------------------+---------------------------------------------------------+||

JSON

{
    "DBInstances": [
        {
            "PubliclyAccessible": false,
            "MasterUsername": "dbuser",
            "MonitoringInterval": 60,
            "LicenseModel": "general-public-license",
            "VpcSecurityGroups": [
                {
                    "Status": "active",
                    "VpcSecurityGroupId": "sg-fde1a28*"
                }
            ],
            "InstanceCreateTime": "2018-01-01T00:00:00.000Z",
            "CopyTagsToSnapshot": false,
            "OptionGroupMemberships": [
                {
                    "Status": "in-sync",
                    "OptionGroupName": "opg-project-01-mysql57"
                }
            ],
            "PendingModifiedValues": {},
            "Engine": "mysql",
            "MultiAZ": false,
            "LatestRestorableTime": "2018-03-22T01:20:00Z",
            "DBSecurityGroups": [],
            "DBParameterGroups": [
                {
                    "DBParameterGroupName": "dbg-project-01-mysql57",
                    "ParameterApplyStatus": "in-sync"
                }
            ],
            "PerformanceInsightsEnabled": false,
            "AutoMinorVersionUpgrade": true,
            "PreferredBackupWindow": "20:00-20:30",
            "DBSubnetGroup": {
                "Subnets": [
                    {
                        "SubnetStatus": "Active",
                        "SubnetIdentifier": "subnet-a44c06e*",
                        "SubnetAvailabilityZone": {
                            "Name": "ap-northeast-1a"
                        }
                    },
                    {
                        "SubnetStatus": "Active",
                        "SubnetIdentifier": "subnet-802fa8d*",
                        "SubnetAvailabilityZone": {
                            "Name": "ap-northeast-1c"
                        }
                    }
                ],
                "DBSubnetGroupName": "dsub-project-01",
                "VpcId": "vpc-8db025e*",
                "DBSubnetGroupDescription": "project 01 DB Subnet Group ",
                "SubnetGroupStatus": "Complete"
            },
            "ReadReplicaDBInstanceIdentifiers": [],
            "AllocatedStorage": 20,
            "DBInstanceArn": "arn:aws:rds:ap-northeast-1:987654321000:db:project-01-db",
            "BackupRetentionPeriod": 7,
            "DBName": "project-01_db",
            "PreferredMaintenanceWindow": "mon:17:00-mon:17:30",
            "Endpoint": {
                "HostedZoneId": "Z7SGTNB24O6O9*",
                "Port": 3306,
                "Address": "project-01-db.c7i33jqceg2*.ap-northeast-1.rds.amazonaws.com"
            },
            "DBInstanceStatus": "available",
            "IAMDatabaseAuthenticationEnabled": false,
            "EngineVersion": "5.7.19",
            "EnhancedMonitoringResourceArn": "arn:aws:logs:ap-northeast-1:987654321000:log-group:RDSOSMetrics:log-stream:db-DOO5RZUZYGHQXDSJDGAQJMFDK*",
            "AvailabilityZone": "ap-northeast-1a",
            "DomainMemberships": [],
            "MonitoringRoleArn": "arn:aws:iam::987654321000:role/rds-monitoring-role",
            "StorageType": "gp2",
            "DbiResourceId": "db-DOO5RZUZYGHQXDSJDGAQJMFDK*",
            "CACertificateIdentifier": "rds-ca-2015",
            "StorageEncrypted": false,
            "DBInstanceClass": "db.t2.micro",
            "DbInstancePort": 0,
            "DBInstanceIdentifier": "project-01-db"
        }
    ]
}

 

出力結果から以下の項目が取得できます。

項目 形式 説明 対応箇所
Marker string 以前の要求によって提供されたオプションのページネーショントークン
DBInstances list DBInstanceインスタンスのリスト。
 DBInstanceIdentifier string ユーザー指定のデータベース識別子が含まれます。 DBインスタンス
 DBInstanceClass string DBインスタンスの計算クラスとメモリ容量クラスの名前が含まれます。 DBインスタンスのクラス
 Engine string このDBインスタンスに使用されるデータベースエンジンの名前を指定します。 エンジン
 DBInstanceStatus string このデータベースの現在の状態を指定します。 DBインスタンスのステータス
 MasterUsername string DBインスタンスのマスターユーザー名を含みます。 ユーザ名
 DBName string このパラメータの意味は、使用するデータベースエンジンによって異なります。 DB名
 Endpoint structure 接続エンドポイントを指定します。 エンドポイント
  Address string DBインスタンスのDNSアドレスを指定します。 ポート
  Port integer データベースエンジンが待機しているポートを指定します。  
  HostedZoneId string ホストされたゾーンを作成するときにAmazon Route 53が割り当てるIDを指定します。  
 AllocatedStorage  integer 割り当てられたストレージサイズをギガバイトで指定します。 ストレージ
 InstanceCreateTime  timesstamp DBインスタンスが作成された日時を提供します。 作成時刻
 PreferredBackupWindow string 自動バックアップが有効になっている場合、自動バックアップが作成される日次時間範囲を指定します バックアップウインド
 BackupRetentionPeriod integer 自動DBスナップショットが保持される日数を指定します。 自動バックアップ
 DBSecurityGroups list DBセキュリティグループ要素のリスト セキュリティグループ
  DBSecurityGroupName string DBセキュリティグループの名前。
  Status string DBセキュリティグループのステータス。

 VpcSecurityGroups list DBインスタンスが属するVPCセキュリティグループ要素のリストを提供します。 VPC
  VpcSecurityGroupId string VPCセキュリティグループの名前。
  Status string VPCセキュリティグループのステータス。
 DBParameterGroups list このDBインスタンスに適用されるDBパラメータグループのリストを提供します。 パラメーターグループ
  DBParameterGroupName string DBパラメータグループの名前。
  ParameterApplyStatus string パラメータ更新のステータス。
 AvailabilityZone string DBインスタンスが配置されている可用性ゾーンの名前を指定します。 アベイラビリティーゾーン
 DBSubnetGroup  structure サブネットグループ内の名前、説明、サブネットなど、DBインスタンスに関連付けられたサブネットグループに関する情報を指定します。 サブネット
  DBSubnetGroupName string DBサブネットグループの名前。
  DBSubnetGroupDescription string DBサブネットグループの説明を提供します。
  VpcId string DBサブネットグループのVpcIdを提供します。
  SubnetGroupStatus string DBサブネットグループのステータスを提供します。
  Subnets list サブネット要素のリストを含みます。
    SubnetIdentifier string サブネットの識別子を指定します。
    SubnetAvailabilityZone structure 可用性ゾーン情報が含まれます。
    Name string 可用性ゾーンの名前。
   SubnetStatus string サブネットのステータスを指定します。
  DBSubnetGroupArn string DBサブネットグループのAmazonリソース名(ARN)。
 PreferredMaintenanceWindow string ユニバーサル協定時刻(UTC)でシステムメンテナンスが行われる週単位の時間範囲を指定します。 メンテナンスウインド
 PendingModifiedValues structure DBインスタンスへの変更が保留中であることを指定します。 保留中の変更
  DBInstanceClass string 適用される、または現在適用されているDBインスタンスの新しいDBInstanceClass含みます。
  AllocatedStorage integer 適用される、または現在適用されているDBインスタンスの新しいAllocatedStorageサイズが含まれます。
  MasterUserPassword string DBインスタンスのマスター資格情報の保留中または進行中の変更が含まれます。
  Port integer DBインスタンスの保留ポートを指定します。
  BackupRetentionPeriod integer 自動バックアップを保持する保留中の日数を指定します。
  MultiAZ boolean シングルAZデータベースインスタンスがマルチAZ配備に変更されることを示します。
  EngineVersion string データベースエンジンのバージョンを示します。
  LicenseModel string DBインスタンスのライセンスモデル。
  Iops integer 適用される、または現在適用されているDBインスタンスの新しいプロビジョニングIOPS値を指定します。
  DBInstanceIdentifier string 適用される、または現在適用されているDBインスタンスの新しいDBInstanceIdentifier含みます。
  StorageType string DBインスタンスに関連付けるストレージタイプを指定します。
  CACertificateIdentifier string DBインスタンスのCA証明書の識別子を指定します
  DBSubnetGroupName string DBインスタンスの新しいDBサブネットグループ。
  PendingCloudwatchLogsExports structure 構成がまだ保留中のログ・タイプのリスト。
   LogTypesToEnable list 非アクティブ化中のログタイプ。
   LogTypesToDisable list 有効にされているプロセスのログタイプ。
  ProcessorFeatures list DBインスタンスのDBインスタンスクラスのCPUコア数とコアあたりのスレッド数。
   Name string プロセッサ機能の名前。有効な名前はcoreCountthreadsPerCoreです。
   Value string プロセッサの機能名の値。
 LatestRestorableTime timestamp 特定の時点のリストアでデータベースをリストアできる最新の時刻を指定します。 最新の復元時刻
 MultiAZ boolean DBインスタンスがマルチAZ配備かどうかを指定します。 マルチAZ
 EngineVersion string データベースエンジンのバージョンを示します。 エンジン
 AutoMinorVersionUpgrade boolean マイナーバージョンのパッチが自動的に適用されることを示します。 マイナーバージョン自動アップグレード
 ReadReplicaSourceDBInstanceIdentifier string このDBインスタンスが読み取りレプリカの場合は、ソースDBインスタンスの識別子が格納されます。
 ReadReplicaDBInstanceIdentifiers list このDBインスタンスに関連付けられた読み取りレプリカの1つ以上の識別子が含まれます。
 ReadReplicaDBClusterIdentifiers list このDBインスタンスの読み取りレプリカであるAurora DBクラスタの識別子を1つ以上含みます。
 LicenseModel string このDBインスタンスのライセンスモデル情報。 ライセンスモデル
 Iops integer プロビジョニングされたIOPS(1秒あたりのI / O操作)値を指定します。
 OptionGroupMemberships list このDBインスタンスのオプショングループメンバーシップのリストを提供します。 オプショングループ
  OptionGroupName string インスタンスが属するオプション・グループの名前。
  Status string DBインスタンスのオプショングループメンバーシップのステータス。
 CharacterSetName string 存在する場合、このインスタンスが関連付けられている文字セットの名前を指定します。
 SecondaryAvailabilityZone stringstring 存在する場合は、複数のAZをサポートするDBインスタンスのセカンダリ可用性ゾーンの名前を指定します。 セカンダリゾーン
 PubliclyAccessible boolean DBインスタンスのアクセシビリティオプションを指定します。 パブリックアクセス可能
 StatusInfos list 読み取りレプリカのステータス。インスタンスが読み取りレプリカでない場合、これは空白です。
  StatusType string この値は現在「読み取り複製」です。
  Normal boolean ブール値。インスタンスが正常に動作している場合はtrue、インスタンスがエラー状態の場合はfalseです。
  Status string DBインスタンスのステータス。
  Message string インスタンスのエラーがある場合のエラーの詳細。
 StorageType string DBインスタンスに関連付けられたストレージタイプを指定します。 ストレージタイプ
 TdeCredentialArn string インスタンスがTDE暗号化に関連付けられているキーストアのARN。
 DbInstancePort integer DBインスタンスがリッスンするポートを指定します。 ポート
 DBClusterIdentifier string DBインスタンスがDBクラスタのメンバである場合、DBインスタンスがメンバであるDBクラスタの名前を含みます。
 StorageEncrypted boolean DBインスタンスを暗号化するかどうかを指定します。
 KmsKeyId  string StorageEncryptedがtrueの場合、暗号化されたDBインスタンスのAWS KMSキー識別子。 暗号の有効化
 DbiResourceId string AWS Region – DBインスタンスの一意で不変な識別子。
 CACertificateIdentifier string このDBインスタンスのCA証明書の識別子。 認証機関
 DomainMemberships list  DBインスタンスに関連付けられたActive Directoryドメインメンバシップレコード。
  Domain string Active Directoryドメインの識別子。
  Status string DBインスタンスのActive Directoryドメインメンバシップのステータス(結合、保留中結合、失敗など)。
  FQDN string Active Directoryドメインの完全修飾ドメイン名。
  IAMRoleName string ディレクトリサービスへのAPI呼び出しを行うときに使用されるIAMロールの名前。
 CopyTagsToSnapshot boolean タグがDBインスタンスからDBインスタンスのスナップショットにコピーされるかどうかを指定します。 タグをスナップショットにコピー
 MonitoringInterval integer DBインスタンスの拡張監視メトリックが収集された時点の間隔(秒単位)。
 EnhancedMonitoringResourceArn string Amazon CloudWatchのAmazonリソース名(ARN)は、DBインスタンスの拡張監視メトリックデータを受け取るログストリームを記録します。
 MonitoringRoleArn string RDSが拡張監視メトリックをAmazon CloudWatchログに送信することを許可するIAMロールのARN。
 PromotionTier integer 既存のプライマリインスタンスの障害後にオーロラレプリカがプライマリインスタンスに昇格される順序を指定する値。
 DBInstanceArn string DBインスタンスのAmazonリソース名(ARN)。
 Timezone string DBインスタンスのタイムゾーン。
 IAMDatabaseAuthenticationEnabled boolean AWS IDとアクセス管理(IAM)アカウントのデータベースアカウントへのマッピングが有効になっている場合はtrue、そうでない場合はfalseです。
 PerformanceInsightsEnabled boolean DB InsightでPerformance Insightsが有効になっている場合はTrue、それ以外の場合はFalseです。
 PerformanceInsightsKMSKeyId string パフォーマンスインサイトデータの暗号化のためのAWS KMSキー識別子。
 PerformanceInsightsRetentionPeriod integer Performance Insightsのデータを保持する時間(日数)。
 EnabledCloudwatchLogsExports list このDBインスタンスがCloudWatchログにエクスポートするように設定されているログの種類のリスト。
 ProcessorFeatures list DBインスタンスのDBインスタンスクラスのCPUコア数とコアあたりのスレッド数。
  Name string プロセッサ機能の名前。有効な名前はcoreCountthreadsPerCoreです。
  Value string プロセッサの機能名の値。

 

 

補足


使用するDBの環境によっては表示される項目が変動します。 以下のようにqueryでフィールドを指定した方が確実に項目が取得できるのでお勧めです。

aws rds describe-db-instances 
--query "DBInstances[].[
AllocatedStorage,
AutoMinorVersionUpgrade,
AvailabilityZone,
BackupRetentionPeriod,
CACertificateIdentifier,
CharacterSetName,
CopyTagsToSnapshot,
DBInstanceArn,
DBInstanceClass,
DBInstanceIdentifier,
DBInstanceStatus,
DBName,
DbInstancePort,
DbiResourceId,
Engine,
EngineVersion,
EnhancedMonitoringResourceArn,
IAMDatabaseAuthenticationEnabled,
InstanceCreateTime,
KmsKeyId,
LatestRestorableTime,
LicenseModel,
MasterUsername,
MonitoringInterval,
MonitoringRoleArn,
MultiAZ,
PerformanceInsightsEnabled,
PreferredBackupWindow,
PreferredMaintenanceWindow,
PubliclyAccessible,
SecondaryAvailabilityZone,
StorageEncrypted,
StorageType,
DBParameterGroups[],
DBSubnetGroup.*,
DBSubnetGroup[].[Subnets],
Endpoint.*,
OptionGroupMemberships[],
VpcSecurityGroups[]
]"
この記事を書いた人
名前:TRUE's。 千葉県育ち、神奈川県在住のIT系フリーエンジニア。 IT系のナレッジサイトを不定期で更新中。 フォトグラファー兼エンジニアとして日々勤しんでいる。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です