DEV Community

How to system test with fixed time on Fargate

How do you perform system tests with fixed time on Fargate?

I considered logging into the container using the aws ecs execute-command and changing the time using the date command, but since privileged containers aren't supported on Fargate I get the following error occurred and I was unable to change it.

date: cannot set date: Operation not permitted

However, you can adjust the system time by using libfaketime. Although the version is old, the Dockerfile verified with Keycloak 19.0.2 image is shown below.

FROM AS builder

USER root

RUN microdnf install -y git make gcc
RUN git clone
WORKDIR /libfaketime/src
RUN make install
ENV LD_PRELOAD=/usr/local/lib/faketime/

ENV FAKETIME="2025-04-24 10:30:00"
RUN date

WORKDIR /opt/keycloak

ENTRYPOINT [ "/opt/keycloak/bin/" ]
Enter fullscreen mode Exit fullscreen mode

If you enter the container and execute the date command as shown below, you will see that the value specified by the FAKETIME variable is fixed.

% aws ecs execute-command --cluster _clustername_ --task _taskID_ --interactive --command "/bin/bash"

The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.

Starting session with SessionId: ecs-execute-command-xxxxxxxxx
[root@ip-NNN-NNN-NNN-NNN keycloak]# date
Thu Apr 24 10:30:00 UTC 2025
Enter fullscreen mode Exit fullscreen mode

Please try it yourself.

Top comments (0)