Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp Function as a Service BBEs #4457

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
be6829b
Update Docker & K8S BBEs
May 3, 2023
a7a1035
Add AWS Lambda echo and context BBEs
May 3, 2023
faebcf9
Update AWS echo and context BBEs
May 3, 2023
0399144
Add S3 and DynamoDB BBEs
May 3, 2023
a7b33a1
Update examples/kubernetes-hello-world/kubernetes-hello-world.md
May 3, 2023
7f7c481
Merge pull request #4382 from praneesha/update-cloud-bbes
May 3, 2023
ca22112
Merge pull request #4383 from praneesha/add-new-aws-lambda-bbes
May 3, 2023
2fa5b4c
Merge pull request #4387 from ballerina-platform/2201.6.x
sm1990 May 3, 2023
35f1cd9
Fix build error
May 4, 2023
7e97b3a
Merge pull request #4390 from praneesha/fix-bbe-gen-error
May 4, 2023
cbc26ca
Fix more BBE gen errors
May 4, 2023
00cec51
Merge pull request #4391 from praneesha/fix-bbe-gen-error
May 4, 2023
c3e04bd
Fix gen errors in Azure BBE
May 4, 2023
f6473cc
Merge pull request #4392 from praneesha/revamp-aws-azure-bbes
May 4, 2023
41196f6
Fix gen error in Azure BBE
May 4, 2023
42ad11a
Merge pull request #4393 from praneesha/revamp-aws-azure-bbes
May 4, 2023
fae6028
Update aws-lambda-hello-world.md
May 7, 2023
5bdd94a
Update aws-lambda-context-execution.md
May 7, 2023
48e172d
Update aws-lambda-s3-trigger.md
May 7, 2023
a5510bb
Update aws-lambda-dynamodb-trigger.md
May 7, 2023
b261a15
Update azure-functions-hello-world.md
May 7, 2023
ba55951
Update aws-lambda-hello-world.md
May 7, 2023
9dc03a5
Rename AWS Lambda execution context BBE
May 7, 2023
0b9b664
Merge pull request #4397 from praneesha/rename-aws-execution-context-bbe
May 7, 2023
8518df9
Add the Azure Functions BBEs
May 7, 2023
ec95b78
Update MD files
May 7, 2023
da74e47
Merge pull request #4398 from praneesha/add-azure-bbes
May 7, 2023
207f051
Fix file names of Azure BBEs
May 8, 2023
53195b7
Merge pull request #4399 from praneesha/fix-build-errors
May 8, 2023
a28bc3a
Fix tips and hyperlinks rendering issues
May 8, 2023
41e58e1
Merge pull request #4407 from praneesha/remove-azure-bbes
May 8, 2023
5ae2294
Add target blank in MD format
May 8, 2023
69f2e49
Merge pull request #4408 from praneesha/fix-hyperlinks-md-format
May 8, 2023
5f807fd
Remove target_blank from hyperlinks
May 8, 2023
5fec387
Merge pull request #4409 from praneesha/fix-links
May 8, 2023
169f0d3
Update Azure BBEs
May 9, 2023
9c7a4b3
Merge pull request #4413 from praneesha/revamp-aws-azure-bbes
May 9, 2023
ce0bc51
Fix structure and formatting of all C2C BBEs
May 9, 2023
398409b
Merge pull request #4414 from praneesha/fix-structure-and-formatting
May 9, 2023
6b3d21e
Add metatags files to all C2C BBEs
May 9, 2023
38ece1b
Merge pull request #4415 from praneesha/add-metatags-to-c2c-bbes
May 9, 2023
73b4b5e
Fix build error and take observability section up
May 10, 2023
6cf50a4
Merge pull request #4416 from praneesha/fix-bbe-gen-error
May 10, 2023
65a0680
Review and update bal codes
May 11, 2023
3dcc258
Merge pull request #4420 from praneesha/check-bal-codes
May 11, 2023
94dbbbc
Update examples/aws-lambda-hello-world/aws-lambda-hello-world.md
Jul 7, 2023
46b96d9
Update examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags
Jul 7, 2023
9676739
Update examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags
Jul 7, 2023
9bb765f
Update examples/azure-functions-hello-world/azure-functions-hello-wor…
Jul 7, 2023
3e5b6cf
Update examples/azure-functions-hello-world/azure-functions-hello-wor…
Jul 7, 2023
5c41c98
Address review comments
Jul 7, 2023
609cb57
Update the Azure hello world description
Jul 7, 2023
31e2fb7
Merge pull request #4676 from praneesha/address-faas-bbe-comments
Jul 10, 2023
e808e79
Merge branch 'master' into revamp-aws-azure-bbes
Jul 10, 2023
c03a76d
Add aggregation BBEs to the FaaS review branch
Jul 11, 2023
3378fbe
Merge pull request #4688 from praneesha/verify-faas-bbes
Jul 11, 2023
7ebf23e
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Jul 12, 2023
de6f3e7
Remove aggregation BBEs
Jul 12, 2023
cd64c34
Merge pull request #4700 from praneesha/remove-aggregation-bbes
Jul 12, 2023
0654896
Revert "Remove manually added aggregation BBEs"
Jul 12, 2023
4d94768
Merge pull request #4701 from ballerina-platform/revert-4700-remove-a…
Jul 12, 2023
f425644
Revert "Add aggregation BBEs to the FaaS review branch"
Jul 12, 2023
e0869f9
Merge pull request #4702 from ballerina-platform/revert-4688-verify-f…
Jul 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions examples/aggregation/aggregation.bal

