Skip to content

Instantly share code, notes, and snippets.

@anna-geller
Last active August 4, 2021 07:34
Show Gist options
  • Save anna-geller/75d42c7439021871817c3462e31cd97f to your computer and use it in GitHub Desktop.
Save anna-geller/75d42c7439021871817c3462e31cd97f to your computer and use it in GitHub Desktop.
import boto3
import pandas as pd
s3_bucket = "annageller"
html_file = "sales_report.html"
df = pd.DataFrame([{'year': 2021, 'month': 8, 'order_status': 'unavailable', 'order_count': 48},
{'year': 2021, 'month': 8, 'order_status': 'delivered', 'order_count': 7069},
{'year': 2021, 'month': 8, 'order_status': 'invoiced', 'order_count': 15},
{'year': 2021, 'month': 8, 'order_status': 'shipped', 'order_count': 74},
{'year': 2021, 'month': 8, 'order_status': 'canceled', 'order_count': 34},
{'year': 2021, 'month': 8, 'order_status': 'processing', 'order_count': 29}])
df.to_html(html_file, index=False)
s3 = boto3.client("s3")
s3.upload_file(
Filename=html_file,
Bucket=s3_bucket,
Key=html_file,
ExtraArgs={"ContentType": "text/html"},
)
shareable_url = s3.generate_presigned_url(
ClientMethod="get_object",
# ExpiresIn reflects time in seconds
ExpiresIn=3600,
HttpMethod="GET",
Params={"Bucket": s3_bucket, "Key": html_file},
)
# URL that you can share with others
print(shareable_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment