色々と応用できそうなので残しておきます。
環境
Python3.7
API Gateway プロキシ統合あり
処理
import boto3
import os
# バケット名は環境変数から取得
BUCKET_NAME = os.environ['BUCKET_NAME']
s3 = boto3.resource('s3')
filepath = '/tmp/hogehoge.html'
def main(event, context):
bucket = s3.Bucket(BUCKET_NAME)
bucket.download_file('hogehoge.html', filepath)
with open(filepath , encoding='utf-8') as f:
html = f.read()
return {
"statusCode": 200,
"headers": {"Content-Type": "text/html"},
"body": html
}