Luciano Mammino PRO
Cloud developer, entrepreneur, fighter, butterfly maker! #nodejs #javascript - Author of https://www.nodejsdesignpatterns.com , Founder of https://fullstackbulletin.com
Luciano Mammino (@loige)
Cloud Native 2023
2023-03-30
👋 I'm Luciano (🇮🇹🍕🍝🤌)
👨💻 Senior Architect @ fourTheorem
📔 Co-Author of Node.js Design Patterns 👉
Grab the slides
✉️ Reach out to us at hello@fourTheorem.com
😇 We are always looking for talent: fth.link/careers
We can help with:
Cloud Migrations
Training & Cloud enablement
Building high-performance serverless applications
Cutting cloud costs
We host a weekly podcast about AWS
A way of running applications in the cloud
Of course, there are servers... we just don't manage them
You pay for what you use
Small units of compute (functions), triggered by events
More focus on the business logic (generally)
Increased team agility (mostly)
Automatic scalability (sorta)
Not a universal solution, but it can work well in many situations!
FaaS offering in AWS
Can be triggered by different kinds of events
Cost = Allocated Memory 𝒙 time
Cost = Allocated Memory 𝒙 time
512 MB = $0.0000000083/ms
Executing a lambda for 15 mins...
0.0000000083 * 900000 = 0.007 $
You don't explicitly configure it:
CPU scales based on memory
You don't explicitly configure it:
CPU scales based on memory
Memory | vCPUs |
---|---|
128 - 3008 MB | 2 |
3009 - 5307 MB | 3 |
5308 - 7076 MB | 4 |
7077 - 8845 MB | 5 |
8846+ MB | 6 |
export const handler = async(event, context) => {
// ... get data from event
// ... run business logic
// ... return a result
}
export const handler = async(event, context) => {
// ... get data from event
const { url } = event
// ... run business logic
const res = await fetch(url)
console.info(`Status of ${url} : ${res.status}`)
// ... return a result
return res.status
}
Node.js
Python
Java
.NET
Go
Ruby
Custom
Node.js
Python
Java
.NET
Go
Ruby
Custom
RUST?!
use lambda_runtime::{service_fn, LambdaEvent, Error};
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Error> {
let func = service_fn(func);
lambda_runtime::run(func).await?;
Ok(())
}
async fn func(event: LambdaEvent<Value>) -> Result<Value, Error> {
let (event, _context) = event.into_parts();
let first_name = event["firstName"].as_str().unwrap_or("world");
Ok(json!({ "message": format!("Hello, {}!", first_name) }))
}
Your Rust Lambda handler
Runs the handler
Extra boilerplate 🤷♀️
Commands
cargo lambda new - scaffolds a new project
cargo lambda watch - starts a dev environment (lambda emulator)
cargo lambda invoke (sends an event to the dev environment)
cargo lambda build (builds the lambda)
cargo lambda deploy (deploys the lambda to AWS)
DEMO 🤞
Some example use cases:
# template.yaml
AWSTemplateFormatVersion : '2010-09-09'
Transform:
- AWS::Serverless-2016-10-31
Description: |
A sample Serverless project triggered from S3 CreateObject events
Resources:
ExampleFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs18.x
Handler: index.handler
Events:
S3CreateObject:
Type: S3
Properties:
Bucket: !Ref MyPhotoBucket
Events: s3:ObjectCreated:*
MyPhotoBucket:
Type: AWS::S3::Bucket
SAM Works with Cargo Lambda (still experimental):
Note: Cargo Lambda also works with CDK
(github.com/cargo-lambda/cargo-lambda-cdk)
A step function that can test different configurations of your Lambda
🤨
🤔
THANKS!
Grab these slides!
By Luciano Mammino
Rust is taking the software engineering world by storm, but how does it affect serverless? In AWS it’s not even a supported runtime, so how can we even use it… and should we even try to do that? Spoiler: yes we should and it’s actually quite easy to get started with it!
Cloud developer, entrepreneur, fighter, butterfly maker! #nodejs #javascript - Author of https://www.nodejsdesignpatterns.com , Founder of https://fullstackbulletin.com