I currently have a Python lambda function that is returning a JSON object. However rather then getting a white screen with JSON data I was wondering if there is a way to return a html webpage that returns instead of JSON? Currently the return data looks like
return {
'statusCode': 200,
'headers': {},
'body': json.dumps({
'HOW-TO: ': prompt,
'instanceId': instanceId,
'PUBLIC_IP_ADDRESS': publicIp,
'instanceRegion':Instance_region
})
But was curious if there is a way to return an HTML page instead?
Yes you can, just define with AWS Python the right headers
"headers": {'Content-Type': 'text/html'}
as in the following example (please adjust the right Python identations)
def lambda_handler(event, context):
import json
longinformation = '''
<h1 style="color: #5e9ca0;">You can edit <span style="color: #2b2301;">this demo</span> text!</h1>
<h2 style="color: #2e6c80;">How to send HTML with AWS lambda in Python:</h2>
<p>Paste your documents in the visual editor on the left or your HTML code in the source editor in the right. <br />Edit any of the two areas and see the other changing in real time. </p>
'''
return {
"statusCode": 200,
"headers": {'Content-Type': 'text/html'}, #it really works by Hector Duran!
"body": longinformation
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With