SlideShare a Scribd company logo
AWS Lambda with Serverless Framework and Java
About
Manish Pandit
Director of Platform Engineering @Marqeta
Twitter : @lobster1234
Blog: lobster1234.github.io
LinkedIn: in/mpandit
Serverless
Serverless is the finest grain abstraction in distributed computing
100% managed with zero infrastructure concerns
Lowest cost compared to Servers and Containers (if designed correctly!)
Why Serverless
Ideal fit for microservices architectures - functions have limited, well
defined scopes
Pricing - you pay for what you use
No need to worry about infrastructure
AWS Lambda
Function as a Service
Simple Pricing Model - Memory * time
Event Sources - DynamoDB, S3, API Gateway, Cloudwatch, SNS...
Security via VPC and IAM Roles
Serverless Framework
Node.js based CLI
Makes working with FaaS much, much easier
Simple, YAML based configuration abstracts Cloudformation
Supports many cloud providers - AWS, OpenWhisk, GCP, Azure
Supports stages
Popular, feature rich, well documented
AWS Lambda with Serverless Framework and Java
Install
bash-3.2$ npm install serverless -g
+ serverless@1.23.0
bash-3.2$ serverless --version
1.23.0
Configure AWS - Option 1
bash-3.2$ aws configure
AWS Access Key ID [****************4MTA]:
AWS Secret Access Key [****************g2uU]:
Default region name [us-east-1]:
Default output format [json]:
bash-3.2$
Configure AWS - Option 2
bash-3.2$ serverless config credentials --provider aws --key XXXX --secret YYY
If you already have a default profile….
Serverless: Setting up AWS...
Serverless: Failed! ~/.aws/credentials already has a "default" profile. Use the
overwrite flag ("-o" or "--overwrite") to force the update
Create a Project
bash-3.2$ serverless create --template aws-java-maven
Serverless: Generating boilerplate...
Serverless: Successfully generated boilerplate for template: "aws-java-maven"
Serverless: NOTE: Please update the "service" property in serverless.yml with your
service name
bash-3.2$
The Project Structure
bash-3.2$ tree .
.
├── pom.xml
├── serverless.yml
└── src
└── main
├── java
│ └── com
│ └── serverless
│ ├── ApiGatewayResponse.java
│ ├── Handler.java
│ └── Response.java
└── resources
└── log4j.properties
6 directories, 6 files
serverless.yml
service: aws-java-maven # NOTE: update this with your service name
provider:
name: aws
runtime: java8
package:
artifact: target/hello-dev.jar
functions:
hello:
handler: com.serverless.Handler
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
# events:
# - http:
# path: users/create
# method: get
Handler Class
package com.serverless;
import …
public class Handler implements RequestHandler<Map<String, Object>, ApiGatewayResponse>
handleRequest Method
@Override
public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) {
BasicConfigurator.configure();
LOG.info("received: " + input);
Response responseBody = new Response("Go Serverless v1.x! Your function executed successfully!",
input);
return ApiGatewayResponse.builder()
.setStatusCode(200)
.setObjectBody(responseBody)
.setHeaders(Collections.singletonMap("X-Powered-By", "AWS Lambda & serverless"))
.build();
}
Build
bash-3.2$ mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hello dev
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.666 s
[INFO] Finished at: 2017-10-07T01:34:10-07:00
[INFO] Final Memory: 16M/214M
[INFO] ------------------------------------------------------------------------
Deploy
bash-3.2$ serverless deploy
Serverless: Packaging service...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
...............
Serverless: Stack update finished...
Service Information
service: aws-java-maven
stage: dev
region: us-east-1
stack: aws-java-maven-dev
api keys:
None
endpoints:
None
functions:
hello: aws-java-maven-dev-hello
Invoke
bash-3.2$ serverless invoke -f hello
{
"statusCode": 200,
"body": "{"message":"Go Serverless v1.x! Your function executed successfully!","input":{}}",
"headers": {
"X-Powered-By": "AWS Lambda & serverless"
},
"isBase64Encoded": false
}
bash-3.2$
Execution
1.An event source generates an event, or a trigger
2.A new container is spun off or an existing one is reused to launch
the runtime
3.The function (script if interpreted language, binary if compiled) is
executed
4.The runtime exits
Invoke Local
bash-3.2$ serverless invoke local -f hello
Serverless: In order to get human-readable output, please implement "toString()" method of your
"ApiGatewayResponse" object.
0 [main] INFO com.serverless.Handler - received: {}
com.serverless.ApiGatewayResponse@77cd7a0
bash-3.2$
Using an HTTP Event Source
service: aws-java-maven # NOTE: update this with your service name
provider:
name: aws
runtime: java8
package:
artifact: target/hello-dev.jar
functions:
hello:
handler: com.serverless.Handler
events:
- http:
path: /hello
method: get
Deploy with a new stage!
bash-3.2$ serverless deploy --stage prod
Serverless: Packaging service...
Serverless: Creating Stack...
Serverless: Checking Stack create progress…
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
Serverless: Stack update finished...
Service Information
service: aws-java-maven
stage: prod
region: us-east-1
stack: aws-java-maven-prod
api keys:
None
endpoints:
GET - https://f582xxq581.execute-api.us-east-1.amazonaws.com/prod/hello
functions:
hello: aws-java-maven-prod-hello
Test
bash-3.2$ curl https://f582xxq581.execute-api.us-east-1.amazonaws.com/prod/hello
{"message":"Go Serverless v1.x! Your function executed
successfully!","input":{"resource":"/hello","path":"/hello","httpMethod":"GET","headers":{"Accept":"*/*","Cl
oudFront-Forwarded-Proto":"https","CloudFront-Is-Desktop-Viewer":"true","CloudFront-Is-Mobile-
Viewer":"false","CloudFront-Is-SmartTV-Viewer":"false","CloudFront-Is-Tablet-Viewer":"false","CloudFront-
Viewer-Country":"US","Host":"f582xxq581.execute-api.us-east-1.amazonaws.com","User-
Agent":"curl/7.51.0","Via":"1.1 3cc911e7eb2df956e3f7c8f27c198a0b.cloudfront.net (CloudFront)","X-Amz-Cf-
Id":"rngpB7WCzOt_XnMXzDc0Pv5i9Eq7_ZA1olb08W84xi5Of8Od4VvVVw==","X-Amzn-Trace-Id":"Root=1-59d895b4-
375b518e32e7a6866c80fa0a","X-Forwarded-For":"69.181.73.181, 205.251.214.68","X-Forwarded-Port":"443","X-
Forwarded-
Proto":"https"},"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"
path":"/prod/hello","accountId":"xxxxxxxxxxxx","resourceId":"07sycy","stage":"prod","requestId":"cab13cdc-
ab3c-11e7-b85c-
0fc68f7d77c1","identity":{"cognitoIdentityPoolId":null,"accountId":null,"cognitoIdentityId":null,"caller":nu
ll,"apiKey":"","sourceIp":"69.181.73.181","accessKey":null,"cognitoAuthenticationType":null,"cognitoAuthenti
cationProvider":null,"userArn":null,"userAgent":"curl/7.51.0","user":null},"resourcePath":"/hello","httpMeth
od":"GET","apiId":"f582xxq581"},"body":null,"isBase64Encoded":false}}
bash-3.2$
Serverless Logs
bash-3.2$ serverless logs -f hello
START RequestId: 32c366cc-ab41-11e7-bcba-6f7680b04a52 Version: $LATEST
2017-10-07 09:23:38 <32c366cc-ab41-11e7-bcba-6f7680b04a52> INFO com.serverless.Handler:20 -
received: {}
0 [main] INFO com.serverless.Handler - received: {}
END RequestId: 32c366cc-ab41-11e7-bcba-6f7680b04a52
REPORT RequestId: 32c366cc-ab41-11e7-bcba-6f7680b04a52 Duration: 411.34 ms Billed Duration: 500 ms
Memory Size: 1024 MB Max Memory Used: 63 MB
START RequestId: e41254f3-ab41-11e7-ab1b-750906e00517 Version: $LATEST
2017-10-07 09:28:34 <e41254f3-ab41-11e7-ab1b-750906e00517> INFO com.serverless.Handler:20 -
received: {}
END RequestId: e41254f3-ab41-11e7-ab1b-750906e00517
REPORT RequestId: e41254f3-ab41-11e7-ab1b-750906e00517 Duration: 9.92 ms Billed Duration: 100 ms
Memory Size: 1024 MB Max Memory Used: 63 MB
Serverless Metrics
bash-3.2$ serverless metrics -f hello
Service wide metrics
October 6, 2017 2:21 AM - October 7, 2017 2:21 AM
Invocations: 4
Throttles: 0
Errors: 0
Duration (avg.): 206.84ms
bash-3.2$
Serverless Metrics w/ Stages
bash-3.2$ serverless metrics --stage dev -f hello
hello
October 6, 2017 2:29 AM - October 7, 2017 2:29 AM
Invocations: 8
Throttles: 0
Errors: 0
Duration (avg.): 120.89ms
bash-3.2$ serverless metrics --stage prod -f hello
hello
October 6, 2017 2:29 AM - October 7, 2017 2:29 AM
Invocations: 6
Throttles: 0
Errors: 0
Duration (avg.): 187.97ms
Serverless Info
bash-3.2$ serverless info
Service Information
service: aws-java-maven
stage: dev
region: us-east-1
stack: aws-java-maven-dev
api keys:
None
endpoints:
None
functions:
hello: aws-java-maven-dev-hello
Serverless Info w/Stages
bash-3.2$ serverless info --stage prod
Service Information
service: aws-java-maven
stage: prod
region: us-east-1
stack: aws-java-maven-prod
api keys:
None
endpoints:
GET - https://f582xxq581.execute-api.us-east-1.amazonaws.com/prod/hello
functions:
hello: aws-java-maven-prod-hello
bash-3.2$
Remove Stack
bash-3.2$ serverless remove
Serverless: Getting all objects in S3 bucket...
Serverless: Removing objects in S3 bucket...
Serverless: Removing Stack...
Serverless: Checking Stack removal progress...
....
Serverless: Stack removal finished…
bash-3.2$
Remove Stack w/Stages
bash-3.2$ serverless remove --stage prod
Serverless: Getting all objects in S3 bucket...
Serverless: Removing objects in S3 bucket...
Serverless: Removing Stack...
Serverless: Checking Stack removal progress...
................
Serverless: Stack removal finished…
bash-3.2$ curl https://f582xxq581.execute-api.us-east-1.amazonaws.com/prod/hello
curl: (35) SSL peer handshake failed, the server most likely requires a client
certificate to connect
bash-3.2$
Lambda Tips
1. Write your code in a way that it can be tested without an event source
2. Lambda cannot execute for longer than 5 minutes
3. Coordinating many Lambdas can be difficult, use AWS Step Functions
4. Do not persist anything on the disk - it may not be available
5. Be aware of cold start - JVM will take a while to start
6. Do not write lambdas for everything - if a service is high throughput, you’re better off
with ECS or EC2 given the costs
7. Lambdas can be tied to VPCs and have IAM execution roles
8. Serverless supports API Gateway Proxy Integration by default - everything gets passed to
the function
Resources
Serverless Framework - https://serverless.com
AWS Lambda - https://aws.amazon.com/lambda
My Tutorial - https://lobster1234.github.io/categories/serverless
Questions
Manish Pandit
@lobster1234
lobster1234.github.io
Ad

More Related Content

What's hot (9)

Packer
Packer Packer
Packer
Nitesh Saini
 
The AWS DevOps combo (January 2017)
The AWS DevOps combo (January 2017)The AWS DevOps combo (January 2017)
The AWS DevOps combo (January 2017)
Julien SIMON
 
Packer by HashiCorp
Packer by HashiCorpPacker by HashiCorp
Packer by HashiCorp
Łukasz Cieśluk
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부
Hyun-Mook Choi
 
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container DayECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
Amazon Web Services Korea
 
Infrastructure as code with Amazon Web Services
Infrastructure as code with Amazon Web ServicesInfrastructure as code with Amazon Web Services
Infrastructure as code with Amazon Web Services
Julien SIMON
 
Introduction to Amazon EC2 Container Service and setting up build pipeline wi...
Introduction to Amazon EC2 Container Service and setting up build pipeline wi...Introduction to Amazon EC2 Container Service and setting up build pipeline wi...
Introduction to Amazon EC2 Container Service and setting up build pipeline wi...
Swapnil Dahiphale
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
George Miranda
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!
David Lapsley
 
The AWS DevOps combo (January 2017)
The AWS DevOps combo (January 2017)The AWS DevOps combo (January 2017)
The AWS DevOps combo (January 2017)
Julien SIMON
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부
Hyun-Mook Choi
 
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container DayECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
Amazon Web Services Korea
 
Infrastructure as code with Amazon Web Services
Infrastructure as code with Amazon Web ServicesInfrastructure as code with Amazon Web Services
Infrastructure as code with Amazon Web Services
Julien SIMON
 
Introduction to Amazon EC2 Container Service and setting up build pipeline wi...
Introduction to Amazon EC2 Container Service and setting up build pipeline wi...Introduction to Amazon EC2 Container Service and setting up build pipeline wi...
Introduction to Amazon EC2 Container Service and setting up build pipeline wi...
Swapnil Dahiphale
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
George Miranda
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!
David Lapsley
 

Similar to AWS Lambda with Serverless Framework and Java (20)

DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
Timofey Turenko
 
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
AWS Chicago
 
AWS Serverless Workshop
AWS Serverless WorkshopAWS Serverless Workshop
AWS Serverless Workshop
Mikael Puittinen
 
2013 05-openstack-israel-heat
2013 05-openstack-israel-heat2013 05-openstack-israel-heat
2013 05-openstack-israel-heat
Alex Heneveld
 
Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020
Andrea Scuderi
 
MesosCon - Be a microservices hero
MesosCon - Be a microservices heroMesosCon - Be a microservices hero
MesosCon - Be a microservices hero
Dragos Dascalita Haut
 
AWS meets Continuous Delivery
AWS meets Continuous DeliveryAWS meets Continuous Delivery
AWS meets Continuous Delivery
Andreas Mohrhard
 
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-ServicesNode Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Chris Bailey
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
Lindsay Holmwood
 
Fluentd Plugins for CouchDB, Amazon SQS/SNS
Fluentd Plugins for CouchDB, Amazon SQS/SNSFluentd Plugins for CouchDB, Amazon SQS/SNS
Fluentd Plugins for CouchDB, Amazon SQS/SNS
Yuri Odagiri
 
A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)
Julien SIMON
 
Deploying SharePoint @ Cloud
Deploying SharePoint @ CloudDeploying SharePoint @ Cloud
Deploying SharePoint @ Cloud
Juan Andrés Valenzuela
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Emerson Eduardo Rodrigues Von Staffen
 
Serverless archtiectures
Serverless archtiecturesServerless archtiectures
Serverless archtiectures
Iegor Fadieiev
 
Integrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code SuiteIntegrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code Suite
Atlassian
 
Infrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitInfrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with Git
Danilo Poccia
 
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js MicroservicesIBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
Chris Bailey
 
Serverless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best PracticesServerless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best Practices
Daniel Zivkovic
 
Puppet and Apache CloudStack
Puppet and Apache CloudStackPuppet and Apache CloudStack
Puppet and Apache CloudStack
Puppet
 
Bare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and ChefBare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and Chef
Matt Ray
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
Timofey Turenko
 
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
AWS Chicago
 
2013 05-openstack-israel-heat
2013 05-openstack-israel-heat2013 05-openstack-israel-heat
2013 05-openstack-israel-heat
Alex Heneveld
 
Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020
Andrea Scuderi
 
AWS meets Continuous Delivery
AWS meets Continuous DeliveryAWS meets Continuous Delivery
AWS meets Continuous Delivery
Andreas Mohrhard
 
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-ServicesNode Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Chris Bailey
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
Lindsay Holmwood
 
Fluentd Plugins for CouchDB, Amazon SQS/SNS
Fluentd Plugins for CouchDB, Amazon SQS/SNSFluentd Plugins for CouchDB, Amazon SQS/SNS
Fluentd Plugins for CouchDB, Amazon SQS/SNS
Yuri Odagiri
 
A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)
Julien SIMON
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Emerson Eduardo Rodrigues Von Staffen
 
Serverless archtiectures
Serverless archtiecturesServerless archtiectures
Serverless archtiectures
Iegor Fadieiev
 
Integrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code SuiteIntegrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code Suite
Atlassian
 
Infrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitInfrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with Git
Danilo Poccia
 
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js MicroservicesIBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
Chris Bailey
 
Serverless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best PracticesServerless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best Practices
Daniel Zivkovic
 
Puppet and Apache CloudStack
Puppet and Apache CloudStackPuppet and Apache CloudStack
Puppet and Apache CloudStack
Puppet
 
Bare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and ChefBare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and Chef
Matt Ray
 
Ad

More from Manish Pandit (20)

Disaster recovery - What, Why, and How
Disaster recovery - What, Why, and HowDisaster recovery - What, Why, and How
Disaster recovery - What, Why, and How
Manish Pandit
 
Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018
Manish Pandit
 
Disaster Recovery and Reliability
Disaster Recovery and ReliabilityDisaster Recovery and Reliability
Disaster Recovery and Reliability
Manish Pandit
 
OAuth2 primer
OAuth2 primerOAuth2 primer
OAuth2 primer
Manish Pandit
 
AWS Primer and Quickstart
AWS Primer and QuickstartAWS Primer and Quickstart
AWS Primer and Quickstart
Manish Pandit
 
Securing your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID ConnectSecuring your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID Connect
Manish Pandit
 
Silicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API AntipatternsSilicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API Antipatterns
Manish Pandit
 
Scalabay - API Design Antipatterns
Scalabay - API Design AntipatternsScalabay - API Design Antipatterns
Scalabay - API Design Antipatterns
Manish Pandit
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Manish Pandit
 
API Design Antipatterns - APICon SF
API Design Antipatterns - APICon SFAPI Design Antipatterns - APICon SF
API Design Antipatterns - APICon SF
Manish Pandit
 
Motivation : it Matters
Motivation : it MattersMotivation : it Matters
Motivation : it Matters
Manish Pandit
 
Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2
Manish Pandit
 
Scala at Netflix
Scala at NetflixScala at Netflix
Scala at Netflix
Manish Pandit
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with Scala
Manish Pandit
 
IGN's V3 API
IGN's V3 APIIGN's V3 API
IGN's V3 API
Manish Pandit
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
Manish Pandit
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Manish Pandit
 
Silicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTSilicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you REST
Manish Pandit
 
Silicon Valley Code Camp: 2011 Introduction to MongoDB
Silicon Valley Code Camp: 2011 Introduction to MongoDBSilicon Valley Code Camp: 2011 Introduction to MongoDB
Silicon Valley Code Camp: 2011 Introduction to MongoDB
Manish Pandit
 
Disaster recovery - What, Why, and How
Disaster recovery - What, Why, and HowDisaster recovery - What, Why, and How
Disaster recovery - What, Why, and How
Manish Pandit
 
Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018
Manish Pandit
 
Disaster Recovery and Reliability
Disaster Recovery and ReliabilityDisaster Recovery and Reliability
Disaster Recovery and Reliability
Manish Pandit
 
AWS Primer and Quickstart
AWS Primer and QuickstartAWS Primer and Quickstart
AWS Primer and Quickstart
Manish Pandit
 
Securing your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID ConnectSecuring your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID Connect
Manish Pandit
 
Silicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API AntipatternsSilicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API Antipatterns
Manish Pandit
 
Scalabay - API Design Antipatterns
Scalabay - API Design AntipatternsScalabay - API Design Antipatterns
Scalabay - API Design Antipatterns
Manish Pandit
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Manish Pandit
 
API Design Antipatterns - APICon SF
API Design Antipatterns - APICon SFAPI Design Antipatterns - APICon SF
API Design Antipatterns - APICon SF
Manish Pandit
 
Motivation : it Matters
Motivation : it MattersMotivation : it Matters
Motivation : it Matters
Manish Pandit
 
Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2
Manish Pandit
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with Scala
Manish Pandit
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Manish Pandit
 
Silicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTSilicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you REST
Manish Pandit
 
Silicon Valley Code Camp: 2011 Introduction to MongoDB
Silicon Valley Code Camp: 2011 Introduction to MongoDBSilicon Valley Code Camp: 2011 Introduction to MongoDB
Silicon Valley Code Camp: 2011 Introduction to MongoDB
Manish Pandit
 
Ad

Recently uploaded (20)

ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
Rock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning JourneyRock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning Journey
Lynda Kane
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
José Enrique López Rivera
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
Rock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning JourneyRock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning Journey
Lynda Kane
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
José Enrique López Rivera
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 

AWS Lambda with Serverless Framework and Java

  • 2. About Manish Pandit Director of Platform Engineering @Marqeta Twitter : @lobster1234 Blog: lobster1234.github.io LinkedIn: in/mpandit
  • 3. Serverless Serverless is the finest grain abstraction in distributed computing 100% managed with zero infrastructure concerns Lowest cost compared to Servers and Containers (if designed correctly!)
  • 4. Why Serverless Ideal fit for microservices architectures - functions have limited, well defined scopes Pricing - you pay for what you use No need to worry about infrastructure
  • 5. AWS Lambda Function as a Service Simple Pricing Model - Memory * time Event Sources - DynamoDB, S3, API Gateway, Cloudwatch, SNS... Security via VPC and IAM Roles
  • 6. Serverless Framework Node.js based CLI Makes working with FaaS much, much easier Simple, YAML based configuration abstracts Cloudformation Supports many cloud providers - AWS, OpenWhisk, GCP, Azure Supports stages Popular, feature rich, well documented
  • 8. Install bash-3.2$ npm install serverless -g + [email protected] bash-3.2$ serverless --version 1.23.0
  • 9. Configure AWS - Option 1 bash-3.2$ aws configure AWS Access Key ID [****************4MTA]: AWS Secret Access Key [****************g2uU]: Default region name [us-east-1]: Default output format [json]: bash-3.2$
  • 10. Configure AWS - Option 2 bash-3.2$ serverless config credentials --provider aws --key XXXX --secret YYY If you already have a default profile…. Serverless: Setting up AWS... Serverless: Failed! ~/.aws/credentials already has a "default" profile. Use the overwrite flag ("-o" or "--overwrite") to force the update
  • 11. Create a Project bash-3.2$ serverless create --template aws-java-maven Serverless: Generating boilerplate... Serverless: Successfully generated boilerplate for template: "aws-java-maven" Serverless: NOTE: Please update the "service" property in serverless.yml with your service name bash-3.2$
  • 12. The Project Structure bash-3.2$ tree . . ├── pom.xml ├── serverless.yml └── src └── main ├── java │ └── com │ └── serverless │ ├── ApiGatewayResponse.java │ ├── Handler.java │ └── Response.java └── resources └── log4j.properties 6 directories, 6 files
  • 13. serverless.yml service: aws-java-maven # NOTE: update this with your service name provider: name: aws runtime: java8 package: artifact: target/hello-dev.jar functions: hello: handler: com.serverless.Handler # The following are a few example events you can configure # NOTE: Please make sure to change your handler code to work with those events # Check the event documentation for details # events: # - http: # path: users/create # method: get
  • 14. Handler Class package com.serverless; import … public class Handler implements RequestHandler<Map<String, Object>, ApiGatewayResponse>
  • 15. handleRequest Method @Override public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) { BasicConfigurator.configure(); LOG.info("received: " + input); Response responseBody = new Response("Go Serverless v1.x! Your function executed successfully!", input); return ApiGatewayResponse.builder() .setStatusCode(200) .setObjectBody(responseBody) .setHeaders(Collections.singletonMap("X-Powered-By", "AWS Lambda & serverless")) .build(); }
  • 16. Build bash-3.2$ mvn clean install [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building hello dev [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.666 s [INFO] Finished at: 2017-10-07T01:34:10-07:00 [INFO] Final Memory: 16M/214M [INFO] ------------------------------------------------------------------------
  • 17. Deploy bash-3.2$ serverless deploy Serverless: Packaging service... Serverless: Creating Stack... Serverless: Checking Stack create progress... Serverless: Stack create finished... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... ............... Serverless: Stack update finished... Service Information service: aws-java-maven stage: dev region: us-east-1 stack: aws-java-maven-dev api keys: None endpoints: None functions: hello: aws-java-maven-dev-hello
  • 18. Invoke bash-3.2$ serverless invoke -f hello { "statusCode": 200, "body": "{"message":"Go Serverless v1.x! Your function executed successfully!","input":{}}", "headers": { "X-Powered-By": "AWS Lambda & serverless" }, "isBase64Encoded": false } bash-3.2$
  • 19. Execution 1.An event source generates an event, or a trigger 2.A new container is spun off or an existing one is reused to launch the runtime 3.The function (script if interpreted language, binary if compiled) is executed 4.The runtime exits
  • 20. Invoke Local bash-3.2$ serverless invoke local -f hello Serverless: In order to get human-readable output, please implement "toString()" method of your "ApiGatewayResponse" object. 0 [main] INFO com.serverless.Handler - received: {} com.serverless.ApiGatewayResponse@77cd7a0 bash-3.2$
  • 21. Using an HTTP Event Source service: aws-java-maven # NOTE: update this with your service name provider: name: aws runtime: java8 package: artifact: target/hello-dev.jar functions: hello: handler: com.serverless.Handler events: - http: path: /hello method: get
  • 22. Deploy with a new stage! bash-3.2$ serverless deploy --stage prod Serverless: Packaging service... Serverless: Creating Stack... Serverless: Checking Stack create progress… Serverless: Updating Stack... Serverless: Checking Stack update progress... Serverless: Stack update finished... Service Information service: aws-java-maven stage: prod region: us-east-1 stack: aws-java-maven-prod api keys: None endpoints: GET - https://f582xxq581.execute-api.us-east-1.amazonaws.com/prod/hello functions: hello: aws-java-maven-prod-hello
  • 23. Test bash-3.2$ curl https://f582xxq581.execute-api.us-east-1.amazonaws.com/prod/hello {"message":"Go Serverless v1.x! Your function executed successfully!","input":{"resource":"/hello","path":"/hello","httpMethod":"GET","headers":{"Accept":"*/*","Cl oudFront-Forwarded-Proto":"https","CloudFront-Is-Desktop-Viewer":"true","CloudFront-Is-Mobile- Viewer":"false","CloudFront-Is-SmartTV-Viewer":"false","CloudFront-Is-Tablet-Viewer":"false","CloudFront- Viewer-Country":"US","Host":"f582xxq581.execute-api.us-east-1.amazonaws.com","User- Agent":"curl/7.51.0","Via":"1.1 3cc911e7eb2df956e3f7c8f27c198a0b.cloudfront.net (CloudFront)","X-Amz-Cf- Id":"rngpB7WCzOt_XnMXzDc0Pv5i9Eq7_ZA1olb08W84xi5Of8Od4VvVVw==","X-Amzn-Trace-Id":"Root=1-59d895b4- 375b518e32e7a6866c80fa0a","X-Forwarded-For":"69.181.73.181, 205.251.214.68","X-Forwarded-Port":"443","X- Forwarded- Proto":"https"},"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{" path":"/prod/hello","accountId":"xxxxxxxxxxxx","resourceId":"07sycy","stage":"prod","requestId":"cab13cdc- ab3c-11e7-b85c- 0fc68f7d77c1","identity":{"cognitoIdentityPoolId":null,"accountId":null,"cognitoIdentityId":null,"caller":nu ll,"apiKey":"","sourceIp":"69.181.73.181","accessKey":null,"cognitoAuthenticationType":null,"cognitoAuthenti cationProvider":null,"userArn":null,"userAgent":"curl/7.51.0","user":null},"resourcePath":"/hello","httpMeth od":"GET","apiId":"f582xxq581"},"body":null,"isBase64Encoded":false}} bash-3.2$
  • 24. Serverless Logs bash-3.2$ serverless logs -f hello START RequestId: 32c366cc-ab41-11e7-bcba-6f7680b04a52 Version: $LATEST 2017-10-07 09:23:38 <32c366cc-ab41-11e7-bcba-6f7680b04a52> INFO com.serverless.Handler:20 - received: {} 0 [main] INFO com.serverless.Handler - received: {} END RequestId: 32c366cc-ab41-11e7-bcba-6f7680b04a52 REPORT RequestId: 32c366cc-ab41-11e7-bcba-6f7680b04a52 Duration: 411.34 ms Billed Duration: 500 ms Memory Size: 1024 MB Max Memory Used: 63 MB START RequestId: e41254f3-ab41-11e7-ab1b-750906e00517 Version: $LATEST 2017-10-07 09:28:34 <e41254f3-ab41-11e7-ab1b-750906e00517> INFO com.serverless.Handler:20 - received: {} END RequestId: e41254f3-ab41-11e7-ab1b-750906e00517 REPORT RequestId: e41254f3-ab41-11e7-ab1b-750906e00517 Duration: 9.92 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 63 MB
  • 25. Serverless Metrics bash-3.2$ serverless metrics -f hello Service wide metrics October 6, 2017 2:21 AM - October 7, 2017 2:21 AM Invocations: 4 Throttles: 0 Errors: 0 Duration (avg.): 206.84ms bash-3.2$
  • 26. Serverless Metrics w/ Stages bash-3.2$ serverless metrics --stage dev -f hello hello October 6, 2017 2:29 AM - October 7, 2017 2:29 AM Invocations: 8 Throttles: 0 Errors: 0 Duration (avg.): 120.89ms bash-3.2$ serverless metrics --stage prod -f hello hello October 6, 2017 2:29 AM - October 7, 2017 2:29 AM Invocations: 6 Throttles: 0 Errors: 0 Duration (avg.): 187.97ms
  • 27. Serverless Info bash-3.2$ serverless info Service Information service: aws-java-maven stage: dev region: us-east-1 stack: aws-java-maven-dev api keys: None endpoints: None functions: hello: aws-java-maven-dev-hello
  • 28. Serverless Info w/Stages bash-3.2$ serverless info --stage prod Service Information service: aws-java-maven stage: prod region: us-east-1 stack: aws-java-maven-prod api keys: None endpoints: GET - https://f582xxq581.execute-api.us-east-1.amazonaws.com/prod/hello functions: hello: aws-java-maven-prod-hello bash-3.2$
  • 29. Remove Stack bash-3.2$ serverless remove Serverless: Getting all objects in S3 bucket... Serverless: Removing objects in S3 bucket... Serverless: Removing Stack... Serverless: Checking Stack removal progress... .... Serverless: Stack removal finished… bash-3.2$
  • 30. Remove Stack w/Stages bash-3.2$ serverless remove --stage prod Serverless: Getting all objects in S3 bucket... Serverless: Removing objects in S3 bucket... Serverless: Removing Stack... Serverless: Checking Stack removal progress... ................ Serverless: Stack removal finished… bash-3.2$ curl https://f582xxq581.execute-api.us-east-1.amazonaws.com/prod/hello curl: (35) SSL peer handshake failed, the server most likely requires a client certificate to connect bash-3.2$
  • 31. Lambda Tips 1. Write your code in a way that it can be tested without an event source 2. Lambda cannot execute for longer than 5 minutes 3. Coordinating many Lambdas can be difficult, use AWS Step Functions 4. Do not persist anything on the disk - it may not be available 5. Be aware of cold start - JVM will take a while to start 6. Do not write lambdas for everything - if a service is high throughput, you’re better off with ECS or EC2 given the costs 7. Lambdas can be tied to VPCs and have IAM execution roles 8. Serverless supports API Gateway Proxy Integration by default - everything gets passed to the function
  • 32. Resources Serverless Framework - https://serverless.com AWS Lambda - https://aws.amazon.com/lambda My Tutorial - https://lobster1234.github.io/categories/serverless