Boris
Boris

Reputation: 11713

How to use Plotly Python SDK in AWS Elastic Beanstalk

I've been trying to install Plot.ly Python SDK, I have it included in the requirements.txt but still fails and I get a Page Not Found error when calling a page served by Flask.

Upvotes: 1

Views: 249

Answers (1)

Boris
Boris

Reputation: 11713

The problem with Plot.ly is that it requires the credentials to be installed:

import plotly 
plotly.tools.set_credentials_file(username='SomeDemoAccount', api_key='SomeAPIKey')

And this won't run in as a code, not from ssh in the console because the instance doesn't has access to the ~/.plotly/.credentials file, i.e. it can't create it nor access it, so any call to the API will always fail. In AWS logs you'll get the following error:

Looks like you don't have 'read-write' permission to your 'home' ('~') directory or to our '~/.plotly' directory. That means plotly's python api can't setup local configuration files. No problem though! You'll just have to sign-in using 'plotly.plotly.sign_in()'. For help with that: 'help(plotly.plotly.sign_in)'.

So the solution is to call the plotly.plotly.sign_in() method that it's not even mentioned in their getting started guide nor the API reference, and it must be called with following arguments:

plotly.plotly.sign_in("Your Plotly Username","Your Plotly API Key")

That I implemented by having those values as EB Environment Properties:

plotly.plotly.sign_in(os.environ['YOUR_PLOTLY_USERNAME_ENV_PROPERTY_NAME'],os.environ['YOUR_PLOTLY_API_KEY_ENV_PROPERTY_NAME'])

Upvotes: 1

Related Questions