我是AWS的新手,我正尝试从amazon s3存储桶中检索HTML文件,并使用aws lambda python对其进行写入。我曾尝试使用urllib检索html文件,但无法对其进行写入/更新。当前html文件包含基本的hello world文本,我想对其进行更新以发布服务器的当前时间。有什么建议可以写入该文件吗?
非常感谢
import boto3
import urllib
def lambda_handler(event, context):
s3 = boto3.client('s3')
response = s3.list_buckets()
buckets = [bucket['Name'] for bucket in response['Buckets']]
print("Bucket Name: %s" % buckets)
bucket_url = urllib.request.urlretrieve("https://s3.us-east-2.amazonaws.com/testbucket/index.html","index.html")
#print(index.html)
#sock = urllib.request.urlopen("https://s3.us-east-2.amazonaws.com/testbucket/index.html")
#htmlsource = sock.read()
#print(type(htmlsource))
#print(htmlsource)
from datetime import datetime
# TODO implement
print(datetime.now().time())
return 'Hello from Lambda'
答案 0 :(得分:1)
只需使用Python AWS开发工具包:https://boto3.readthedocs.io/en/latest/reference/services/s3.html
https://boto3.readthedocs.io/en/latest/guide/s3-example-download-file.html有一个有关如何读取文件的示例。