使用AWS Lambda(Python)在AWS S3存储桶中读取和写入HTML文件

时间:2018-08-05 04:26:38

标签: html python-3.x amazon-s3 aws-lambda

我是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'

1 个答案:

答案 0 :(得分:1)