Amazon Web Services

[Sample] 초심자를 위한 AWS Lambda 의 Hello World 코드.(Python3, HTML)

혀뇽뇽이·2019년 3월 20일·조회 4,416

 Lambda로 Python을 기본 생성하면, 파일 Dump하는 코드만 생성된다.

 Python에 낯설기도 하고 Lambda도 낯선 초심자라면 다음의 코드로 

 HTML로 Hello World를 출력하는 Python 코드를 Lambda에 짤 수 있다.

def lambda_handler(event, context):
    response = {
        "statusCode": 200,
        "statusDescription": "200 OK",
        "isBase64Encoded": False,
        "headers": {
            "Content-Type": "text/html; charset=utf-8"
        }
    }

    response['body'] = """<html>
        <head>
            <title>Hello World!</title>
            <style>
                html, body {
                    margin: 0; padding: 0;
                    font-family: arial; font-weight: 700; font-size: 3em;
                    text-align: center;
                }
            </style>
        </head>
        <body>
            <p>Hello World!</p>
        </body>
        </html>"""
    return response


댓글 0

로그인 후 댓글을 남길 수 있습니다.

아직 댓글이 없습니다.