2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS Aurora Mysql をCLIで作成

Last updated at Posted at 2023-06-26

問題

AWS内で製品やその製品とそのハードとの互換性が定期的に更新されるため、コマンドラインで用意したパラメーターがいずれ無効になる可能性がある。

aws rds create-db-instance \
--db-instance-identifier <⭐️識別子⭐️> \
--engine <⭐️エンジン⭐️> \
--db-instance-class <⭐️インスタンスクラス⭐️> \
--master-username ユーザー名 \
--master-user-password ユーザーパスワード \
--allocated-storage ギガバイト \
--backup-retention-period バックアップ期間

An error occurred (InvalidParameterCombination) when calling the CreateDBInstance operation: RDS does not support creating a DB instance with the following combination: DBInstanceClass=db.t2.micro, Engine=aurora-mysql, EngineVersion=5.7.mysql_aurora.2.11.2, LicenseModel=general-public-license. For supported combinations of instance class and database engine version, see the documentation.

解決

それぞれのRDBの作成に必要なパラメーターを調べる。ブラウザーで調べても面白くないのでCLIで取得.

① エンジンを調べる

aws rds describe-db-engine-versions \
    --output table \
    --query "DBEngineVersions[].{Engine:Engine,EngineVersion:EngineVersion,DBEngineVersionDescription:DBEngineVersionDescription}"

上記でエンジンとエンジンバージョンを取得(2023/06/26時点の結果の一部のみ搭載)

DBEngineVersionDescription Engine EngineVersion
...
Aurora MySQL 3.01.0 (compatible with MySQL 8.0.23) aurora-mysql 8.0.mysql_aurora.3.01.0
Aurora MySQL 3.01.1 (compatible with MySQL 8.0.23) aurora-mysql 8.0.mysql_aurora.3.01.1
Aurora MySQL 3.02.0 (compatible with MySQL 8.0.23) aurora-mysql 8.0.mysql_aurora.3.02.0
Aurora MySQL 3.02.1 (compatible with MySQL 8.0.23) aurora-mysql 8.0.mysql_aurora.3.02.1
...

エンジン = aurora-mysqlとエンジンバージョン = 8.0.mysql_aurora.3.01.0が分かった!

② インスタンスクラスを調べる

上記のコマンでで好みのエンジンとエンジンバージョンを指定し

aws rds describe-orderable-db-instance-options \
    --engine aurora-mysql \
    --engine-version "8.0.mysql_aurora.3.01.0" \
    --query "OrderableDBInstanceOptions[].{DBInstanceClass:DBInstanceClass,SupportedEngineModes:SupportedEngineModes[0],EngineVersion:EngineVersion}" \
    --output table \
    --region ap-northeast-1

対応するインスタンスクラスを取得(2023/06/26時点の結果)

DBInstanceClass EngineVersion SupportedEngineModes
db.r5.12xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r5.16xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r5.24xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r5.2xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r5.4xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r5.8xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r5.large 8.0.mysql_aurora.3.01.0 provisioned
db.r5.xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r6g.12xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r6g.16xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r6g.2xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r6g.4xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r6g.8xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.r6g.large 8.0.mysql_aurora.3.01.0 provisioned
db.r6g.xlarge 8.0.mysql_aurora.3.01.0 provisioned
db.t3.large 8.0.mysql_aurora.3.01.0 provisioned
db.t3.medium 8.0.mysql_aurora.3.01.0 provisioned
db.t4g.large 8.0.mysql_aurora.3.01.0 provisioned
db.t4g.medium 8.0.mysql_aurora.3.01.0 provisioned

安価なものがほしいからインスタンスクラス = db.t3.mediumが分かった!

さて! 今まで分かったパラメーターだけで作成できそう! 実際にcreate-db-instanceコマンドを叩くとと allocated-storage不正エラーに遭遇してしまう。

An error occurred (InvalidParameterCombination) when calling the CreateDBInstance operation: Invalid storage size for engine name aurora-mysql and storage type aurora: 20

Githubの問題の通り、db cluster identifierを指定するが、そのためにdb clusterを作成する必要がある。

③ 今まで分かったパラメータ一覧

パラメーター名 備考
エンジン aurora-mysql ClusterとInstance作成時両方必要
エンジンバージョン 8.0.mysql_aurora.3.01.0 Cluster作成時必要
インスタンスクラス db.t3.medium Instance作成時に必要
DBクラスターID my-db 自分で決める。ClusterとInstance作成時両方必要
DBインスタンスID my-db-instance 自分で決める。Instance作成時に必要

④ Clusterを作成!

エンジンとエンジンバージョンを指定して実行!

