Dela filer via en webbplats

Introduktion till AWS Boto i Python

Maksim Pecherskiy

Data Engineer

Servera HTML-sidor

S3 som servar HTML

Introduktion till AWS Boto i Python

HTML-tabell i Pandas

Konvertera DataFrame till HTML

df.to_html('table_agg.html')

DataFrame till HTML

Introduktion till AWS Boto i Python

HTML-tabell i Pandas med länkar

Konvertera DataFrame till HTML

df.to_html('table_agg.html', render_links=True)

DataFrame till HTML

Introduktion till AWS Boto i Python

Vissa kolumner till HTML

Konvertera DataFrame till HTML

df.to_html('table_agg.html', 
           render_links=True,
           columns['service_name', 'request_count', 'info_link'])

DataFrame till HTML

Introduktion till AWS Boto i Python

Ramar

Konvertera DataFrame till HTML

df.to_html('table_agg.html', 
           render_links=True,
           columns['service_name', 'request_count', 'info_link'],
           border=0)

DataFrame till HTML med ramar

Introduktion till AWS Boto i Python

Ladda upp en HTML-fil till S3

Ladda upp en HTML-fil till S3

s3.upload_file(
  Filename='./table_agg.html', 
  Bucket='datacamp-website',

Key='table.html',
ExtraArgs = { 'ContentType': 'text/html', 'ACL': 'public-read'} )
Introduktion till AWS Boto i Python

Åtkomst till HTML-fil

Mall för S3-objektets URL

https://{bucket}.{key}
https://datacamp-website.table.html
Introduktion till AWS Boto i Python

HTML-sida

HTML-sida

Introduktion till AWS Boto i Python

Ladda upp andra innehållstyper

Ladda upp en bildfil till S3

s3.upload_file(
  Filename='./plot_image.png', 
  Bucket='datacamp-website',
  Key='plot_image.png',

ExtraArgs = { 'ContentType': 'image/png', 'ACL': 'public-read'} )
Introduktion till AWS Boto i Python

IANA-medietyper

  • JSON : application/json
  • PNG : image/png
  • PDF : application/pdf
  • CSV : text/csv
1 http://www.iana.org/assignments/media-types/media-types.xhtml
Introduktion till AWS Boto i Python

Generera en indexsida

# List the gid-reports bucket objects starting with 2019/
r = s3.list_objects(Bucket='gid-reports', Prefix='2019/')

# Convert the response contents to DataFrame objects_df = pd.DataFrame(r['Contents'])

Indexsida

Introduktion till AWS Boto i Python

Generera en indexsida

# Create a column "Link" that contains website url + key
base_url = "http://datacamp-website."
objects_df['Link'] = base_url + objects_df['Key']
# Write DataFrame to html
objects_df.to_html('report_listing.html', 
                   columns=['Link', 'LastModified', 'Size'],
                   render_links=True)

Generera en indexsida

Introduktion till AWS Boto i Python

Ladda upp indexsida

Ladda upp en HTML-fil till S3

s3.upload_file(
  Filename='./report_listing.html', 
  Bucket='datacamp-website',
  Key='index.html',
  ExtraArgs = {
    'ContentType': 'text/html', 
    'ACL': 'public-read'}
)

https://datacamp-website.index.html

Introduktion till AWS Boto i Python

Repetition

  • HTML-tabell i Pandas (df.to_html('table.html'))
  • Ladda upp HTML-fil (ContentType: text/html)
  • Ladda upp bildfil (ContentType: image/png)
  • Dela URL:en till vår HTML-sida!
Introduktion till AWS Boto i Python

Nu kör vi en övning!

Introduktion till AWS Boto i Python

Preparing Video For Download...