본문 바로가기

Docker

docker awslogs UnrecognizedClientException: The security token included in the request is invalid.

docker-compose를 이용해 awslogs driver를 사용하는 경우, 그리고 aws 계쩡을 새로 옮길 경우, 단순히 aws key를 environment에 export를 하면 다음과 같은 에러가 난다.

 

 

그 이유는 docker는 docker engine에서 사용하는 config file이 따로 있기 때문이다.

그래서 docker engine이 사용하는 config file에서 aws key값이 저장되어 있을 텐데 그 값을 바꿔줘야 한다.

 

일단 안되는 이유가 key값이 안맞기 때문인지 확인하기 위해서 다음과 같은 명령어로 docker daemon의 현재 aws key environment값을 확인해보자.

systemctl show --property=Environment docker

 

만약 aws key 값이 맞지 않는다면, aws key 값을 config file에 적절히 넣고 daemon을 재시작해야한다.

 

docker가 init에 설치되어 있는지, systemd에 설치되어 있는지에 따라 차이가 있지만 대부분 systemd에 설치되어 있으므로(pstree를 이용해서 뿌리가 init인지, systemd인지 확인하면 된다.), /etc/systemd/system/docker.service.d/aws-credentials.conf 경로로 가서 aws key를 바꿔준 다음 daemon과 docker를 재시작한다.

sudo systemctl daemon-reload
sudo systemctl restart docker

 

다시 한번 docker environment 값을 확인해보고 맞다면 awslogs가 될 것이다.