I am trying to set my Bluemix VCAP_SERVICES
environment variable locally, but I'm getting this error in the terminal:
NoSQL: command not found
Steps to reproduce
- Login to Bluemix.net
- Deploy a hello world flask application
- Bind a Bluemix Cloudant Service to the application
- Copy the
VCAP_SERVICES
Environment Variables from the Runtime / Environment Variables on the application for Python - In local editor remove all the line breaks on Mac terminal
vi ~/.bash_profile
- Enter insert mode with
i
paste in
VCAPSERVICES
, mine looks like this:VCAP_SERVICES="{"VCAP_SERVICES":{"cloudantNoSQLDB": [{"credentials": {"host": "fakehostc-bluemix.cloudant.com","password":"fakepassword4da6de3a12a83362b26a","port": 443,"url": "https://fakeURLc-bluemix:fakeab96175c-bluemix.cloudant.com","username": "fakeusername-b749-399cfbd1175c-bluemix"},"label":"cloudantNoSQLDB","name":"Cloudant NoSQL DB-p2","plan":"Lite","provider":null,"syslog_drain_url":null,"tags":["data_management","ibm_created","ibm_dedicated_public"]}]}}" export VCAP_SERVICES
Save the file and quit
vi
with:wq!
- Source the modified file with
. ~/.bash_profile
to set the terminal window with the new VCAP Environment Variable
What am I doing wrong copying and setting my local Bluemix VCAP_Services Environment Variable?
If I copy the whole thing I get errors that the line is too long. How can I easily copy and paste the entire Bluemix Python Runtime VCAP_SERVICES
Variable into my local Mac .bash_profile
environment settings without manually massaging JSON and all these line breaks etc?
I don't want to use a local file to store those since it isn't very secure as I move from dev, test, staging and production.
I figured out the answer use single quotes at the beginning and end of VCAP_SERVICES
Here is the corresponding code to retrieve VCAP Services environment variables and do basic operations on Cloudant:
It's an anti-pattern to create the VCAP_SERVICES env variable locally. I suggest just using the connecting info when running locally.
Option 1
Option 2
If you don't want to hardcode credentials into your code, then you can create a
.env
file:and in your python code:
and then
source .env
before you run your application.Be sure to add
.env
to.gitignore
and.cfignore
There is a cf CLI plugin that will get VCAP_SERVICES from your app and help you set it locally. I've used it on my Mac and didn't have to adjust the quotes at all.
Checkout https://github.com/jthomas/copyenv