This file was deleted.

21 changes: 0 additions & 21 deletions examples/aggregation/aggregation.md

This file was deleted.

2 changes: 0 additions & 2 deletions examples/aggregation/aggregation.metatags

This file was deleted.

4 changes: 0 additions & 4 deletions examples/aggregation/aggregation.out

This file was deleted.

3 changes: 0 additions & 3 deletions examples/aws-lambda-deployment/aws_deploy.out

This file was deleted.

27 changes: 0 additions & 27 deletions examples/aws-lambda-deployment/aws_lambda_deployment.bal

This file was deleted.

23 changes: 0 additions & 23 deletions examples/aws-lambda-deployment/aws_lambda_deployment.md

This file was deleted.

1 change: 0 additions & 1 deletion examples/aws-lambda-deployment/bal_new.out

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ballerina/io;
import ballerinax/awslambda;

@awslambda:Function
public function dynamoDBTrigger(awslambda:Context ctx,
awslambda:DynamoDBEvent event) {
io:println(event.Records[0].dynamodb.Keys.toString());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# AWS Lambda DynamoDB trigger

This example creates a function, which will be executed for each entry added to a database in the DynamoDB.

For more information, see the [AWS Lambda learn guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/).

## Set up the prerequisites

For instructions, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-the-prerequisites).

## Write the function

Follow the steps below to write the function.

1. Execute the command below to create a new Ballerina package.

::: out bal_new.out :::

2. Replace the content of the generated Ballerina file with the content below.

::: code aws-lambda-dynamodb-trigger.bal :::

## Build the function

Execute the command below to generate the AWS Lambda artifacts.

::: out bal_build.out :::

## Deploy the function

Execute the AWS CLI command given by the compiler to create and publish the functions by replacing the respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values given in the command with your values.

::: out aws_deploy.out :::

## Invoke the function

Follow the instructions below to create a DynamoDB table for invoking this function.

