Building Scaleable Serverless Event-Driven Computing with AWS Lambda powered by BoxLang

ortussolutions 122 views 32 slides Jun 27, 2024
Slide 1
Slide 1 of 32
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32

About This Presentation

Explore how to build scalable, serverless event-driven applications using AWS Lambda powered by BoxLang. This session dives into leveraging Lambda's capabilities to handle event-driven computing efficiently. Whether new to serverless architecture or looking to enhance your skills, join us to lea...


Slide Content

ROOM A
PRESENTED BY
GAVIN PICKIN
Building Scalable Serverless
Event-Driven Computing
with AWS Lambda
powered by
INTO THE BOX 2024

GAVIN PICKIN
SPEAKER AT ITB 2024
•Software Consultant for Ortus
•Work with ColdBox, CommandBox,
ContentBox APIs and VueJS every day!
•Working with Coldfusion since 1999 - V4
•Love learning and sharing the lessons learned
•From New Zealand, live in Bakersfield, Ca
•Loving wife, lots of kids, and countless critters

AWS Lambda?
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang

Why AWS Lambda?
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
AWS Lambda is a compute service that runs
your code in response to events and
automatically manages the compute
resources, making it the fastest way to turn an
idea into a modern, production, serverless
applications.
https://aws.amazon.com/lambda/

What is Serverless?
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
●Most people refer to Lambda a “serverless” programming
model.
●Serverless doesn’t mean that there are no servers
involved.
●There are always servers involved.
https://aws.amazon.com/lambda/

What is Serverless?
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
●You just don’t see them
●You don’t manage them
●You can login and touch them.
●You write code for a specific runtime
●Deploy it to the serverless environment.
●Lambda takes care of everything else, including
scalability and core security.
https://aws.amazon.com/lambda/

Benefits of Lambda

●No need for managing servers
●Automatic scaling
●Pay-as-you-go pricing
●Performance optimization

INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://aws.amazon.com/lambda/

Features of AWS Lambda?
●Extend other AWS services with custom logic
●Build custom backend services
●Bring your own code
●Completely automated administration
●Built-in fault tolerance
●Package and deploy functions as container images
●Automatic scaling
●Connect to relational databases
●Fine-grained control over performance
●Connect to shared file systems
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://aws.amazon.com/lambda/features/

Features of AWS Lambda?
●Run code in response to Amazon CloudFront requests
●Orchestrate multiple functions
●Integrated security model
●Trust and integrity controls
●Only pay for what you use
●Flexible resource model
●Integrate Lambda with your favorite operational tools
●Achieve up to 34% better price performance with functions
powered by Graviton2
●Monitoring and observability

INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://aws.amazon.com/lambda/features/

Use Cases for Lambda

●Quickly process data at scale
●Run interactive web and mobile backends
●Enable powerful ML insights
●Create event-driven applications
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://aws.amazon.com/lambda/features/

Lambda - Pricing
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://aws.amazon.com/lambda/pricing/

Getting started with BoxLang AWS Lambdas
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://boxlang.ortusbooks.com/getting-started/installation/binaries

Getting started with BoxLang AWS Lambdas
This repository contains the AWS Lambda Runtime for
the BoxLang language. This runtime allows you to run
BoxLang code in AWS Lambda functions. The runtime is
built using the AWS Lambda Custom Runtime API and
the BoxLang interpreter.
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://github.com/ortus-boxlang/boxlang-aws-lambda

BoxLang AWS Lambda - Usage
To use it, you need to create a Lambda function and
specify Java 21 as the runtime. The class that executes
your BoxLang code is
ortus.boxlang.runtime.aws.LambdaRunner. By
convention it will execute a Lambda.bx file in the root
(/var/task/Lambda.bx) of the Lambda function, via the
run() method.
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://github.com/ortus-boxlang/boxlang-aws-lambda

BoxLang AWS Lambda - Usage
Method Signature:
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://github.com/ortus-boxlang/boxlang-aws-lambda
// Lambda.bx
class{

function run( event, context, response ){
// Your code here
}

}

