lambda local - a local server for developing aws lambda function in java

26
使 AWS Lambda 開發 Rest Services 馮彥永 Zaoo

Upload: yenwen-feng

Post on 16-Apr-2017

933 views

Category:

Software


1 download

TRANSCRIPT

使⽤用 AWS Lambda

開發 Rest Services

馮彥永

Zaoo

馮彥永 Tempo

• 2012. Cubie

• 2008. Gamelet

• 2004. Willmobile

• http://fb.me/tempofeng, http://tempo.tw

•產品開發週報 http://fb.me/pdwtaiwan

AWS Lambda

• Launched on 2014

• Run code without provisioning or managing servers -

Serverless

• Supported Node.js, Java, C#, Python

• Why?

• Billed by 100ms (and by memory usage)

• Easier

AWS Lambda - Applications

AWS Lambda - Applications

AWS Lambda - Applications

Hello World! - HTTP

Hello World! - Packaging

Hello World! - Deployment

Hello World! - Testing

Hello World! - Pojo

Hello World! - API Gateway

Hello World! - API Gateway

AWS Lambda Proxy Integration

• Wiring between API Gateway and Lambda is hard!

• Lambda Proxy integration

• Remember to Deploy API!

• http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-

up-simple-proxy.html#api-gateway-simple-proxy-for-lambda-input-format

AWS Lambda Proxy Integration

AWS Lambda - Details

• AWS Lambda Log4j Appender

• http://docs.aws.amazon.com/lambda/latest/dg/java-logging.html

• Server Logs

• AWS CloudWatch logs for Humans™

• https://github.com/jorgebastida/awslogs

AWS Lambda - Details

• Object Serialization

• Plain Objects

• Lambda Proxy Integration is better!

• Api Gateway is hard: Returning HTML, Response Headers, Content-Type, …

• Lambda Proxy Integration is better!

• Local testing

• Unit tests only 😢

Lambda-Local

• https://github.com/tempofeng/lambda-local

• Runs AWS Lambda on your local machine

• Uses syntax like Spring MVC (or Retrofit) to

build Rest Services

• Using Jackson for JSON ⇆ Java

• Migrates AWS Lambda Functions back to

Beanstalk or other Application Servers

Lambda-Local - Hello World

Lambda-Local - Running on Local Machine

Lambda-Local - Object Mapping

Lambda-Local - Path Parameters

Lambda-Local - CrossOrigin

Lambda-Local - Running on Lambda

Thoughts on AWS Lambda

• Dagger vs Spring Framework (IoC Container)

• Start up time

• 5sec

• Using sentry.io to collect exceptions

• Cloudwatch

• Running new services without any cost

• Beanstalk → AWS Lambda

Lambda-local

• Lambda-Local

• https://github.com/tempofeng/lambda-local

• Examples today

• https://github.com/tempofeng/lambda-local-talk

• Suggestions

• email: [email protected]

• Facebook: fb.me/tempofeng