Currently S3 documentation with compose file reports:
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} # Read AWS secrets from environment (or a .env file)
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
but .env file is not supported with a Stack deployment over Swarm. Instead, Swarm implements Secrets that would be a better solution for security purpose.
Use of them have to be implemented with the application, reading for example from /run/secrets/aws_access_key_id and /run/secrets/aws_secret_access_key, because secrets are not injectable directly from docker-stack.yml into environemnt.