34
rney to roservice architecture Amazon Lambda ps://www.flickr.com/photos/robertthigpen/5651555624/ Sergej Jakovljev

Journey to Microservice architecture via Amazon Lambda

  • Upload
    axilis

  • View
    28

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Journey to Microservice architecture via Amazon Lambda

Journey to Microservice architecture via Amazon Lambda

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

Sergej Jakovljev

Page 2: Journey to Microservice architecture via Amazon Lambda
Page 3: Journey to Microservice architecture via Amazon Lambda

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

Page 4: Journey to Microservice architecture via Amazon Lambda
Page 5: Journey to Microservice architecture via Amazon Lambda

Example0

Page 6: Journey to Microservice architecture via Amazon Lambda

RDS with Lambda1

Page 7: Journey to Microservice architecture via Amazon Lambda

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

Page 8: Journey to Microservice architecture via Amazon Lambda

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

Page 9: Journey to Microservice architecture via Amazon Lambda

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:

Page 10: Journey to Microservice architecture via Amazon Lambda

Code Structure2

Page 11: Journey to Microservice architecture via Amazon Lambda
Page 12: Journey to Microservice architecture via Amazon Lambda

Pricing & Limits3

Page 13: Journey to Microservice architecture via Amazon Lambda

http://serverlesscalc.com

Page 14: Journey to Microservice architecture via Amazon Lambda

10,000,000

$7,63requests

Page 15: Journey to Microservice architecture via Amazon Lambda

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

Page 16: Journey to Microservice architecture via Amazon Lambda
Page 17: Journey to Microservice architecture via Amazon Lambda
Page 18: Journey to Microservice architecture via Amazon Lambda

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

Page 19: Journey to Microservice architecture via Amazon Lambda

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

Page 20: Journey to Microservice architecture via Amazon Lambda

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.

Page 21: Journey to Microservice architecture via Amazon Lambda

Continuous Integration4

Page 22: Journey to Microservice architecture via Amazon Lambda
Page 23: Journey to Microservice architecture via Amazon Lambda

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

Page 24: Journey to Microservice architecture via 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

Page 25: Journey to Microservice architecture via Amazon Lambda
Page 26: Journey to Microservice architecture via Amazon Lambda

#!/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!

Page 27: Journey to Microservice architecture via Amazon Lambda

# 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.

Page 28: Journey to Microservice architecture via Amazon Lambda

#!/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!

Page 29: Journey to Microservice architecture via Amazon Lambda

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

Page 30: Journey to Microservice architecture via Amazon Lambda

#!/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

Page 31: Journey to Microservice architecture via Amazon Lambda

Further reading Discussion5

Page 32: Journey to Microservice architecture via Amazon Lambda

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

Page 33: Journey to Microservice architecture via Amazon Lambda

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

Page 34: Journey to Microservice architecture via Amazon Lambda

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

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