Well, have you tried running the rake task by providing these environment variables?
DISCOURSE_S3_BUCKET=blablabla \
DISCOURSE_S3_REGION=blablabla \
DISCOURSE_S3_ACCESS_KEY_ID=blabalbal \
DISCOURSE_S3_SECRET_ACCESS_KEY=blablabla \
rake uploads:migrate_to_s3