Serverless
LINE
KEVIN LUO
Outline
• LINE Chatbot Enabler - Messaging API
• Serverless Architecture
• Charbot architecture on AWS
• Implementation & Deployment
Who AM I
• Chasing New Technologies
• Principal Application
Analyst @LINE
• Service/Solution
Architecture, BigData,
Software Engineering,
• @Youku @miiiCasa
@Yahoo!Kimo
Messaging API
What’s New
• New Features

• API Design

• Beacon Event
3 New Features
GROUP
/CHAT
Group/Room
Event
Organiser
3 New Features
NEW
MESSAG
E
TYPE
GROUP
/CHAT
Confirm Button Carousel
Imagemap
• Multiple
areas
• Different
actions
More Template Messages
• Template message is HTML type
message
• Develop more templates
• Even work with partners
3 New Features
REPLY
/PUSH
NEW
MESSAG
E
TYPE
GROUP
/CHAT
Reply / Push
user send message
Reply from bot
Push from bot
ne
How Does It Work?
LINE
APP
(channel
)
webhook (https)
API call (https)response (https)
request (https)
Your Bot
LINE
Bot
Platform
API Design
Improvement
Intuitive & Simplicity & Secure
Messaging API Bot API (Deprecated)
Developer Trial Account Trial Account
Webhook event object
Receiving message
Receiving operation
Imagemap message Rich message
Reply message Sending message
Push message Sending message
Template message n/a
Reply token n/a
User_id (different from each Bot provider) Mid
Webhook Event Object
Message Text, Image, Audio, Video, Sticker, Location
Follow Added as friend
Unfollow Blocked
Join Join group/room
Leave new Leave group/room
Postback new From template action
Beacon new Got beacon signal
Location Event Object
Postback Event Object
Push Message
Additional APIs
• Get Content
• GET https://api.line.me/v2/bot/message/
{messageId}/content
• Get Profile
• GET https://api.line.me/v2/bot/profile/
{userId}
SDK Support
• Easily use
• Wrap up data parsing
• Simplify message composing
• Many languages
• https://github.com/line/
Develop NOW !!!
(App) https://business.line.me
(Bot) https://developers.line.me
(Bot) https://admin-official.line.me
Terms & Relationship
Personal LINE Account
Business
LINE OA
BC(Business
Connect)
LINE @
Messaging API
Login & Add Company
https://business.line.me/en/
Bot Settings
Features
Disabled:
1-on-1
Enable
Channel
Channel ID
Channel
Webhook URL
Channel Access
Serviceless
Architecture
What is Serverless?
• NOT no servers, NO maintenances
(setup, monitor, scale, security…)

• Development focus on functions 

• No always-on servers
Example - From
Example - To
Pros
• Reduced Operation Cost

• Reduced Development Cost

• Scaling Cost

• Time to market/Experimentation
Cons
• Vendor Control

• Multi-tenancy

• Vendor Lock-in

• Security Concerns

• No in-server state

• Startup Latency
Serverless in AWS
AWS Lambda
• Deploy functions in Java, Python,
Node.js, C#

• Build-in scalability and high availability

• Well integrated with other AWS services

• Pay as you go
What can you do with AWS
Lambda?
• Build event-driven applications

• Build APIs together with Amazon API
Gateway

• Restful APIs

• Resources, methods
Service Architecture
Setup & Configuration
A simple Lambda function in
Python"
• aws lambda create-function --function-name add --
handler myFunc.lambda_handler --runtime python2.7 --
zip-file fileb://myFunc.zip --memory-size 128 --role
arn:aws:iam::ACCOUNT_NUMBER:role/lambda_basic_execution 

• curl -H "Content-Type: application/json" -X POST -d
"{"value1":5, "value2":7}" https://API_ENDPOINT
That’s great, but…
• No one wants to code in the AWS console (right?) 

• Managing functions with the AWS CLI isn’t dev-friendly 

• Managing APIs with the AWS CLI quite complex (low-
level calls) 

• CloudFormation doesn’t make it easy to deploy and
manage serverless applications (custom resources) 

• So what are the options?
Serverless Tools
• Development

• Serverless Framework

• Gordon

• AWS Chalice

• More frameworks: Kappa, Apex, Zappa, Docker-lambda

• AWS Lambda plugin for Eclipse 

• Deployment 

• AWS Serverless Application Framework (SAM)
Development
https://github.com/xfalcons/serverless-aws
The Severless Framework
• Announced at re:Invent 2015 by Austen Collins and Ryan
Pendergast 

• Supports Node.js, as well as Python and Java (with restrictions) 

• Auto-deploys and runs Lambda functions, locally or remotely 

• Auto-deploys your Lambda event sources: API Gateway, S3,
DynamoDB, etc. 

• Creates all required infrastructure with CloudFormation 

