AWS Lambda using python

AWS Lambda?



can make running your application(code),
without server - serverless

서버를 따로 만들지 않고 어플리케이션(코드)을 구현 가능 - 서버리스 



AWS Lambda using python

def my_handler(event, context):
    message = 'Hello {} {}!'.format(event['first_name'], 
                                    event['last_name'])  
    return { 
        'message' : message
    }  
This example has one function caller

handler

서비스를 요청받을때 실행될 함수입니다. 
handler, which is a function in your code, that AWS Lambda can invoke when the service executes your code.

event

evenet 파라미터를 통해 데이터를 람다함수에 전달할 수 있습니다. 
주로 파이썬 딕셔너리 타입이며, 그외의 list, str, int, float 혹은 None 타입또한 가능합니다. 
AWS Lambda uses this parameter to pass in event data to the handler. This parameter is usually of the Python dict type. It can also be liststrintfloat, or NoneType type.

context


람다 내부적으로 사용되기도하며 이 값에 요청한 사용자에게 반환값을 저장할 수 있습니다. 
 AWS Lambda uses this parameter to provide runtime information to your handler. For details,Optionally, the handler can return a value.
해당 자세한 내용은 아래를 참조하시길 바랍니다.
please see detail below
(http://docs.aws.amazon.com/ko_kr/lambda/latest/dg/python-programming-model-handler-types.html)

HOW TO SETUP?https://ndb796.tistory.com/293

위의 방법 외에도 local 에서 코드 작성후 패키지와 합께 압축하여 업로드
또한aws-cli 를 이용하여 모든과정 진행등 다양한 루트가 있습니다.
threre are many other way to using aws-lambda service


혹은 zappa를 사용할수 있습니다.
zappa는 lambda로 api를 서비스하기 위한 일련의 과정(api gateway, aws lambda, role,..)을 셋팅해주는 툴(?) 입니다.
단순히 python으로 작성한 flask 웹어플리케이션 작성하여 zappa deploy 와같은 명령어 하나면 모든 셋팅이 끝납니다. 
on other way, there is a super easy thing , which is 'zappa' that make deployment auto
what you have to do is just write python-flask or python-django web application!
then zappa deploy that application to aws lambda and setting all of others


이러한 과정까지도 너무너무 귀찮기 때문에 ... 개인적인 목적으로 zappa사용을 위한 프로젝트 구조를
이래저의 레포지토리에서 확인할 수 있습니다. 코드로 직접 보시면 이해가 빠르실겁니다.
https://github.com/heewinkim/zappa-framework

for me, these thing still too annying.. So i make a zappa wrapping framkework for me.
with this, all i have to do is make 'python function' that return dict(json) object. 


다만 역시 aws lambda는 용량 제한이 커서.. 저는 다른 서버리스 프레임워크를 고려하고 있습니다.
lastly, aws lambda's upload size limit is too small, so i'll study other serverless platform later




댓글