Search

[TroubleShooting] AWS ElastiCache

Date
2025/03/12
Category
Devops
Tag
AWS
SpringBoot
목차

문제 개요

개발 환경: 로컬에서는 Docker로 실행한 Redis(v 7.4.2)를 사용한 Spring Boot 애플리케이션이 정상 동작
배포 환경: AWS ElastiCache(Redis 7.1)를 사용하여 EC2에 배포한 애플리케이션에서 Redis와의 연결 시 에러 발생
주요 에러 메시지:
ERR unknown command 'CONFIG', with args beginning with: 'GET' 'notify-keyspace-events'
SQL
복사
Spring Boot 애플리케이션 시작 시 redisKeyValueAdapter 빈 초기화 중에 위와 같은 에러가 지속적으로 발생

문제 원인

명령어 제약

AWS ElastiCache는 보안상의 이유로 기본적으로 CONFIG 명령어의 사용을 제한 (참조: Spring Docs)
The keyspace notification message listener alters notify-keyspace-events settings in Redis, if those are not already set. Existing settings are not overridden, so you must set up those settings correctly (or leave them empty). Note that CONFIG is disabled on AWS ElastiCache, and enabling the listener leads to an error. To work around this behavior, set the keyspaceNotificationsConfigParameter parameter to an empty string. This prevents CONFIG command usage.
Spring Data Redis에서는 keyspace 이벤트를 활성화하기 위해 CONFIG GET notify-keyspace-events 명령어를 호출하는데, 이 명령어 호출이 AWS ElastiCache 환경에서 실패

해결 방법

해결 1: AWS ElastiCache 파라미터 그룹 수정

조치 내용:
AWS ElastiCache의 Parameter Group에서 notify-keyspace-events 값에 AKE를 추가해 keyspace 이벤트 관련 설정을 활성화 (참조: AWS Knowledge Center)
결과:
파라미터 그룹 수정 후에도 CONFIG 명령어 호출 자체가 차단되어 동일한 에러가 계속 발생

해결 2: 클라이언트 측에서 CONFIG 명령어 호출 비활성화

조치 내용
Spring Boot 애플리케이션에서 RedisRepository를 사용 시, 기본적으로 keyspace 이벤트 활성화를 위해 @EnableRedisRepositories 어노테이션에 설정된 enableKeyspaceEvents 옵션이 작동하면서 CONFIG 명령어가 호출됨
이를 해결하기 위해 어노테이션에 추가 옵션인 keyspaceNotificationsConfigParameter 값을 빈 문자열("")로 지정하여 CONFIG 명령어 호출을 무력화
@EnableRedisRepositories( enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP, keyspaceNotificationsConfigParameter = "" )
Java
복사
결과
코드 수정 후 애플리케이션을 재가동하자, AWS ElastiCache Redis와의 통신이 정상적으로 이뤄짐

결론

AWS ElastiCache와 같은 관리형 Redis 서비스는 보안과 안정성 차원에서 일부 명령어 사용을 제한한다.
따라서 Spring Data Redis를 사용하는 경우, keyspace event 활성화와 관련된 설정을 직접 조정하거나 비활성화하는 방법을 고려해야 한다.

참조