• Simple configuration in YML
https://serverless.com
Serverless: standalone function
$ serverless create --template aws-python
Edit handler.py, serverless.yml
$ serverless deploy
$ serverless invoke 

[ local ]

--function function_name
$ serverless logs --function function_name
Gordon
• Released in Oct’15 by Jorge Batista 

• Supports Python, Javascript, Golang, Java, Scala, Kotlin
(including in the same project) 

• Auto-deploys and runs Lambda functions, locally or remotely 

• Auto-deploys your Lambda event sources: API Gateway,
CloudWatch Events, DynamoDB Streams, Kinesis Streams, S3 

• Creates all required infrastructure with CloudFormation 

• Simple configuration in YML
https://github.com/jorgebastida/gordon
Gordon: “Hello World” API
$ gordon startproject helloworld
$ gordon startapp helloapp
Write hellofunc() function
$ gordon build
$ echo '{"name":"Julien"}' | gordon run helloapp.hellofunc
$ gordon apply --stage stage_name
$ http post $API_ENDPOINT name=Julien
Zappa
"Think of it as "serverless" web hosting for your Python web apps"
• Just add your Python code 

• Deploy with a single call and zero config 

• The API is created automatically, the IAM policy is
auto-generated 

• Run APIs locally on port 8000 (similar to Flask) 

• Fast & lightweight framework 

• 100% boto3 calls (AWS SDK for Python) —> fast
https://github.com/awslabs/chalice
Zappa: “Hello World” API
Write your function in app.py
(flask or django)
$ zappa init
$ zappa deploy dev
$ zappa tail dev
Summing things up
Serverless 

• The most popular
serverless framework 

• Built with and for
Node.js. Python and
Java: YMMV 

• Rich features, many
event sources 

• Not a web
framework
Gordon

• Great challenger! 

• Node.js, Python,
Java, Scala, Golang 

• Comparable to
Serverless feature-
wise 

• Not a web
framework
Zappa 

• Python only 

• Does only one
thing, but does it
great 

• Dead simple, zero
config 

• Flask, Django web
framework
Deployment
AWS Serverless Application Model (SAM)
"formerly known as Project Flourish"
• CloudFormation extension released in Nov’16 to bundle Lambda functions, APIs & events 

• 3 new CloudFormation resource types 

• AWS::Serverless::Function 

• AWS::Serverless::Api 

• AWS::Serverless::SimpleTable 

• 2 new CloudFormation commands 

• aws cloudformation package

• aws cloudformation deploy

• Integration with CodeBuild and CodePipeline for CI/CD 

• Expect SAM to be integrated in most / all frameworks
Demo
- aws cli
- serverless
- zappa
https://github.com/xfalcons/serverless-aws
Thank you and Enjoy!