aws rds create-db-cluster \
    --engine aurora-mysql \
    --engine-version "8.0.mysql_aurora.3.01.0" \
    --master-username adminAurora \
    --master-user-password adminAuroraPassword \
    --db-cluster-identifier my-db
{
    "DBCluster": {
        "AllocatedStorage": 1,
        "AvailabilityZones": [
            "ap-northeast-1c",
            "ap-northeast-1a",
            "ap-northeast-1d"
        ],
        "BackupRetentionPeriod": 1,
        "DBClusterIdentifier": "my-db",
        "DBClusterParameterGroup": "default.aurora-mysql8.0",
        "DBSubnetGroup": "default",
        "Status": "creating",
        "Endpoint": "my-db.cluster-xyz1.ap-northeast-1.rds.amazonaws.com",
        "ReaderEndpoint": "my-db.cluster-ro-xyz1.ap-northeast-1.rds.amazonaws.com",
        "MultiAZ": false,
        "Engine": "aurora-mysql",
        "EngineVersion": "8.0.mysql_aurora.3.01.0",
        "Port": 3306,
        "MasterUsername": "adminAurora",
        "PreferredBackupWindow": "17:52-18:22",
        "PreferredMaintenanceWindow": "fri:16:36-fri:17:06",
        "ReadReplicaIdentifiers": [],
        "DBClusterMembers": [],
        "VpcSecurityGroups": [
            {
                "VpcSecurityGroupId": "sg-abc",
                "Status": "active"
            }
        ],
        "HostedZoneId": "Z24O6O9L7SGTNB",
        "StorageEncrypted": false,
        "DbClusterResourceId": "cluster-Ddef",
        "DBClusterArn": "arn:aws:rds:ap-northeast-1:999:cluster:my-db",
        "AssociatedRoles": [],
        "IAMDatabaseAuthenticationEnabled": false,
        "ClusterCreateTime": "2023-06-26T10:19:22.490000+00:00",
        "EngineMode": "provisioned",
        "DeletionProtection": false,
        "HttpEndpointEnabled": false,
        "CopyTagsToSnapshot": false,
        "CrossAccountClone": false,
        "DomainMemberships": [],
        "TagList": [],
        "AutoMinorVersionUpgrade": true,
        "NetworkType": "IPV4"
    }
}

④ RDS Instanceを作成!

注意: Clusterの方で既にユーザー名とパスワードを指定しているので create-db-instanceの時に指定しない。指定してしまうと怒られる。

An error occurred (InvalidParameterCombination) when calling the CreateDBInstance operation: The requested DB Instance will be a member of a DB Cluster. Set master user password for the DB Cluster.

成功するコマンド:

aws rds create-db-instance \
    --db-instance-identifier my-db-instance \
    --db-cluster-identifier my-db \
    --engine aurora-mysql \
    --db-instance-class db.t3.medium  

結果:

{
    "DBInstance": {
        "DBInstanceIdentifier": "my-db-instance",
        "DBInstanceClass": "db.t3.medium",
        "Engine": "aurora-mysql",
        "DBInstanceStatus": "creating",
        "MasterUsername": "adminAurora",
        "AllocatedStorage": 1,
        "PreferredBackupWindow": "17:52-18:22",
        "BackupRetentionPeriod": 1,
        "DBSecurityGroups": [],
        "VpcSecurityGroups": [
            {
                "VpcSecurityGroupId": "sg-stu",
                "Status": "active"
            }
        ],
        "DBParameterGroups": [
            {
                "DBParameterGroupName": "default.aurora-mysql8.0",
                "ParameterApplyStatus": "in-sync"
            }
        ],
        "DBSubnetGroup": {
            "DBSubnetGroupName": "default",
            "DBSubnetGroupDescription": "default",
            "VpcId": "vpc-def",
            "SubnetGroupStatus": "Complete",
            "Subnets": [
                {
                    "SubnetIdentifier": "subnet-abc123",
                    "SubnetAvailabilityZone": {
                        "Name": "ap-northeast-1c"
                    },
                    "SubnetOutpost": {},
                    "SubnetStatus": "Active"
                },
                {
                    "SubnetIdentifier": "subnet-abc789",
                    "SubnetAvailabilityZone": {
                        "Name": "ap-northeast-1a"
                    },
                    "SubnetOutpost": {},
                    "SubnetStatus": "Active"
                },
                {
                    "SubnetIdentifier": "subnet-abc567",
                    "SubnetAvailabilityZone": {
                        "Name": "ap-northeast-1d"
                    },
                    "SubnetOutpost": {},
                    "SubnetStatus": "Active"
                }
            ]
        },
        "PreferredMaintenanceWindow": "thu:19:56-thu:20:26",
        "PendingModifiedValues": {},
        "MultiAZ": false,
        "EngineVersion": "8.0.mysql_aurora.3.01.0",
        "AutoMinorVersionUpgrade": true,
        "ReadReplicaDBInstanceIdentifiers": [],
        "LicenseModel": "general-public-license",
        "OptionGroupMemberships": [
            {
                "OptionGroupName": "default:aurora-mysql-8-0",
                "Status": "in-sync"
            }
        ],
        "PubliclyAccessible": false,
        "StorageType": "aurora",
        "DbInstancePort": 0,
        "DBClusterIdentifier": "my-db",
        "StorageEncrypted": false,
        "DbiResourceId": "db-XYZ123",
        "CACertificateIdentifier": "rds-ca-2019",
        "DomainMemberships": [],
        "CopyTagsToSnapshot": false,
        "MonitoringInterval": 0,
        "PromotionTier": 1,
        "DBInstanceArn": "arn:aws:rds:ap-northeast-1:99966:db:my-db-instance",
        "IAMDatabaseAuthenticationEnabled": false,
        "PerformanceInsightsEnabled": false,
        "DeletionProtection": false,
        "AssociatedRoles": [],
        "TagList": [],
        "CustomerOwnedIpEnabled": false,
        "BackupTarget": "region",
        "NetworkType": "IPV4",
        "StorageThroughput": 0,
        "CertificateDetails": {
            "CAIdentifier": "rds-ca-2019"
        }
    }
}

出来上がり!

result.png

⑤ VPC設定関連

Instanceを作成する際に

本当は--vpc-security-group-idsを指定し アクセスを制御する方がいいが、

外から試しに色々と叩きたい時はぜひ --public accessibleをパスして + 設定されているVPCのinboundの設定をする。

AWS Cloudshell から試す場合は curl http://checkip.amazonaws.com/ などを使ってIPを取得して Inbound rulesに適用。

他の参考になったリンク

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?