官术网_书友最值得收藏!

How to do it

We won't parse the data in the planets.html file, but simply retrieve it from the local web server using requests:

  1. The following code, (found in 03/S3.py), reads the planets web page and stores it in S3:
import requests
import boto3

data = requests.get("http://localhost:8080/planets.html").text

# create S3 client, use environment variables for keys
s3 = boto3.client('s3')

# the bucket
bucket_name = "planets-content"

# create bucket, set
s3.create_bucket(Bucket=bucket_name, ACL='public-read')
s3.put_object(Bucket=bucket_name, Key='planet.html',
Body=data, ACL="public-read")
  1. This app will give you output similar to the following, which is S3 info telling you various facts about the new item.

{'ETag': '"3ada9dcd8933470221936534abbf7f3e"', 'ResponseMetadata': {'HTTPHeaders': {'content-length': '0', 'date': 'Sun, 27 Aug 2017 19:25:54 GMT', 'etag': '"3ada9dcd8933470221936534abbf7f3e"', 'server': 'AmazonS3', 'x-amz-id-2': '57BkfScql637op1dIXqJ7TeTmMyjVPk07cAMNVqE7C8jKsb7nRO+0GSbkkLWUBWh81k+q2nMQnE=', 'x-amz-request-id': 'D8446EDC6CBA4416'}, 'HTTPStatusCode': 200, 'HostId': '57BkfScql637op1dIXqJ7TeTmMyjVPk07cAMNVqE7C8jKsb7nRO+0GSbkkLWUBWh81k+q2nMQnE=', 'RequestId': 'D8446EDC6CBA4416', 'RetryAttempts': 0}}
  1. This output shows us that the object was successfully created in the bucket. At this point, you can navigate to the S3 console and see your bucket:
The Bucket in S3
  1. Inside the bucket you will see the planet.html file:
The File in the Bucket
  1. By clicking on the file you can see the property and URL to the file within S3:
The Properties of the File in S3
主站蜘蛛池模板: 焦作市| 安仁县| 专栏| 子洲县| 巴中市| 双江| 宜城市| 河东区| 保山市| 于田县| 大冶市| 榕江县| 车致| 葫芦岛市| 宁德市| 临湘市| 新兴县| 威远县| 平乐县| 汝南县| 浦江县| 邹城市| 沈丘县| 镇江市| 万盛区| 邓州市| 湖口县| 大厂| 雷山县| 梨树县| 平塘县| 长海县| 霍城县| 乌鲁木齐市| 泾源县| 天等县| 行唐县| 遂宁市| 滦平县| 阿巴嘎旗| 普兰县|