LoginSignup
0
0

More than 5 years have passed since last update.

[aws-cli]RDSをjson形式設定ファイルから設定変更する。

Posted at

[aws-cli]RDSをjson形式設定ファイルから設定変更する。

RDSの設定変更コマンドはmodify-db-instance
modify-db-instance — AWS CLI 1.10.38 Command Reference
同じ設定内容で何度コマンドを実行しても変更は走らないので、ビルド実行時等に自動実行することも可能。

デフォルトの設定ファイルを出力


$ aws rds modify-db-instance --generate-cli-skeleton > default.json
$ cat default.json
{
    "DBInstanceIdentifier": "",
    "AllocatedStorage": 0,
    "DBInstanceClass": "",
    "DBSecurityGroups": [
        "" 
    ],
    "VpcSecurityGroupIds": [
        "" 
    ],
    "ApplyImmediately": true,
    "MasterUserPassword": "",
    "DBParameterGroupName": "",
    "BackupRetentionPeriod": 0,
    "PreferredBackupWindow": "",
    "PreferredMaintenanceWindow": "",
    "MultiAZ": true,
    "EngineVersion": "",
    "AllowMajorVersionUpgrade": true,
    "AutoMinorVersionUpgrade": true,
    "Iops": 0,
    "OptionGroupName": "",
    "NewDBInstanceIdentifier": "",
    "StorageType": "",
    "TdeCredentialArn": "",
    "TdeCredentialPassword": "",
    "CACertificateIdentifier": "",
    "CopyTagsToSnapshot": true,
    "DBPortNumber": 0,
    "PubliclyAccessible": true
}

各項目について確認

DBInstanceIdentifier: DBインスタンス名 アカウント内で一意
AllocatedStorage: ストレージのサイズ
DBInstanceClass: インスタンスタイプ
MasterUserPassword: DB管理ユーザパスワード
DBSecurityGroups: DBセキュリティグループの配列
VpcSecurityGroupIds: VPCセキュリティグループの配列
PreferredMaintenanceWindow: メンテナンスウィンドウ ddd:hh24:mi-ddd:hh24:mi
DBParameterGroupName: DBパラメータグループ名
BackupRetentionPeriod: バックアップ保持期間 0だとバックアップを行わない
PreferredBackupWindow: バックアップウィンドウ hh24:mi-hh24:mi
Port: ポート 未定義であればデフォルト
MultiAZ: マルチAZ構成にするか否か
EngineVersion: DBエンジンのバージョン
AllowMajorVersionUpgrade: メジャーバージョンアップを適用するか否か
AutoMinorVersionUpgrade: 自動マイナーバージョンアップを許可するか否か
Iops: ストレージへの秒間IO上限
OptionGroupName: オプショングループ名
NewDBInstanceIdentifier: 新しいDBインスタンス名 変更の際に定義
PubliclyAccessible: 外部アクセス可否
StorageType: ストレージタイプ standard | gp2 | io1
TdeCredentialArn: HAパーティショングループのリソース番号
TdeCredentialPassword: HAパーティショングループの初期化時に使用したパーティションパスワード
CACertificateIdentifier: 認証局
CopyTagsToSnapshot: スナップショットにタグをコピーするか否か
DBPortNumber: DBのポート番号

設定ファイル書き換え


$ cat modify.json
{
    "DBInstanceIdentifier": "test",
    "AllocatedStorage": 5,
    "DBInstanceClass": "db.t2.micro",
    "VpcSecurityGroupIds": [
        "sg-xxxxxxxx"
    ],
    "ApplyImmediately": true,
    "DBParameterGroupName": "default.mysql5.6",
    "BackupRetentionPeriod": 3,
    "PreferredBackupWindow": "19:00-19:30",
    "PreferredMaintenanceWindow": "sat:18:00-sat:18:30",
    "MultiAZ": false,
    "EngineVersion": "5.6.27",
    "AllowMajorVersionUpgrade": true,
    "AutoMinorVersionUpgrade": true,
    "Iops": 0,
    "OptionGroupName": "default:mysql-5-6",
    "StorageType": "standard",
    "CopyTagsToSnapshot": true,
    "PubliclyAccessible": false
}

設定変更コマンド実行


$ aws --region ap-northeast-1 rds modify-db-instance --cli-input-json file:///tmp/modify.json
{
    "DBInstance": {
        "PubliclyAccessible": false,
        "MasterUsername": "root",
        "LicenseModel": "general-public-license",
        "VpcSecurityGroups": [
            {
                "Status": "active",
                "VpcSecurityGroupId": "sg-xxxxxxxx" 
            }
        ],
        "InstanceCreateTime": "2016-06-16T08:48:46.145Z",
        "CopyTagsToSnapshot": true,
        "OptionGroupMemberships": [
            {
                "Status": "in-sync",
                "OptionGroupName": "default:mysql-5-6" 
            }
        ],
        "PendingModifiedValues": {
            "BackupRetentionPeriod": 3
        },
        "Engine": "mysql",
        "MultiAZ": false,
        "DBSecurityGroups": [],
        "DBParameterGroups": [
            {
                "DBParameterGroupName": "default.mysql5.6",
                "ParameterApplyStatus": "in-sync" 
            }
        ],
        "AutoMinorVersionUpgrade": true,
        "PreferredBackupWindow": "19:00-19:30",
        "DBSubnetGroup": {
            "Subnets": [
                {
                    "SubnetStatus": "Active",
                    "SubnetIdentifier": "subnet-xxxxxxxx",
                    "SubnetAvailabilityZone": {
                        "Name": "ap-northeast-1c" 
                    }
                },
                {
                    "SubnetStatus": "Active",
                    "SubnetIdentifier": "subnet-xxxxxxxx",
                    "SubnetAvailabilityZone": {
                        "Name": "ap-northeast-1a" 
                    }
                }
            ],
            "DBSubnetGroupName": "default-vpc-xxxxxxxx",
            "VpcId": "vpc-xxxxxxxx",
            "DBSubnetGroupDescription": "Created from the RDS Management Console",
            "SubnetGroupStatus": "Complete" 
        },
        "ReadReplicaDBInstanceIdentifiers": [],
        "AllocatedStorage": 5,
        "BackupRetentionPeriod": 0,
        "DBName": "test",
        "PreferredMaintenanceWindow": "sat:18:00-sat:18:30",
        "Endpoint": {
            "Port": 3306,
            "Address": "test.xxxxxxxx.ap-northeast-1.rds.amazonaws.com" 
        },
        "DBInstanceStatus": "available",
        "EngineVersion": "5.6.27",
        "AvailabilityZone": "ap-northeast-1a",
        "StorageType": "standard",
        "DbiResourceId": "db-xxxxxxxxxxxxxxxxxxxxxxxx",
        "CACertificateIdentifier": "rds-ca-2015",
        "StorageEncrypted": false,
        "DBInstanceClass": "db.t2.micro",
        "DbInstancePort": 0,
        "DBInstanceIdentifier": "test" 
    }
}
$

エラー集

A client error (InvalidParameterValue) occurred when calling the ModifyDBInstance operation: Invalid endpoint port 0. Valid range is: 1150-65535
Portに0が設定されているのが原因。
Portを削除して解消。
各DBのデフォルトポートが使用される。
 
A client error (InvalidParameterValue) occurred when calling the ModifyDBInstance operation: The parameter NewDBInstanceIdentifier must be provided and must not be blank.
NewDBInstanceIdentifierに空が設定されていたのが原因。
NewDBInstanceIdentifierを削除して解消。
 
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