Luciano Mammino (@loige)
AWS FEST Compute edition
2023-05-03
👋 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
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)
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)
THANKS!
Grab these slides!