Home > Enterprise >  Save HTML File to S3 bucket
Save HTML File to S3 bucket

Time:11-08

After converting a Plotly graph to an HTML Page by this code:

import plotly
import plotly.express as px

df = px.data.stocks()
fig = px.line(df, x='date', y="GOOG")


plotly.offline.plot(fig , filename = 'filename.html', auto_open=False)

How can I store this HTML Page on an S3 bucket?

I tried this code:

fig.write_html('testPage.html', auto_play=False)

But I'm getting this error:

 Read-only file system: 'testPage.html'

CodePudding user response:

Assuming you are running this into a lambda:

import boto3
import plotly
import plotly.express as px

df = px.data.stocks()
fig = px.line(df, x='date', y="GOOG")

file_name = 'testPage.html'
fig.write_html('/tmp/' file_name, auto_play=False)

s3_client = boto3.client('s3')
response = s3_client.upload_file('/tmp/' file_name, 'my-bucket', file_name)

Make sure the lambda has the right permission in place to upload the file into the s3 bucket.

CodePudding user response:

To get the latest code examples of all AWS SDKs, including Python, look at the new AWS Code Library here:

enter image description here

  • Related