ballerinax/awslambda : 1.0.0
Module Overview
This module provides the capabilities of creating AWS Lambda functions using Ballerina.
Annotation Usage Sample:
1import ballerinax/awslambda;2import ballerina/uuid;3import ballerina/io;45// The `@awslambda:Function` annotation marks a function to6// generate an AWS Lambda function7@awslambda:Function8public function echo(awslambda:Context ctx, json input) returns json {9 return input;10}1112@awslambda:Function13public function uuid(awslambda:Context ctx, json input) returns json {14 return uuid:createType1AsString();15}1617// The `awslambda:Context` object contains request execution18// context information19@awslambda:Function20public 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}2829@awslambda:Function30public function notifySQS(awslambda:Context ctx,31 awslambda:SQSEvent event) returns json {32 return event.Records[0].body;33}3435@awslambda:Function36public function notifyS3(awslambda:Context ctx,37 awslambda:S3Event event) returns json {38 return event.Records[0].s3.'object.key;39}4041@awslambda:Function42public function notifyDynamoDB(awslambda:Context ctx,43 awslambda:DynamoDBEvent event) returns json {44 return event.Records[0].dynamodb.Keys.toString();45}4647@awslambda:Function48public function notifySES(awslambda:Context ctx,49 awslambda:SESEvent event) returns json {50 return event.Records[0].ses.mail.commonHeaders.subject;51}5253@awslambda:Function54public 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.bal2Compiling source3 functions.bal45Generating executable6 functions.jar7 @awslambda:Function: echo, uuid, ctxinfo, notifySQS, notifyS389 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 101112 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. |