title: How to store text file with utf-8 encoding into AWS S3 bucket?
body: <p>I am just wondering how to write a text file encoded with utf-8 into AWS S3 directly, without needing to save that text file (temporarily or not) into local computer. To be concrete, as shown below, I think I could manage to save the file, which was downloaded from the web and was parsed with BeautifulSoup library locally, and to store that file into the designated S3 bucket. </p>
  
  <pre><code>import codecs
  import boto3
  import requests
  from bs4 import BeautifulSoup
  
  url = 'https://www.sec.gov/Archives/edgar/data/732247/0000950144-00-012588.txt'
  r = requests.get(url)
  
  soup = BeautifulSoup(r.content, "lxml")
  text = soup.get_text("\n")
  
  txt_path = 'report.txt'
  
  # Saving the parsed file into local directory in the name of 'report.txt'
  with codecs.open(txt_path, 'w', encoding='utf-8') as fout:
      fout.write(text)
  
  
  # Loading the parsed file 'report.txt' and saving it into AWS S3
  # with the 'my-bucket-name' as the bucket name 
  # and 'report_s3.txt' as the file name in that bucket
  s3 = boto3.resource('s3')
  with codecs.open('report.txt', 'rb', encoding='utf-8') as fin:
      text = fin.read()
  s3.Object('my-bucket-name', 'report_s3.txt').put(Body=text)
  </code></pre>
  
  <p>But, I would like to skip that local-saving process and want to directly save that parsed file with utf-8 encoding into S3 bucket. Is there any good idead to do that? Thank you in advance!</p>