Heroku app uploads only once w/ AWS S3 security credentials - heroku

Heroku app gives a error message to have a look at the logs and heroku logs --tail shows 401 error or writes simply "idle" when uploading a file to amazon S3. Once I have seen SQL statement for inserting file into MariaDB. What's this all about?
I changed the AWS S3 security credentials, both in AWS console and in my heroku environment. Then the upload works for one single time.
Expected: AWS S3 upload works permanently.
Actual: file gets uploaded only once.
leder#DESKTOP-M6L5EDG:~$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
leder#DESKTOP-M6L5EDG:~$ rails -v
Rails 5.1.2
leder#DESKTOP-M6L5EDG:~$

Related

Inspect Heroku local logs

I have an app that's deployed to production, but I'm also testing it locally.
When I run heroku logs --tail, I get the production logs. I can see when I make a request to the webapp and it shows up instantly in the logs.
However, my app on heroku local returns me a "500 Server Error." I want to inspect these logs to understand why. However, I can't find these logs. Is there a command like heroku local logs --tail?
In order to see logs in IDE or Console use below command
Local:
I'm using Python script and the same deployed in heroku. I want to run locally by using heroku local command and would like to see logs in console but it is not showing logs in IDE Console. So for workaround i tried below command and it works well. Now I can see logs in the IDE itself.
E.g. for Python Script:
heroku local:run python test.py
E.g. for Rails:
heroku local:run rails console
Production:
heroku logs --tail --app <app-name>

On deploy, Heroku says it can't find API key even though I've logged in

When I run heroku deploy:jar app.jar --app app, I receive this error:
$ heroku deploy:jar build/libs/app.jar --app app
Uploading app.jar
-----> Packaging application...
- app: app
- including: build/libs/app.jar
! ERROR: Could not get API key! Please install the toolbelt and login with `heroku login` or set the HEROKU_API_KEY environment variable.
! Re-run with HEROKU_DEBUG=1 for more info.
▸ There was a problem deploying to app.
▸ Make sure you have permission to deploy by running: heroku apps:info -a app
Here's there environment's information:
On a Mac.
Heroku version: heroku-cli/6.16.12 (darwin-x64) node-v9.11.1
Heroku plugins: heroku-cli-deploy 0.4.0
java version "1.8.0_131"
node version: v4.9.1
I've tried running heroku login multiple times. After it's run, I can run heroku apps:info -a app and it lists the information. I'm inferring that that means I'm logged in already.
My login works on another computer, so I assume it's a local config issue and not an account issue. When I set HEROKU_DEBUG=1, it provides no additional information.
The issue lay in heroku login. It creates a file ~/.netrc containing your login and token.
The format of this generated file on another mac (the mac I mentioned the deploy was working fine) was as follows:
machine api.heroku.com
password ...
login ...
machine git.heroku.com
password ...
login ...
The format of the same generated file on the mac which was giving the above problem was as follows:
machine api.heroku.com login ... password ...
machine git.heroku.com login ... password ...
Apparently, both formats are fine for most Heroku commands such as viewing apps and such. But for the deploy command (which requires the heroku-cli-deploy plugin, only the first format is acceptable.
So basically the heroku cli accepts both new lines and spaces as delimiters between the endpoint, login, and token. But the deploy plugin only accepts new lines. heroku login was using spaces for some reason; so heroku commands were working, while the heroku deploy commands were not.
There would be another reason for the same error in Ubuntu. For some reason in Ubuntu it is easy to make jhipster cli installation that requires sudo while heroku cli don't allow to log in under sudo because browser start doesn't work from the sudo call. And it is uneasy to figure out, what was wrong with jhipster sudo installation, which particular files now owned by the root and so on.
But if you have logged to heroku cli not from the root user (i.e not using sudo) or created api key variable not from root user (i.e not using sudo) your deploy will fail with the error above if you'll request jhipster with sudo:
sudo hipster heroku
if you'll try it without sudo, it will hang on
Installing Heroku CLI deployment plugin
To make it working just run
sudo -E jhipster heroku
and -E will pass your api key variable to the sudo execution

Amazon Web Services secret key & id not being found in my bash profile when pushing cloned Rails 4 S3 app to Heroku

I have an application I built that pushes images to Amazon S3 using Carrierwave. I forked and cloned that repo on Github. When trying to push it as a new application to Heroku, Heroku keeps throwing an error that it can't find my Amazon S3 secret key and ID and aborts the push. I have the original Secret Key and ID in my bash profile and pushing to heroku worked with that setup. I can't figure out why it isn't working with my clone of the application.
You need to set configuration varibles via heroku config:set KEY=VALUE for them to be available on Heroku
Read more at https://devcenter.heroku.com/articles/config-vars

No such file 'config/database.yml' on Heroku

My app is a Ruby rack app. When my Heroku app starts it breaks because
/app/config.ru:8:in `read': No such file or directory - config/database.yml (Errno::ENOENT)
Why does this happen? I understood Heroku is meant to create this file https://devcenter.heroku.com/articles/cedar-migration
The database credentials will still be configured automatically: at slug compile time, a config/database.yml that parses the DATABASE_URL from the environment will be written into the app.
Frustratingly the doc at https://devcenter.heroku.com/articles/ruby doesn't explain about database.yml
Ok, the first thing - heroku does not use database.yml file. By default rails app loading it from config/ directory automatically. And it's no need to load it manually in config.ru. If you want to use in heroku PosgreSQL - just add add-on. Heroku wil do all other things to link your app and db. If you want to use external MySQL server you should use Amazon RDS add-on
heroku addons:add amazon_rds url=mysql2://user:pass#dbhost/dbname
By this you can use any db. I use GoDaddy mysql bases through the Amazon RDS add-on.
Any way, the problem in your config.ru 8th line something like
read 'config/database.yml'
Delete it and look other ways that not conflicted with heroku
Good luck
It appears Heroku only creates its config/database.yml if you have a folder config under source control. Not explained in docs.

Heroku with sinatra does not have RAILS_ROOT or Rail.root

I'm trying to upload file to amazon s3 and apparently I have to write to a temp file first then upload that file. But I cannot figure it out how to do that with Sinatra and heroku since it cannot find "#{RAILS_ROOT}" or #{Rail.root} how do I upload temp file to sinatra with heroku.
Thanks
I'm assuming you have read through Heroku's docs for Uploading to S3. The temp directory path on Heroku is ./tmp. If you are running Sinatra, Heroku likely does not create the environment variables related to Rails (although it may, I'm not sure). Here is more info on Heroku's file system.
EDIT: In Sinatra, you can get the root directory via settings.root, similar to RAILS_ROOT.

Resources