使用aws lambda(Python)读取和写入aws s3 bucket中的html文件
我是AWS新手,我正在尝试从AmazonS3 bucket中检索Html文件,并使用AWS lambda python对其进行写入。我尝试使用urllib检索html文件,但无法写入/更新它。当前html文件包含基本的hello world文本,我想更新它以发布服务器的当前时间。有什么建议吗?我该如何写入该文件 非常感谢使用aws lambda(Python)读取和写入aws s3 bucket中的html文件,html,python-3.x,amazon-s3,aws-lambda,Html,Python 3.x,Amazon S3,Aws Lambda,我是AWS新手,我正在尝试从AmazonS3 bucket中检索Html文件,并使用AWS lambda python对其进行写入。我尝试使用urllib检索html文件,但无法写入/更新它。当前html文件包含基本的hello world文本,我想更新它以发布服务器的当前时间。有什么建议吗?我该如何写入该文件 非常感谢 import boto3 import urllib def lambda_handler(event, context): s3 = boto3.client(
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'
只需使用Python AWS SDK:
有一个关于如何读取文件的示例 请正确格式化您的代码