AWS の実践チュートリアル 「RDS MySQL から Aurora MySQL へのニアゼロダウンタイム移行」 を試してみた

AWS の実践チュートリアル 「RDS MySQL から Aurora MySQL へのニアゼロダウンタイム移行」 を試してみた

2026.01.26

こんにちは!クラスメソッドオペレーションズ AWS テクニカルサポートチームの大高です。

今回は AWS の実践チュートリアルで「RDS MySQL から Aurora MySQL へのニアゼロダウンタイム移行」というものを見つけたので、実際に試してみました。

https://docs.aws.amazon.com/ja_jp/hands-on/latest/migrate-rdsmysql-to-auroramysql/migrate-rdsmysql-to-auroramysql.html

はじめに

このチュートリアルを試してみたところ、基本的な流れは実践できました。
しかし、公開されているリソースがいくつか古くなっているところもあり、うまく動かなくなってしまっているものや、気になったポイントなどを修正しつつ実践してみました。

そのため、基本的な流れはチュートリアルドキュメントの通りなのですが、いくつかポイントを抑えつつ実際に試したことを記しておきたいと思います。
一方で、それ以外についてはチュートリアルドキュメントに記載されている通りとなるので、細かくは書いていません。ドキュメントをご参照ください。

前提条件

前提条件は、ドキュメントに記載の以下のとおりです。(以下は参考訳となります。)

・既存の AWS アカウント。AWS アカウントをお持ちでない場合は、新しいアカウントを作成して開始することができます。
・Amazon EC2 キーペアは、SSH を使用して EC2 Linux ベースのインスタンスに安全に接続するために使用されます。既にキーペアをお持ちの場合は、このチュートリアルで再利用できます。キーペアをお持ちでない場合は、このチュートリアルを完了する予定のお好みのリージョンで新しいキーペアを作成する手順に従ってください。
・このチュートリアルはデフォルト VPC で完了することを推奨します。各 AWS アカウントは、各リージョンにデフォルト VPC が自動的に作成され、基本的なネットワーク構成が含まれています。そこでは、リソースをそのリージョンのいずれかのアベイラビリティーゾーンにプロビジョニングでき、インターネットへの直接アクセスが可能です。まれに、お客様がこれらのデフォルト VPC を別の目的に使用したり、完全に削除したりすることがあります。アカウントとリージョンでデフォルト VPC が見つからない場合は、ここに記載されている手順に従って再作成できます。

私は既に検証用の AWS アカウントを持っており、VPC については以下のような VPC を準備済みだったので、キーペアのみ新規に追加作成しました。
なお、デフォルト VPC ではなく作成済みの VPC とサブネットを利用するようにしています。

【作成済み VPC】

sample-network-vpc
├── sample-network-public-subnet-1
├── sample-network-public-subnet-2
└── sample-network-public-subnet-3

やってみた

では、実際にやっていきます。
なお、チュートリアルドキュメントは英語のみのドキュメントなので Google Chrome の翻訳機能を利用すると便利でした。

https://support.google.com/chrome/answer/173424

Step 1: Setup web application

CloudFormation の修正について

まずは、ここでダウンロードした CloudFormation テンプレートに修正を入れていきます。

最終的には以下としましたが、修正ポイントを記載しておきます。

CloudFormation.yaml
Metadata:
  License: Apache-2.0
AWSTemplateFormatVersion: '2010-09-09'
Description: 'This AWS CloudFormation Template will launch an Amazon EC2 instance of type t2.micro with latest Amazon Linux 2 OS, bootstrap Apache/PHP, and
install a simple address book web application. The template will also create an Amazon RDS MySQL database instance in free tier, i.e. of type db.t2.micro and with no Multi-AZ setup or
read replicas. The WebTier Security Group will allow only SSH and HTTP connections to this web server EC2 instance, and the DBTier Security Group will
only allow the WebTier Security Group to initiate database connections to the RDS DB instance over TCP port 3306. It is recommended that you deploy in Default VPC.'