用Serverless技術快速開發line聊天機器人

  • 1.
  • 2.
    Outline • LINE ChatbotEnabler - Messaging API • Serverless Architecture • Charbot architecture on AWS • Implementation & Deployment
  • 3.
    Who AM I •Chasing New Technologies • Principal Application Analyst @LINE • Service/Solution Architecture, BigData, Software Engineering, • @Youku @miiiCasa @Yahoo!Kimo
  • 4.
  • 5.
    What’s New • NewFeatures • API Design • Beacon Event
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
    More Template Messages •Template message is HTML type message • Develop more templates • Even work with partners
  • 13.
  • 14.
    Reply / Push usersend message Reply from bot Push from bot ne
  • 15.
    How Does ItWork? LINE APP (channel ) webhook (https) API call (https)response (https) request (https) Your Bot LINE Bot Platform
  • 16.
  • 17.
  • 18.
    Messaging API BotAPI (Deprecated) Developer Trial Account Trial Account Webhook event object Receiving message Receiving operation Imagemap message Rich message Reply message Sending message Push message Sending message Template message n/a Reply token n/a User_id (different from each Bot provider) Mid
  • 19.
    Webhook Event Object MessageText, Image, Audio, Video, Sticker, Location Follow Added as friend Unfollow Blocked Join Join group/room Leave new Leave group/room Postback new From template action Beacon new Got beacon signal
  • 20.
  • 21.
  • 23.
  • 24.
    Additional APIs • GetContent • GET https://api.line.me/v2/bot/message/ {messageId}/content • Get Profile • GET https://api.line.me/v2/bot/profile/ {userId}
  • 25.
    SDK Support • Easilyuse • Wrap up data parsing • Simplify message composing • Many languages • https://github.com/line/
  • 27.
    Develop NOW !!! (App)https://business.line.me (Bot) https://developers.line.me (Bot) https://admin-official.line.me
  • 28.
    Terms & Relationship PersonalLINE Account Business LINE OA BC(Business Connect) LINE @ Messaging API
  • 29.
    Login & AddCompany https://business.line.me/en/
  • 34.
  • 36.
  • 37.
  • 38.
  • 39.
    What is Serverless? •NOT no servers, NO maintenances (setup, monitor, scale, security…) • Development focus on functions • No always-on servers
  • 40.
  • 41.
  • 42.
    Pros • Reduced OperationCost • Reduced Development Cost • Scaling Cost • Time to market/Experimentation
  • 43.
    Cons • Vendor Control •Multi-tenancy • Vendor Lock-in • Security Concerns • No in-server state • Startup Latency
  • 44.
  • 45.
    AWS Lambda • Deployfunctions in Java, Python, Node.js, C# • Build-in scalability and high availability • Well integrated with other AWS services • Pay as you go
  • 46.
    What can youdo with AWS Lambda? • Build event-driven applications • Build APIs together with Amazon API Gateway • Restful APIs • Resources, methods
  • 47.
  • 48.
  • 49.
    A simple Lambdafunction in Python" • aws lambda create-function --function-name add -- handler myFunc.lambda_handler --runtime python2.7 -- zip-file fileb://myFunc.zip --memory-size 128 --role arn:aws:iam::ACCOUNT_NUMBER:role/lambda_basic_execution • curl -H "Content-Type: application/json" -X POST -d "{"value1":5, "value2":7}" https://API_ENDPOINT
  • 50.
    That’s great, but… •No one wants to code in the AWS console (right?) • Managing functions with the AWS CLI isn’t dev-friendly • Managing APIs with the AWS CLI quite complex (low- level calls) • CloudFormation doesn’t make it easy to deploy and manage serverless applications (custom resources) • So what are the options?
  • 51.
    Serverless Tools • Development •Serverless Framework • Gordon • AWS Chalice • More frameworks: Kappa, Apex, Zappa, Docker-lambda • AWS Lambda plugin for Eclipse • Deployment • AWS Serverless Application Framework (SAM)
  • 52.
  • 53.
    The Severless Framework •Announced at re:Invent 2015 by Austen Collins and Ryan Pendergast • Supports Node.js, as well as Python and Java (with restrictions) • Auto-deploys and runs Lambda functions, locally or remotely • Auto-deploys your Lambda event sources: API Gateway, S3, DynamoDB, etc. • Creates all required infrastructure with CloudFormation • Simple configuration in YML https://serverless.com
  • 54.
    Serverless: standalone function $serverless create --template aws-python Edit handler.py, serverless.yml $ serverless deploy $ serverless invoke 
 [ local ]
 --function function_name $ serverless logs --function function_name
  • 55.
    Gordon • Released inOct’15 by Jorge Batista • Supports Python, Javascript, Golang, Java, Scala, Kotlin (including in the same project) • Auto-deploys and runs Lambda functions, locally or remotely • Auto-deploys your Lambda event sources: API Gateway, CloudWatch Events, DynamoDB Streams, Kinesis Streams, S3 • Creates all required infrastructure with CloudFormation • Simple configuration in YML https://github.com/jorgebastida/gordon
  • 56.
    Gordon: “Hello World”API $ gordon startproject helloworld $ gordon startapp helloapp Write hellofunc() function $ gordon build $ echo '{"name":"Julien"}' | gordon run helloapp.hellofunc $ gordon apply --stage stage_name $ http post $API_ENDPOINT name=Julien
  • 57.
    Zappa "Think of itas "serverless" web hosting for your Python web apps" • Just add your Python code • Deploy with a single call and zero config • The API is created automatically, the IAM policy is auto-generated • Run APIs locally on port 8000 (similar to Flask) • Fast & lightweight framework • 100% boto3 calls (AWS SDK for Python) —> fast https://github.com/awslabs/chalice
  • 58.
    Zappa: “Hello World”API Write your function in app.py (flask or django) $ zappa init $ zappa deploy dev $ zappa tail dev
  • 59.
    Summing things up Serverless • The most popular serverless framework • Built with and for Node.js. Python and Java: YMMV • Rich features, many event sources • Not a web framework Gordon • Great challenger! • Node.js, Python, Java, Scala, Golang • Comparable to Serverless feature- wise • Not a web framework Zappa • Python only • Does only one thing, but does it great • Dead simple, zero config • Flask, Django web framework
  • 60.
  • 61.
    AWS Serverless ApplicationModel (SAM) "formerly known as Project Flourish" • CloudFormation extension released in Nov’16 to bundle Lambda functions, APIs & events • 3 new CloudFormation resource types • AWS::Serverless::Function • AWS::Serverless::Api • AWS::Serverless::SimpleTable • 2 new CloudFormation commands • aws cloudformation package • aws cloudformation deploy • Integration with CodeBuild and CodePipeline for CI/CD • Expect SAM to be integrated in most / all frameworks
  • 62.
    Demo - aws cli -serverless - zappa https://github.com/xfalcons/serverless-aws
  • 63.