When authenticating to AWS, you may run into an issue where the error
token has expired is being returned. This issue can arise when stale credentials are being used for authentication.
- Solution - Removing cached configuration files
Two likely sources of this error are the Docker
credentialsfiles when cached or persisted on a self-hosted runner.
You can add run the following code snippet at the beginning of your job to remove these files.
- run: name: Remove config and credential files command: | if [ -f "$HOME/.docker/config.json" ]; then rm -f ~/.docker/config.json fi if [ -f "$HOME/.aws/credentials" ]; then rm -f ~/.aws/credentials fi
Following that, you can then proceed to authenticate by using a command such as the aws-ecr orb's
The stored credentials will be cleared, and you can then authenticate via the aws cli with the correct credentials.