Parameters:
  KeyName:
    Description: Name of an existing EC2 KeyPair to enable SSH access
    Type: AWS::EC2::KeyPair::KeyName
    ConstraintDescription: Must be the name of an existing EC2 KeyPair.
  VPC:
    Description: Choose VPC
    Type: AWS::EC2::VPC::Id
  SubnetID1:
    Description: Choose Subnet
    Type: AWS::EC2::Subnet::Id
  SubnetID2:
    Description: Choose Subnet
    Type: AWS::EC2::Subnet::Id
  LatestAmiId:
    Type : AWS::SSM::Parameter::Value<String>
    Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs
  DBInstanceID:
    Default: rdsdb
    Description: RDS DB instance
    Type: String
    MinLength: '1'
    MaxLength: '63'
    AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
    ConstraintDescription: >-
      Must begin with a letter and must not end with a hyphen or contain two
      consecutive hyphens.
  DatabaseName:
    Default: mydb
    Description: Database name
    Type: String
    MinLength: '1'
    MaxLength: '64'
    AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
    ConstraintDescription: Must begin with a letter and contain only alphanumeric characters.
  MasterUsername:
    NoEcho: 'true'
    Description: Username for MySQL database access
    Type: String
    MinLength: '1'
    MaxLength: '16'
    AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
    ConstraintDescription: Must begin with a letter and contain only alphanumeric characters.
  MasterPassword:
    NoEcho: 'true'
    Description: Password for MySQL database access
    Type: String
    MinLength: '8'
    MaxLength: '41'
    AllowedPattern: '[a-zA-Z0-9]*'
    ConstraintDescription: Must contain only alphanumeric characters.
  LocalGIP:
    Description: Please type your local IP address.
    Type: String
    Default: 192.168.0.1

Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      KeyName: !Ref KeyName
      ImageId: !Ref LatestAmiId
      Tags:
        - Key: Name
          Value: "Webserver"
      VpcId: !Ref VPC
      SecurityGroupIds:
        - !Ref WebSecurityGroup
      SubnetId: !Ref SubnetID1
      UserData:
        Fn::Base64: |
           #!/bin/bash
           yum -y install httpd php mysql php-mysql

           case $(ps -p 1 -o comm | tail -1) in
           systemd) systemctl enable --now httpd ;;
           init) chkconfig httpd on; service httpd start ;;
           *) echo "Error starting httpd (OS not using init or systemd)." 2>&1
           esac

           if [ ! -f /var/www/html/bootcamp-app.tar.gz ]; then
           cd /var/www/html
           wget https://s3.amazonaws.com/immersionday-labs/bootcamp-app.tar
           tar xvf bootcamp-app.tar
           chown apache:root /var/www/html/rds.conf.php
           fi
           yum -y update

  IPAddress:
    Type: AWS::EC2::EIP
  IPAssoc:
    Type: AWS::EC2::EIPAssociation
    Properties:
      InstanceId: !Ref EC2Instance
      EIP: !Ref IPAddress
  WebSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: Allow SSH and HTTP connections to EC2 instance
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: "WebTier-sg"
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: !Sub ${LocalGIP}/32
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: !Sub ${LocalGIP}/32
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          SourcePrefixListId: pl-08d491d20eebc3b95
          Description: Allow EC2 Instance Connect
  DBSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow connections only from Webserver
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: "DBTier-sg"
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: 3306
        ToPort: 3306
        SourceSecurityGroupId: !GetAtt WebSecurityGroup.GroupId

  DBSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    Properties:
      DBSubnetGroupName: !Sub ${DatabaseName}-db-subnet-group
      DBSubnetGroupDescription: Subnet group for RDS MySQL
      SubnetIds:
        - !Ref SubnetID1
        - !Ref SubnetID2

  MyDB:
    Type: 'AWS::RDS::DBInstance'
    Properties:
      DBInstanceIdentifier: !Ref DBInstanceID
      DBName: !Ref DatabaseName
      DBInstanceClass: db.t3.micro
      AllocatedStorage: 20
      Engine: MySQL
      EngineVersion: 8.0.43
      MasterUsername: !Ref MasterUsername
      MasterUserPassword: !Ref MasterPassword
      DBParameterGroupName: !Ref RDSParameterGroup
      DBSubnetGroupName: !Ref DBSubnetGroup
      VPCSecurityGroups:
        - Fn::GetAtt: [ DBSecurityGroup, GroupId ]

  RDSParameterGroup:
    Properties:
      Description: "custom parameter group"
      Family: mysql8.0
      Parameters:
        character_set_server: utf8
        character_set_connection: utf8
        character_set_database: utf8
        collation_connection: utf8_general_ci
        collation_server: utf8_general_ci
      Tags:
        - Key: Name
          Value: "tut"
    Type: "AWS::RDS::DBParameterGroup"

