bene@theodo.co.uk
Ben Ellerby
@EllerbyBen
Ben Ellerby
@EllerbyBen
serverless-transformation
@EllerbyBen
@EllerbyBen
💰 Cost reduction
👷♂️ #NoOps... well LessOps
💻 Developers focus on delivering business value
📈 More scalable
🌳 Greener
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
3.8 3.7, 3.6, 2.7
@EllerbyBen
def handler_name(event, context):
...
return some_value
Event: The event body
dict, list, str, int, float, or NoneType
Context: Meta Data
dict
@EllerbyBen
def my_handler(event, context):
message = 'Hello {} {}!'.format(event['first_name'],
event['last_name'])
return {
'message' : message
}
@EllerbyBen
A handler function is a function of your code triggered by AWS when your lambda is invoked
@EllerbyBen
@EllerbyBen
npm install -g serverless
serverless create
--template aws-python3
--path myService
@EllerbyBen
serverless.yml
handler.py
@EllerbyBen
import json
def hello(event, context):
body = {
"message": "Go Serverless v1.0! Your function executed successfully!",
"input": event
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response
@EllerbyBen
service: myService
provider:
name: aws
runtime: python3.7
functions:
hello:
handler: handler.hello
@EllerbyBen
➜ sls invoke local -f hello
{
"statusCode": 200,
"body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
@EllerbyBen
➜ sls deploy
➜ sls invoke -f hello
{
"statusCode": 200,
"body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
@EllerbyBen
Lambda
S3
Dynamo
API Gateway
Compute
Storage
Data
API Proxy
Cognito
Auth
SQS
Queue
Step Functions
Workflows
EventBridge
Bus
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
Memory | 128MB - 10,240 MB |
Timeout | 900 seconds |
Burst Concurrency | 500-3000 |
/tmp dir storage | 512 MB |
Concurrent Executions | 1,000 ⏫ |
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
AWS Step Functions is a serverless function orchestrator that makes it easy to sequence AWS Lambda functions and multiple AWS services into business-critical applications.
@EllerbyBen
@EllerbyBen
AWSTemplateFormatVersion: '2010-09-09'
Description: An example template for a Step Functions state machine.
Resources:
MyStateMachine:
Type: AWS::StepFunctions::StateMachine
Properties:
StateMachineName: HelloWorld-StateMachine
DefinitionString: |-
{
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Task",
"Resource": "ARN of Function.....",
"End": true
}
}
}
RoleArn: arn-of-role
Tags:
-
Key: "keyname1"
Value: "value1"
-
Key: "keyname2"
Value: "value2"
@EllerbyBen
@EllerbyBen
stepFunctions:
stateMachines:
MyStateMachine:
name: MyMachine
definition:
Comment: "Does something cool"
States:
HelloWorld:
Type: Task
Resource: "HelloLambdaARN"
End: true
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
@EllerbyBen
Artillery is a load testing and smoke testing solution for SREs, developers and QA engineers
@EllerbyBen
config:
target: "https://shopping.service.staging"
phases:
- duration: 60
arrivalRate: 5
name: Warm up
- duration: 120
arrivalRate: 5
rampTo: 50
name: Ramp up load
- duration: 600
arrivalRate: 50
name: Sustained load
payload:
# Load search keywords from an external CSV file and make them available
# to virtual user scenarios as variable "keywords":
path: "keywords.csv"
fields:
- "keywords"
scenarios:
# We define one scenario:
- name: "Search and buy"
flow:
- post:
url: "/search"
body: "kw={{ keywords }}"
# The endpoint responds with JSON, which we parse and extract a field from
# to use in the next request:
capture:
json: "$.results[0].id"
as: "id"
# Get the details of the product:
- get:
url: "/product/{{ id }}/details"
# Pause for 3 seconds:
- think: 3
# Add product to cart:
- post:
url: "/cart"
json:
productId: "{{ id }}"
artillery run search-and-add-to-cart.yml
@EllerbyBen
@EllerbyBen
@EllerbyBen
Combine serverless with artillery and you get serverless-artillery for instant, cheap, and easy performance testing at scale.
@EllerbyBen
@EllerbyBen
@EllerbyBen
"The mission Science Data Center will use AWS Step Function to orchestrate various AWS Lambda functions to check, index, and move files into a master database, and Amazon Simple Storage Service (Amazon S3) for shared storage."
https://aws.amazon.com/blogs/publicsector/uae-mars-mission-uses-aws-advance-scientific-discoveries/
@EllerbyBen
https://aws.amazon.com/blogs/architecture/scaling-neuroscience-research-on-aws/
@EllerbyBen
@EllerbyBen
serverless-transformation