はじめに
RDSへの接続確認のため、Privateサブネットに配置したEC2インスタンスにMySQLをインストールしようとしたらエラーでハマったので対応方法をまとめる。
事象
Privateサブネットに配置したEC2(Amazon Linux2)にMySQLをインストールしようとしたところ、下記のエラーが発生してインストールできない
sudo yum -y install mysql
Could not retrieve mirrorlist https://amazonlinux-2-repos-ap-northeast-1.s3.dualstack.ap-northeast-1.amazonaws.com/2/core/latest/x86_64/mirror.list error was
12: Timeout on https://amazonlinux-2-repos-ap-northeast-1.s3.dualstack.ap-northeast-1.amazonaws.com/2/core/latest/x86_64/mirror.list: (28, 'Connection timeout after 5000 ms')
One of the configured repositories failed (不明),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot find a valid baseurl for repo: amzn2-core/2/x86_64
原因
Amazon Linux2のyumリポジトリはS3上に存在しているが、そのリポジトリにアクセスできていない。
対応方法
s3へのVPCエンドポイントを作成後にyum install
する。
- VPC > VPCエンドポイント > エンドポイントを作成を選択
- タイプは「AWSのサービス」を選択
- サービス名は
com.amazonaws.ap-northeast-1.s3
、タイプがGateWay
のものを選択 - ルートテーブルの設定はEC2インスタンスが含まれるサブネットのルートテーブルを選択
おわりに
VPCエンドポイントの存在を初めて知った。
GateWayタイプは無料だが、Interfaceタイプは有料らしい。
違いについても機会があれば調べてみたい。
参考