Amazon Linux 2から Amazon ElastiCache for Redis にSSL接続する

本日はAmazon ElastiCache for Redisを作成し、Amazon Linux2から接続して見ます。

Amazon ElastiCache とは?

Amazon ElastiCache は完全マネージド型の Redis と MemCache と互換性のあるサービスで、最新のアプリケーション向けにコスト最適化されたパフォーマンスをリアルタイムで提供します。ElastiCache は、マイクロ秒の応答時間で 1 秒あたり数億回の操作までスケーリングでき、エンタープライズグレードのセキュリティと信頼性を提供します。

Amazon ElastiCache エンジンとは?

  • Redis
  • Memcached

ElastiCache for Redis の概要

Redisを使用する既存のアプリケーションは、ほとんど変更することなく ElastiCache を使用できます。アプリケーションに必要な情報は、デプロイした ElastiCache ノードのホスト名とポート番号だけです。

これから、Amazon ElastiCache for Redisを構築してから、接続してみます。

Amazon ElastiCache for Redis 作成

1.新規作成

「新しいクラスターを設定および作成」を選択
file

2.名前を任意入力

file

3.デフォルト設定のまま

file

4.クラスター設定

料金節約のため、レプリケーションは「0」に変更
file

5.サブネットグループを作成

名前任意入力でOK
file

6.「転送中の暗号化」選択する

※重要、チェックしないと、パスワード認証できない
file

7.その他の設定項目はデフォルト値

バックアップ とメンテナンス 等はデフォルト値のままでOK

file

8.作成

作成ボタンをクリックすると、しばらく下記の様に作成完了する

file

暗号化/認証が有効なクラスターへの接続

1.暗号化および認証が有効の接続確認

暗号化および認証が有効のクラスターに接続方法

src/redis-cli -h cluster-endpoint --tls -a your-password -p port number

次のような Redis のコマンドプロンプトが表示されますと、接続が成功

[ec2-user@ip-172-31-42-232 redis-stable]$ src/redis-cli -h master.redis-test.flnuf6.apne1.cache.amazonaws.com --tls -a 12345678901234aB? -p 6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?
master.redis-test.flnuf6.apne1.cache.amazonaws.com:6379>

2.暗号化のみ接続確認

次の例では、暗号化のみが有効なクラスターに接続方法

src/redis-cli -h cluster-endpoint --tls -p port number

次のような Redis のコマンドプロンプトが表示されますと、接続が成功

[ec2-user@ip-172-31-42-232 redis-stable]$ src/redis-cli -h master.redis-test.flnuf6.apne1.cache.amazonaws.com --tls -p 6379
master.redis-test.flnuf6.apne1.cache.amazonaws.com:6379>

3.コマンド実行確認

Redis コマンドを実行できるようになりました

master.redis-test.flnuf6.apne1.cache.amazonaws.com:6379> set x Hi
OK
master.redis-test.flnuf6.apne1.cache.amazonaws.com:6379> set y Hello
OK
master.redis-test.flnuf6.apne1.cache.amazonaws.com:6379> get y
"Hello"
master.redis-test.flnuf6.apne1.cache.amazonaws.com:6379> get x
"Hi"
master.redis-test.flnuf6.apne1.cache.amazonaws.com:6379>

注意

パスワード認証を有効にするために、「転送時の暗号化」を有効にする必要がある

 参考URL

https://docs.aws.amazon.com/ja_jp/AmazonElastiCache/latest/red-ug/nodes-connecting.html
https://docs.aws.amazon.com/ja_jp/AmazonElastiCache/latest/red-ug/GettingStarted.ConnectToCacheNode.html

Last modified: 2023-10-20

Author