Outputs:
  WebsiteURL:
    Value: !Sub 'http://${EC2Instance.PublicDnsName}/'
    Description: Webserver URL
  RDSEndpoint:
    Value: !GetAtt MyDB.Endpoint.Address
    Description: RDS DB instance endpoint
パラメータ: SubnetID

SubnetID は RDS のサブネットグループに明示指定したかったので、SubnetID1 と SubnetID2 に分けて2つ用意しました。

パラメータ: LocalGIP

Web アプリケーションのアクセス元制御のため、セキュリティグループで明示的にアドレスを絞り込めるようにローカル環境のグローバル IP アドレスを指定できるようにしました。

EC2 インスタンス

VPC とサブネット(SubnetID1)を明示的に指定させました。
また、セキュリティグループにはローカル環境のグローバル IP アドレスと、インスタンスコネクトでアクセスするためのインバウンド設定を追加しています。

RDS MySQL

データベースバージョンを 5.7.28 から 8.0.43 に上げました。
また、それに伴ってパラメータグループにも修正を入れています。

特に、データベースのエンコード関連は Web アプリケーション側が php5 系であったため、以下のブログ記事を参考にさせていただき、いくつか修正を入れています。

https://media.zenet-web.co.jp/entry/2021/10/04/183222

また、サブネットグループで利用するサブネットについても、パラメータで指定したサブネットを利用するようにしています。

スタックの作成

あとは、修正したテンプレートを利用してスタック作成をするだけです。
なお、パラメータの LocalGIP に指定するグローバル IP アドレスは、以下の URL にアクセスして確認しました。

https://checkip.amazonaws.com/

Step 2: Create Aurora Read Replica

Aurora リードレプリカ作成で、指定するパラメータは作成した RDS MySQL に準じて以下としました。

DB エンジンバージョン: Aurora MySQL 3.11.1 (compatible with MySQL 8.0.43)
DB インスタンスクラス: db.t3.large

また、「仮想プライベートクラウド (VPC)」、「サブネットグループ」、「VPC セキュリティグループ」、「DB パラメータグループ」には RDS 用に作成したものを指定するのを忘れないように注意します。

他はドキュメント通りで問題ないかと思います。

Step 3 以降

あとは、ドキュメント通りで問題なく実施可能です。

なお、「Step 5: Promote Aurora Read Replica to Standalone Cluster」で RDS MySQL インスタンスを停止しますが、「Clean up resources」で CloudFormation のスタック削除をする際には RDS が起動している必要がある ので、ここだけ注意が必要でした。

まとめ

データベースのバージョンの変更や、セキュリティグループの調整で少しハマってしまいましたが、一度 CloudFormation テンプレートでの調整が完了すれば簡単に実践できるチュートリアルでとてもよかったです。

特に、実際に RDS MySQL から Aurora MySQL へのニアゼロダウンタイム移行などは経験する機会はなかなか無いと思うので、このように公開されているチュートリアルがあってとてもありがたかったです。

今回のブログ記事がどなたかのお役に立てば幸いです。それでは!

クラスメソッドオペレーションズ株式会社について

クラスメソッドグループのオペレーション企業です。

運用・保守開発・サポート・情シス・バックオフィスの専門チームが、IT・AI をフル活用した「しくみ」を通じて、お客様の業務代行から課題解決や高付加価値サービスまでを提供するエキスパート集団です。

当社は様々な職種でメンバーを募集しています。

「オペレーション・エクセレンス」と「らしく働く、らしく生きる」を共に実現するカルチャー・しくみ・働き方にご興味がある方は、クラスメソッドオペレーションズ株式会社 コーポレートサイト をぜひご覧ください。※2026 年 1 月 アノテーション㈱から社名変更しました

この記事をシェアする

FacebookHatena blogX

関連記事