1. Navigate to [**roles**](https://console.aws.amazon.com/iamv2/home#/roles), and add `AWSLambdaDynamoDBExecutionRole` to the role you created in [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-the-prerequisites).
2. Go to [DynamoDB](https://us-west-1.console.aws.amazon.com/dynamodbv2).
3. Click **Create Table**, enter the table name and partition key, and create the table (if you already have a table created, you can skip this step).
4. Click on the DynamoDB table you created, and then click the **Exports and streams** tab.
5. Click **enable DynamoDB stream details**, and select the key attributes only for the event type.
6. Once it is enabled, click **Create a trigger**, select the `dynamoDBTrigger` from the dropdown, and create a trigger.
7. Go to [**Items**](https://us-west-1.console.aws.amazon.com/dynamodbv2) in the DynamoDB, select the table, and click **Create item** to add an entry to the DynamoDB table to invoke the Lambda function.
8. Go to the AWS Lambda function and check the logs via CloudWatch to see the object identifier in the logs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description: This example creates a function, which will be executed for each entry added to a database in the DynamoDB.
keywords: ballerina, ballerina by example, aws lambda, dynamodb, serverless, cloud, function as a service
1 change: 1 addition & 0 deletions examples/aws-lambda-dynamodb-trigger/aws_deploy.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ aws lambda create-function --function-name dynamoDBTrigger --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-dynamodb-trigger.dynamoDBTrigger --runtime provided --role arn:aws:iam::908363916111:role/lambda-role--layers arn:aws:lambda:us-west-1:134633749276:layer:ballerina-jre11:6 --memory-size 512 --timeout 10
12 changes: 12 additions & 0 deletions examples/aws-lambda-dynamodb-trigger/bal_build.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ bal build
Compiling source
wso2/aws-lambda-dynamodb-trigger:0.1.0

Generating executable
@awslambda:Function: dynamoDBTrigger

Run the following command to deploy each Ballerina AWS Lambda function:
aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb://<project-dir>/aws-lambda-s3-trigger/target/bin/aws-ballerina-lambda-functions.zip --handler aws-lambda-dynamodb-trigger.$FUNCTION_NAME --runtime provided --role $LAMBDA_ROLE_ARN --layers arn:aws:lambda:$REGION_ID:134633749276:layer:ballerina-jre11:6 --memory-size 512 --timeout 10

Run the following command to re-deploy an updated Ballerina AWS Lambda function:
aws lambda update-function-code --function-name $FUNCTION_NAME --zip-file fileb://aws-ballerina-lambda-functions.zip
1 change: 1 addition & 0 deletions examples/aws-lambda-dynamodb-trigger/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ bal new aws-lambda-dynamodb-trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ballerinax/awslambda;

@awslambda:Function
public function ctxinfo(awslambda:Context ctx, json input) returns json|error {
return {
RequestID: ctx.getRequestId(),
DeadlineMS: ctx.getDeadlineMs(),
InvokedFunctionArn: ctx.getInvokedFunctionArn(),
TraceID: ctx.getTraceId(),
RemainingExecTime: ctx.getRemainingExecutionTime()
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# AWS Lambda execution context

The example below demonstrates how the execution context information of an AWS function can be retrieved.

For more information, see the [AWS Lambda learn guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/).

## Set up the prerequisites

For instructions, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-the-prerequisites).

## Write the function

Follow the steps below to write the function.

1. Execute the command below to create a new Ballerina package.

::: out bal_new.out :::

2. Replace the content of the generated Ballerina file with the content below.

::: code aws-lambda-execution-context.bal :::

## Build the function

Execute the command below to generate the AWS Lambda artifacts.

::: out bal_build.out :::

## Deploy the function

Execute the AWS CLI command given by the compiler to create and publish the functions by replacing the respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values given in the command with your values.

::: out aws_deploy.out :::

## Invoke the function

Execute the commands below to invoke the function.

::: out invoke_functions.out :::
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description: The example below demonstrates how the execution context information of an AWS function can be retrieved.
keywords: ballerina, ballerina by example, aws lambda, execution context, serverless, cloud, function as a service
1 change: 1 addition & 0 deletions examples/aws-lambda-execution-context/aws_deploy.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ aws lambda create-function --function-name ctxinfo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-execution-context.ctxinfo --runtime provided --role arn:aws:iam::908363916111:role/lambda-role --layers arn:aws:lambda:us-west-1:134633749276:layer:ballerina-jre11:6 --memory-size 512 --timeout 10
12 changes: 12 additions & 0 deletions examples/aws-lambda-execution-context/bal_build.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ bal build
Compiling source
wso2/aws-lambda-execution-context:0.1.0

Generating executable
@awslambda:Function: ctxinfo

Run the following command to deploy each Ballerina AWS Lambda function:
aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb://<project-dir>/aws-lambda-execution-context/target/bin/aws-ballerina-lambda-functions.zip --handler aws_lambda_deployment.$FUNCTION_NAME --runtime provided --role $LAMBDA_ROLE_ARN --layers arn:aws:lambda:$REGION_ID:134633749276:layer:ballerina-jre11:6 --memory-size 512 --timeout 10

Run the following command to re-deploy an updated Ballerina AWS Lambda function:
aws lambda update-function-code --function-name $FUNCTION_NAME --zip-file fileb://aws-ballerina-lambda-functions.zip
1 change: 1 addition & 0 deletions examples/aws-lambda-execution-context/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ bal new aws-lambda-execution-context
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
$ echo '{"MESSAGE":"HELLO"}' > input.json
$ aws lambda invoke --function-name echo --payload fileb://input.json echo-response.txt
{
"ExecutedVersion": "$LATEST",
"StatusCode": 200
}
$ cat echo-response.txt
{"MESSAGE":"HELLO"}

$ aws lambda invoke --function-name ctxinfo ctxinfo-response.txt
{
"ExecutedVersion": "$LATEST",
Expand Down
9 changes: 9 additions & 0 deletions examples/aws-lambda-hello-world/aws-lambda-hello-world.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ballerina/io;
import ballerinax/awslambda;

// The `@awslambda:Function` annotation marks a function to generate an AWS Lambda function.
@awslambda:Function
public function echo(awslambda:Context ctx, json input) returns json {
io:println(input.toJsonString());
return input;
}
39 changes: 39 additions & 0 deletions examples/aws-lambda-hello-world/aws-lambda-hello-world.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# AWS Lambda - Hello world

This example demonstrates how to write a simple echo function in AWS Lambda.

For more information, see the [AWS Lambda learn guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/).

## Set up the prerequisites

For instructions, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-the-prerequisites).

## Write the function

Follow the steps below to write the function.

1. Execute the command below to create a new Ballerina package.

::: out bal_new.out :::

2. Replace the content of the generated Ballerina file with the content below.

::: code aws-lambda-hello-world.bal :::

## Build the function

Execute the command below to generate the AWS Lambda artifacts.

::: out bal_build.out :::

## Deploy the function

Execute the AWS CLI command given by the compiler to create and publish the functions by replacing the respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values given in the command with your values.

::: out aws_deploy.out :::

## Invoke the function

Execute the commands below to invoke the function.

::: out invoke_functions.out :::
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description: This example demonstrates how to write a simple echo function in AWS Lambda.
keywords: ballerina, ballerina by example, serverless, aws lambda, cloud, function as a service
1 change: 1 addition & 0 deletions examples/aws-lambda-hello-world/aws_deploy.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ aws lambda create-function --function-name echo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-hello-world.echo --runtime provided --role arn:aws:iam::908363916111:role/lambda-role--layers arn:aws:lambda:us-west-1:134633749276:layer:ballerina-jre11:6 --memory-size 512 --timeout 10
12 changes: 12 additions & 0 deletions examples/aws-lambda-hello-world/bal_build.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ bal build
Compiling source
wso2/aws-lambda-hello-world:0.1.0

Generating executable
@awslambda:Function: echo

Run the following command to deploy each Ballerina AWS Lambda function:
aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb://<project-dir>/aws-lambda-hello-world/target/bin/aws-ballerina-lambda-functions.zip --handler aws-lambda-hello-world.$FUNCTION_NAME --runtime provided --role $LAMBDA_ROLE_ARN --layers arn:aws:lambda:$REGION_ID:134633749276:layer:ballerina-jre11:6 --memory-size 512 --timeout 10

Run the following command to re-deploy an updated Ballerina AWS Lambda function:
aws lambda update-function-code --function-name $FUNCTION_NAME --zip-file fileb://aws-ballerina-lambda-functions.zip
1 change: 1 addition & 0 deletions examples/aws-lambda-hello-world/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ bal new aws-lambda-hello-world
8 changes: 8 additions & 0 deletions examples/aws-lambda-hello-world/invoke_functions.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$ echo '{"MESSAGE":"HELLO"}' > input.json
$ aws lambda invoke --function-name echo --payload fileb://input.json echo-response.txt
{
"ExecutedVersion": "$LATEST",
"StatusCode": 200
}
$ cat echo-response.txt
{"MESSAGE":"HELLO"}
8 changes: 8 additions & 0 deletions examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ballerina/io;
import ballerinax/awslambda;

@awslambda:Function
public function s3Trigger(awslambda:Context ctx,
awslambda:S3Event event) {
io:println(event.Records[0].s3.'object.key);
}
Loading
Loading