Dynamic AWS
Lambda with
LED BY
Luis F. Majano
LUIS F. MAJANO
• CEO Ortus Solutions
• Computer Engineer
• Born in El Salvador => Raised in the USA
• 2023 Leading EU Expansion team (Malaga, Spain 🇪🇸)
• Creator & Maintainer:
ColdBox MVC, TestBox BDD/TDD, CommandBox CLI, ContentBox CMS, etc.
• Creator / Chief Language Engineer BoxLang Programming Language
@lmajano @ortussolutions
• Serverless
• What? Why? When?
• Providers
• Use Cases
• Real Life Case
• Best Practices
Agenda
• BoxLang
• Lambda Runtime
• Lambda Template
Part 1 Part 2
AWS Lambda - Serverless Computing
FaaS
AWS Lambda is a serverless computing service that runs
code in response to events without managing servers,
automatically scaling and charging only for execution time.
What is serverless?
Serverless Computing Evolution
Physical Machines
Virtual Machines
Containers
Lambdas
Focus on Business Logic
Abstraction
Execution Patterns
• API Driven Patterns
• Event Driven Patterns
• Data Streaming Patterns
• Scheduling Patterns
Key Points about Serverless
• Me
• Focus on code abstractions
• Provider
• Auto Scaling
• Fault tolerance
• High Availability
• Metrics and Logging
• No OS updates
• Pay per use ONLY
Fine-Grained Pricing: Never pay for idle
• FREE Tier
• Buy in 100ms increments
• No minimums
• No per-device fees
• No idle fees
How Functions Work
Upload Function
(CI, Manually)
De
fi
ne Function Triggers
(API Calls, Events, Schedules)
Function Execution
(Stateless, Cold Start,
Timeouts)
Different Providers
Different Language Implementations
PHP
Node.js
Python
Go
Ruby
.Net
Core Concept of Serverless is ….
Function = Unit of Work
Common Use Cases
REST Data Processing
Chat Bots
Amazon Alexa IoT
Scheduled Tasks Code Execution AI
Real-Time File Processing
REST (Direct Function URL or API Gateway)
Event Handling
Scheduling with AWS EventBridge
Ortus Use Case : BoxLang Code Playground : try.boxlang.io
Wanna play?
64MB RAM
600 KB
8 MB
<Your
Code>
Wanna play?
• try.boxlang.io
• Internet playground for BoxLang
• First production BoxLang applications
• Powered by our MiniServer and AWS Lambda
Runtimes
Cool Stats
• Average executions per day: 32,000+
• Average execution time: 32ms
• Monthly Bill ????
$0.0000000000
AWS Lambda Best Practices
• Code is stateless
• Leverage external services: S3, ElastiCache, RDS,
etc.
• Ephemeral Disk Capacity
• 512MB by default -> 10GB if needed (But you pay)
• Max Timeout = 15 Minutes, lower it to your convenience,
or pay for it :)
AWS Lambda Best Practices
• Concurrent Executions: 1000
• Beware the ColdStart
• Use static constructs to avoid re-creations per request
• Payload Size (Careful Here)
• Request: 6MB Synchronous, 256KB asynchronous
• Response: 6MB
Logging & Metrics
• USE IT! It’s already included
• Enable X-Ray + Lambda Service Traces
• Enable Enhanced Monitoring
• A wealth of debugging data is available!
Deployment Limits
• 50 MB zip or jar
fi
le
• 250MB unzipped
• Up to 5 Layers (Dependency Jars)
• Recommendations:
• Create a Fat/Shaded Jar
• Use Container Images -> 10GB
• Use our BoxLang Template!
• But, remember, focused work units is what you want.
Power Levels
• Had no idea at
fi
rst!
• You don’t choose CPU, you choose the memory
• More Memory => More CPU you get
• From 128bm => 10GB in 1GB increments
• Want to save money?
Choose ARM and not x86, way cheaper!
• Geek way to save money?
AWS Lambda Power Tuning: https://github.com/alexcasalboni/aws-lambda-power-tuning
SAM - Your new Best Friend
• Template-Driven resource management model
• Fancy words for Infrastructure as Code
• Supports anything AWS
• Included CLI
• Great for testing locally
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html
DYNAMIC : MODULAR : PRODUCTIVE
Part 2
BoxLang is a modular dynamic language for the JVM, aiming to
make your development more productive, expressive, functional,
and available everywhere.
DYNAMIC : MODULAR : PRODUCTIVE
Part 2
Multi-Runtime Architecture
Any OS
Docker MiniServer CommandBox Servlet Lambda Azure Android WebAssembly
In Dev Soon Soon
8 MB
9 MB 8 MB
15 MB
15 MB
160 MB
BoxLang Lambda Runtime
BoxLang Lambda Runtime
• Leverages the AWS Java SDK
• BoxLang implements the AWS Runtime Handler for you
• Bootstraps the runtime (Con
fi
gurations + Modules + Dependencies)
• Tuned for fast startups
Lambda Flow
• Lambda Handler:
• ortus.boxlang.runtime.aws.LambdaRunner
:
:
handleRequest
• Acts as a Front Controller
• Inspects incoming Request
• Automatic logging/tracing
• Automatic error handling
• Delegates to the appropriate BoxLang Class + Function
• Automatic response handling
BoxLang Lambda Handler
• Implement Handlers as BoxLang Classes
• Class by Convention: Lambda.bx
• 1 method by convention: run( event, context, response )
• 1 Optional Application.bx for life-cycles or activating framework features
BoxLang Handlers
• Run() function by convention
• Event = Struct of the request
• Context = AWS Context Object
• Response = Struct of response data (optional)
• Return:
• Nothing (Use the response struct)
• Simple Value
• Complex Values
BoxLang Lambda
BoxLang Lambda
• A Struct
• Lambda Invocation Types
• Manual input
• Function URL Request
BoxLang Event Struct
https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html
{
"version": "2.0",
"routeKey": "$default",
"rawPath": "/my/path",
"rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value",
"cookies": [
"cookie1",
"cookie2"
],
"headers": {
"header1": "value1",
"header2": "value1,value2"
},
"queryStringParameters": {
"parameter1": "value1,value2",
"parameter2": "value"
},
"requestContext": {
"accountId": "123456789012",
"apiId": "<urlid>",
"authentication": null,
"authorizer": {
"iam": {
"accessKey": "AKIA
.
.
.
",
"accountId": "111122223333",
"callerId": "AIDA
.
.
.
",
"cognitoIdentity": null,
"principalOrgId": null,
"userArn": "arn:aws:iam
:
:
111122223333:user/example-user",
"userId": "AIDA
.
.
.
"
}
},
"domainName": "<url-id>.lambda-url.us-west-2.on.aws",
"domainPrefix": "<url-id>",
"http": {
"method": "POST",
"path": "/my/path",
"protocol": "HTTP/1.1",
"sourceIp": "123.123.123.123",
"userAgent": "agent"
},
"requestId": "id",
"routeKey": "$default",
"stage": "$default",
• A Java object
• com.amazonaws.services.lambda.runtime.Context
AWS Lambda Context
https://docs.aws.amazon.com/lambda/latest/dg/java-context.html
• We build the response object for you according to your return
• Return:
• Nothing (Use the response struct)
• statusCode: numeric
• headers: struct
• Body: anything
• Cookies : array
• Simple Value
• Complex Values
AWS Lambda Response
• Lambda exposed as a URL
• Run() function by convention
• Add as many public functions as you want
• Execute them via the x-bx-function header
• Class Routing
• `/{ClassName}` -> ClassName.bx : run()
Lambda Multi-Function Routing
BoxLang Lambda Template
• Turnkey Template for Lambda Development
• Unit + Integration Testing
• JUnit/TestBox + SAM
• Gradle
• Java Dependencies + Packaging + Testing
• CommandBox
• BoxLang Dependencies
• Github Actions CI
• Testing -> Packaging -> Deployment
https://github.com/ortus-boxlang/bx-aws-lambda-template
Package
Getting Started
Try Boxlang
An online code playground built on
the MiniServer + AWS Lambda
Runtimes.
Docs
Learn about BoxLang, and contribute
to our extensive documentation.
Community
Join our community and get help,
tips and more.
x.com/tryboxlang
www.boxlang.io
linkedin.com/company/tryboxlang
facebook.com/tryboxlang
youtube.com/ortussolutions
Questions?
THANK YOU

June Webinar: BoxLang-Dynamic-AWS-Lambda

  • 1.
    Dynamic AWS Lambda with LEDBY Luis F. Majano
  • 2.
    LUIS F. MAJANO •CEO Ortus Solutions • Computer Engineer • Born in El Salvador => Raised in the USA • 2023 Leading EU Expansion team (Malaga, Spain 🇪🇸) • Creator & Maintainer: ColdBox MVC, TestBox BDD/TDD, CommandBox CLI, ContentBox CMS, etc. • Creator / Chief Language Engineer BoxLang Programming Language @lmajano @ortussolutions
  • 3.
    • Serverless • What?Why? When? • Providers • Use Cases • Real Life Case • Best Practices Agenda • BoxLang • Lambda Runtime • Lambda Template Part 1 Part 2
  • 4.
    AWS Lambda -Serverless Computing FaaS
  • 5.
    AWS Lambda isa serverless computing service that runs code in response to events without managing servers, automatically scaling and charging only for execution time. What is serverless?
  • 6.
    Serverless Computing Evolution PhysicalMachines Virtual Machines Containers Lambdas Focus on Business Logic Abstraction
  • 7.
    Execution Patterns • APIDriven Patterns • Event Driven Patterns • Data Streaming Patterns • Scheduling Patterns
  • 8.
    Key Points aboutServerless • Me • Focus on code abstractions • Provider • Auto Scaling • Fault tolerance • High Availability • Metrics and Logging • No OS updates • Pay per use ONLY
  • 9.
    Fine-Grained Pricing: Neverpay for idle • FREE Tier • Buy in 100ms increments • No minimums • No per-device fees • No idle fees
  • 10.
    How Functions Work UploadFunction (CI, Manually) De fi ne Function Triggers (API Calls, Events, Schedules) Function Execution (Stateless, Cold Start, Timeouts)
  • 11.
  • 12.
  • 13.
    Core Concept ofServerless is …. Function = Unit of Work
  • 14.
    Common Use Cases RESTData Processing Chat Bots Amazon Alexa IoT Scheduled Tasks Code Execution AI
  • 15.
  • 16.
    REST (Direct FunctionURL or API Gateway)
  • 17.
  • 18.
  • 19.
    Ortus Use Case: BoxLang Code Playground : try.boxlang.io
  • 20.
    Wanna play? 64MB RAM 600KB 8 MB <Your Code>
  • 21.
    Wanna play? • try.boxlang.io •Internet playground for BoxLang • First production BoxLang applications • Powered by our MiniServer and AWS Lambda Runtimes
  • 22.
    Cool Stats • Averageexecutions per day: 32,000+ • Average execution time: 32ms • Monthly Bill ???? $0.0000000000
  • 23.
    AWS Lambda BestPractices • Code is stateless • Leverage external services: S3, ElastiCache, RDS, etc. • Ephemeral Disk Capacity • 512MB by default -> 10GB if needed (But you pay) • Max Timeout = 15 Minutes, lower it to your convenience, or pay for it :)
  • 24.
    AWS Lambda BestPractices • Concurrent Executions: 1000 • Beware the ColdStart • Use static constructs to avoid re-creations per request • Payload Size (Careful Here) • Request: 6MB Synchronous, 256KB asynchronous • Response: 6MB
  • 25.
    Logging & Metrics •USE IT! It’s already included • Enable X-Ray + Lambda Service Traces • Enable Enhanced Monitoring • A wealth of debugging data is available!
  • 26.
    Deployment Limits • 50MB zip or jar fi le • 250MB unzipped • Up to 5 Layers (Dependency Jars) • Recommendations: • Create a Fat/Shaded Jar • Use Container Images -> 10GB • Use our BoxLang Template! • But, remember, focused work units is what you want.
  • 27.
    Power Levels • Hadno idea at fi rst! • You don’t choose CPU, you choose the memory • More Memory => More CPU you get • From 128bm => 10GB in 1GB increments • Want to save money? Choose ARM and not x86, way cheaper! • Geek way to save money? AWS Lambda Power Tuning: https://github.com/alexcasalboni/aws-lambda-power-tuning
  • 28.
    SAM - Yournew Best Friend • Template-Driven resource management model • Fancy words for Infrastructure as Code • Supports anything AWS • Included CLI • Great for testing locally https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html
  • 29.
    DYNAMIC : MODULAR: PRODUCTIVE Part 2
  • 30.
    BoxLang is amodular dynamic language for the JVM, aiming to make your development more productive, expressive, functional, and available everywhere. DYNAMIC : MODULAR : PRODUCTIVE Part 2
  • 31.
    Multi-Runtime Architecture Any OS DockerMiniServer CommandBox Servlet Lambda Azure Android WebAssembly In Dev Soon Soon 8 MB 9 MB 8 MB 15 MB 15 MB 160 MB
  • 32.
  • 33.
    BoxLang Lambda Runtime •Leverages the AWS Java SDK • BoxLang implements the AWS Runtime Handler for you • Bootstraps the runtime (Con fi gurations + Modules + Dependencies) • Tuned for fast startups
  • 34.
  • 35.
    • Lambda Handler: •ortus.boxlang.runtime.aws.LambdaRunner : : handleRequest • Acts as a Front Controller • Inspects incoming Request • Automatic logging/tracing • Automatic error handling • Delegates to the appropriate BoxLang Class + Function • Automatic response handling BoxLang Lambda Handler
  • 36.
    • Implement Handlersas BoxLang Classes • Class by Convention: Lambda.bx • 1 method by convention: run( event, context, response ) • 1 Optional Application.bx for life-cycles or activating framework features BoxLang Handlers
  • 37.
    • Run() functionby convention • Event = Struct of the request • Context = AWS Context Object • Response = Struct of response data (optional) • Return: • Nothing (Use the response struct) • Simple Value • Complex Values BoxLang Lambda
  • 38.
  • 39.
    • A Struct •Lambda Invocation Types • Manual input • Function URL Request BoxLang Event Struct https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html { "version": "2.0", "routeKey": "$default", "rawPath": "/my/path", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": [ "cookie1", "cookie2" ], "headers": { "header1": "value1", "header2": "value1,value2" }, "queryStringParameters": { "parameter1": "value1,value2", "parameter2": "value" }, "requestContext": { "accountId": "123456789012", "apiId": "<urlid>", "authentication": null, "authorizer": { "iam": { "accessKey": "AKIA . . . ", "accountId": "111122223333", "callerId": "AIDA . . . ", "cognitoIdentity": null, "principalOrgId": null, "userArn": "arn:aws:iam : : 111122223333:user/example-user", "userId": "AIDA . . . " } }, "domainName": "<url-id>.lambda-url.us-west-2.on.aws", "domainPrefix": "<url-id>", "http": { "method": "POST", "path": "/my/path", "protocol": "HTTP/1.1", "sourceIp": "123.123.123.123", "userAgent": "agent" }, "requestId": "id", "routeKey": "$default", "stage": "$default",
  • 40.
    • A Javaobject • com.amazonaws.services.lambda.runtime.Context AWS Lambda Context https://docs.aws.amazon.com/lambda/latest/dg/java-context.html
  • 41.
    • We buildthe response object for you according to your return • Return: • Nothing (Use the response struct) • statusCode: numeric • headers: struct • Body: anything • Cookies : array • Simple Value • Complex Values AWS Lambda Response
  • 42.
    • Lambda exposedas a URL • Run() function by convention • Add as many public functions as you want • Execute them via the x-bx-function header • Class Routing • `/{ClassName}` -> ClassName.bx : run() Lambda Multi-Function Routing
  • 43.
    BoxLang Lambda Template •Turnkey Template for Lambda Development • Unit + Integration Testing • JUnit/TestBox + SAM • Gradle • Java Dependencies + Packaging + Testing • CommandBox • BoxLang Dependencies • Github Actions CI • Testing -> Packaging -> Deployment https://github.com/ortus-boxlang/bx-aws-lambda-template
  • 44.
  • 45.
    Getting Started Try Boxlang Anonline code playground built on the MiniServer + AWS Lambda Runtimes. Docs Learn about BoxLang, and contribute to our extensive documentation. Community Join our community and get help, tips and more. x.com/tryboxlang www.boxlang.io linkedin.com/company/tryboxlang facebook.com/tryboxlang youtube.com/ortussolutions
  • 46.