Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用aws lambda(Python)读取和写入aws s3 bucket中的html文件_Html_Python 3.x_Amazon S3_Aws Lambda - Fatal编程技术网

使用aws lambda(Python)读取和写入aws s3 bucket中的html文件

使用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(

我是AWS新手,我正在尝试从AmazonS3 bucket中检索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'

只需使用Python AWS SDK:


有一个关于如何读取文件的示例

请正确格式化您的代码