Tiny Rails Tipp: Check S3 Credentials
Hello! Today, I had to switch out some AWS S3 credentials. We had them in ENV
variables in Heroku, but we got new ones and are now saving them in the credentials.yml.enc
file.
After the deploy, I wanted to make sure the new credentials still work. Since we use the credentials for ActiveStorage, I went to the Rails Console on Heroku and entered this to download a "random" ActiveStorage file from S3:
ActiveStorage::Attachment.take.blob.download_chunk(0..0)
=> "%"
The %
means: Success! (It also means that we only download the first byte of the file, since it's all we need to check the credentials.)
If it didn't work, we'd get some kind of error instead:
Aws::S3::Errors::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
Now you know!