ballerinax/awslambda : 1.0.0

Module Overview

This module offers the capabilities of creating AWS Lambda functions using Ballerina.

Annotation Usage Sample:

1import ballerinax/awslambda;
2import ballerina/uuid;
3import ballerina/io;
4
5// The `@awslambda:Function` annotation marks a function to
6// generate an AWS Lambda function
7@awslambda:Function
8public function echo(awslambda:Context ctx, json input) returns json {
9 return input;
10}
11
12@awslambda:Function
13public function uuid(awslambda:Context ctx, json input) returns json {
14 return uuid:createType1AsString();
15}
16
17// The `awslambda:Context` object contains request execution
18// context information
19@awslambda:Function
20public function ctxinfo(awslambda:Context ctx, json input) returns json|error {
21 json result = { RequestID: ctx.getRequestId(),
22 DeadlineMS: ctx.getDeadlineMs(),
23 InvokedFunctionArn: ctx.getInvokedFunctionArn(),
24 TraceID: ctx.getTraceId(),
25 RemainingExecTime: ctx.getRemainingExecutionTime() };
26 return result;
27}
28
29@awslambda:Function
30public function notifySQS(awslambda:Context ctx,
31 awslambda:SQSEvent event) returns json {
32 return event.Records[0].body;
33}
34
35@awslambda:Function
36public function notifyS3(awslambda:Context ctx,
37 awslambda:S3Event event) returns json {
38 return event.Records[0].s3.'object.key;
39}
40
41@awslambda:Function
42public function notifyDynamoDB(awslambda:Context ctx,
43 awslambda:DynamoDBEvent event) returns json {
44 return event.Records[0].dynamodb.Keys.toString();
45}
46
47@awslambda:Function
48public function notifySES(awslambda:Context ctx,
49 awslambda:SESEvent event) returns json {
50 return event.Records[0].ses.mail.commonHeaders.subject;
51}
52
53@awslambda:Function
54public function apigwRequest(awslambda:Context ctx,
55 awslambda:APIGatewayProxyRequest request) {
56 io:println("Path: ", request.path);
57}

The output of the bal build is as follows:

1$ bal build functions.bal
2Compiling source
3 functions.bal
4
5Generating executable
6 functions.jar
7 @awslambda:Function: echo, uuid, ctxinfo, notifySQS, notifyS3
8
9 Run the following command to deploy each Ballerina AWS Lambda function:
10 aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb://aws-ballerina-lambda-functions.zip --handler functions.$FUNCTION_NAME --runtime provided --role $LAMBDA_ROLE_ARN --layers arn:aws:lambda:$REGION_ID:134633749276:layer:ballerina-jre11:6 --memory-size 512 --timeout 10
11
12 Run the following command to re-deploy an updated Ballerina AWS Lambda function:
13 aws lambda update-function-code --function-name $FUNCTION_NAME --zip-file fileb://aws-ballerina-lambda-functions.zip

Functions

[2]

__process

Process and excute the handler.

__register

Register a function handler with the function and event type.

Classes

[1]

Context

Object to represent an AWS Lambda function execution context.

Records

[21]

APIGatewayProxyRequest

Represents the AWS API Gateway proxy request details received from AWS when the gateway is triggered.

DynamoDBEvent

Represents the DynamoDB event details received from AWS when the DynamoDB notification is triggered.

DynamoDBRecord

Represents the DynamoDB related details.

DynamoDBStreamRecord

Represents the details of the stream related to the DynamoDB.

NameValue

Represents the details of the name related to the simple email service.

S3Bucket

Represents the details of the bucket related to the S3 service.

S3Element

Represents the details of the element related to the S3 service.

S3Event

Represents the S3 event details received from AWS when the S3 notification is triggered.

S3Identity

Represents the details of the identity related to the S3 service.

S3Object

Represents the details of the object related to the S3 service.

S3Record

Represents the S3 bucket notification related details.

SESAction

Represents the details of the action related to the simple email service.

SESCommonHeaders

Represents the simple email service related details.

SESElement

Represents the details of the element related to the simple email service.

SESEvent

Represents the simple email service event details received from AWS when the SES notification is triggered.

SESMail

Represents the details of the email related to the simple email service.

SESReceipt

Represents the details of the receipt related to the simple email service.

SESRecord

Represents the details of the notification related to the simple email service.

SESVerdict

Represents the details of the verdict related to the simple email service.

SQSEvent

Represents the AWS SQS event details received from AWS when the SQS notification is triggered.

SQSRecord

Represents the Amazon simple queue service notification related details.

Annotations

[1]

Function

The annotation, which is used to mark the function as an AWS Lambda function.