BoxLang AWS Lambda - Run Arguments
Run Arguments
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://github.com/ortus-boxlang/boxlang-aws-lambda
●The event parameter is the event data that is passed to the Lambda function as
a Struct.
●The context parameter is the context object that is passed to the Lambda
function. This matches the AWS Lambda context object:
com.amazonaws.services.lambda.runtime.Context.
●The response parameter is the response object that is passed to the Lambda
function.

BoxLang AWS Lambda - Response Struct
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://github.com/ortus-boxlang/boxlang-aws-lambda
The response object is a Struct that you can use to set the response data. The
response object has the following keys:

●statusCode : The HTTP status code for the response.
●headers : A Struct of headers to send in the response.
●body : The body of the response, which can be anything.

The BoxLang lambda runner will return the response object as the response to
the Lambda function as a JSON object.

BoxLang AWS Lambda - Testing Locally
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://github.com/ortus-boxlang/boxlang-aws-lambda
Build

gradle shadowJar
gradle buildMainZip

BoxLang AWS Lambda - Testing Locally
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html
The AWS Serverless Application Model (AWS SAM) is a
toolkit that improves the developer experience of building
and running serverless applications on AWS.

Requires: Docker running

BoxLang AWS Lambda - AWS SAM benefits:
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html
●Define your application infrastructure code quickly, using less code
●Manage your serverless applications through their entire
development lifecycle
●Quickly provision permissions between resources with AWS SAM
connectors
●Continuously sync local changes to the cloud as you develop
●Manage your Terraform serverless applications

Invoking Lambda Locally with Sample Data
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang

sam local invoke bxFunction
--event=workbench/sampleEvents/api.json

sam local invoke bxFunction
--event=workbench/sampleEvents/event.json

Invoking Lambda Locally with Debug Mode
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang

sam local invoke bxFunction
--event=workbench/sampleEvents/api.json --debug

sam local invoke bxFunction
--event=workbench/sampleEvents/event.json --debug

Custom Lambda Function
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang

If you don't want to use the convention of Lambda.bx
then you can setup an environment variable called:
BOXLANG_LAMBDA_CLASS

with the full path to the BoxLang class that will execute
your code.
The class must have a run() method that matches the
signature above.

Custom Lambda Function
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang

If you don't want to use the convention of Lambda.bx
then you can setup an environment variable called:
BOXLANG_LAMBDA_CLASS

with the full path to the BoxLang class that will execute
your code.
The class must have a run() method that matches the
signature above.

Debugging your Lambda Function
INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang

You can enable debug mode by setting the environment
variable BOXLANG_LAMBDA_DEBUG to true.

This will output debug information to the Lambda logs.

INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
// Lambda.bx
class{

function run( event, context, response ){
// response.statusCode = 200; set by default
response.headers = {
"Content-Type" : "text/plain"
};
response.body = "Hello World";
}

}

Hello World

INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
However, if you don't even want to deal with the response struct, you can just use
a return and whatever you return will be placed for you in the response.body.

// Lambda.bx
class{

function run( event, context ){
return "Hello World";
}

}
Skip the response object

INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
However, if you don't even want to deal with the response struct, you can just use
a return and whatever you return will be placed for you in the response.body.

// Lambda.bx
class{

function run( event, context ){
return "Hello World";
}

}
Skip the response object

INTO THE BOX 2024
SUBTITLE - IF NEEDED
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang

INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang

In order to deploy your function to AWS Lambda, you need to package the
runtime and your BoxLang code into a zip file. The zip file should contain the
following structure:

+ Lambda.bx
/lib
+ boxlang-aws-lambda-1.0.0-all.jar


Packaging your BoxLang Lambda

INTO THE BOX 2024
Building Scalable Serverless Event-Driven Computing with AWS Lambda - powered by BoxLang
●Brian Klaas - the CFML AWS Guy
Great AWS Content including NodeJS Lambdas, StepFunctions and much more
https://brianklaas.net/

Interesting Links

INTO THE BOX 2024
THANK YOU TO OUR
SPONSORS
INTO THE BOX 2024