ballerinax/awslambda0.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 function and event type

Classes

[1]

Context

Object to represent an AWS Lambda function execution context.

Records

[21]

APIGatewayProxyRequest

APIGatewayProxyRequest

DynamoDBEvent

DynamoDBEvent

DynamoDBRecord

DynamoDBRecord

DynamoDBStreamRecord

DynamoDBStreamRecord

NameValue

NameValue

S3Bucket

S3Bucket details.

S3Element

S3Element

S3Event

S3Event

S3Identity

S3Identity.

S3Object

S3Object

S3Record

S3Record

SESAction

Simple Email Service Action

SESCommonHeaders

SESCommonHeaders

SESElement

Simple Email Service Element

SESEvent

Simple Email Service Event

SESMail

Simple Email Service Mail

SESReceipt

Simple Email Service Receipt

SESRecord

Simple Email Service Record

SESVerdict

Simple Email Service Verdict

SQSEvent

SQSEvent

SQSRecord

SQSRecord

Annotations

[1]

Function

@awslambda:Function annotation