Journey to Microservice architecture via Amazon Lambda

Preview:

Citation preview

Journey to Microservice architecture via Amazon Lambda

https://www.flickr.com/photos/robertthigpen/5651555624/

Sergej Jakovljev

https://www.nginx.com/blog/building-microservices-inter-process-communication/

Example0

RDS with Lambda1

http://www.slideshare.net/AmazonWebServices/february-2016-webinar-series-accessing-resources-in-vpc-with-aws-lambda

http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Scenario2.html

VPC100.0.0.0/16

AWS

Private Subnet100.0.0.0/24

Public Subnet100.0.2.0/24

InternetGateway

LambdaInstances

NAT Gateway

DatabaseServer

NAT Route Table

Destination Target

100.0.0.0/16 local

0.0.0.0/0 nat-gateway

Internet Route TableDestination Target

100.0.0.0/16 local

0.0.0.0/0 igw-gateway

CI EC2

Internet

Regioneu-central-1

Avai

labi

lity

Zone

1

Setup order matters:

Code Structure2

Pricing & Limits3

http://serverlesscalc.com

10,000,000

$7,63requests

https://www.flickr.com/photos/68751915@N05/6355816649

https://www.linkedin.com/pulse/aws-lambda-container-lifetime-config-refresh-frederik-willaert

https://www.flickr.com/photos/38007185@N00/8466324955/

https://www.linkedin.com/pulse/aws-lambda-container-lifetime-config-refresh-frederik-willaert

Q: Typically, how long can I expect a container to live if it’s idle?

A: The "official" answer to all of these questions goes something like, "We reserve the right to make changes to better serve customers and so I can't give you a response that's guaranteed to remain accurate." But that said, in the current implementation we'll typically consider a function a candidate for what we call "fast spindown" if we haven't seen it used in the last five minutes. This can vary by event type, function and account history, etc. but is generally the case.

Continuous Integration4

Development box

$ ./program-bash: ./program: cannot execute binary file: Exec format error

$ deploy$ cp . /tmp/j918wdja$ rm -r node-modules

$ npm i --productionbuilding dependencies ...

$ zip -r code.zip$ configure aws$ upload code.zip

cannot execute binary file: Exec format error

$ unzip code.zip$ magic ...Deployed!

HTTP Requests

Amazon Lambda

VPC100.0.0.0/16

AWS

Private Subnet100.0.0.0/24

Public Subnet100.0.2.0/24

InternetGateway

LambdaInstances

NAT Gateway

NAT Route Table

Destination Target

100.0.0.0/16 local

0.0.0.0/0 nat-gateway

Internet Route TableDestination Target

100.0.0.0/16 local

0.0.0.0/0 igw-gateway

CI EC2

Internet

Regioneu-central-1

Avai

labi

lity

Zone

1

DatabaseServer

#!/programmer

create EC2 instanceadd instance to VPC and setup firewallinstall Jenkins

for (service of services): create service and configure package.JSON run claudia create manually

create GitHub repository create SSH key-pair* add Jenkins as webhook add SSH key-pair

create Jenkins project configure Jenkins

push local repo to Github hope it all works!

# Jenkins on EC2 Amazon Linux

ping google.comsudo yum updatesudo yum install git

curl --silent --location https://rpm.nodesource.com/setup_4.x | sudo bash -sudo yum -y install nodejssudo yum -y install gcc-c++ makecurl --silent --location "https://www.npmjs.org/install.sh" | sudo bash -

node --versionnpm --versionsudo npm install -g npm@latestsudo npm update -g

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024sudo /sbin/mkswap /var/swap.1sudo /sbin/swapon /var/swap.1sudo chmod 0600 /var/swap.1sudo vim /etc/fstabecho "/var/swap.1 swap swap defaults 0 0" | sudo tee -a /etc/fstabsudo shutdown -r now

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.reposudo rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.keysudo yum install jenkinssudo chkconfig jenkins onsudo service jenkins restartsudo cat /var/lib/jenkins/secrets/initialAdminPassword

But wait,

there’s more!

You still need to secure instance.

#!/programmer

create EC2 instanceadd instance to VPC and setup firewallinstall Jenkins

for (service of services): create service and configure package.JSON run claudia create manually

create GitHub repository create SSH key-pair add Jenkins as webhook add SSH key-pair

create Jenkins project configure Jenkins

push local repo to Github hope it all works!

https://www.flickr.com/photos/44811338@N05/7505286308/

#!/programmer

create EC2 instanceadd instance to VPC and setup firewallinstall Jenkins

for (service of services): create service and configure package.JSON run claudia create manually

create GitHub repository create SSH key-pair add Jenkins as webhook add SSH key-pair

create Jenkins project configure Jenkins

push local repo to Github hope it all works!

configure manually rest of Lambda settings (VPC, RAM size, timeout ...) configure logging, packages ... and build service

Further reading Discussion5

One, last thing :)Always redeploy functions after changing configuration!Because changes only take place when new function version gets deployed.

Big thanks to Gordan and Damir.

Blog post (covering most of the presentation)Soon on Axilis.com blog

Book (recommended by Damir)Building Microservices by Sam Newman

Introduction:https://app.pluralsight.com/library/courses/microservices-architecture/table-of-contentshttps://www.nginx.com/blog/introduction-to-microservices/

VPC Example:https://gist.github.com/reggi/dc5f2620b7b4f515e68e46255ac042a7

References:https://claudiajs.com/claudia-api-builder.htmlhttps://www.linkedin.com/pulse/aws-lambda-container-lifetime-config-refresh-frederik-willaerthttps://medium.com/@tjholowaychuk/dos-and-don-ts-of-aws-lambda-7dfcab7ad115#.937xuhm3ahttp://docs.aws.amazon.com/lambda/latest/dg/limits.html

https://www.flickr.com/photos/gagzclix/9472875083/

Official AWS Documentationhttps://aws.amazon.com/documentation/

Recommended