From be6829b9653c724dcc11cd53e0f100c159ac9200 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Wed, 3 May 2023 13:24:25 +0530 Subject: [PATCH 01/38] Update Docker & K8S BBEs --- .../Cloud.toml | 0 .../build_output.out | 0 .../docker-hello-world.bal} | 0 .../docker-hello-world.md} | 6 +- .../docker_images.out | 0 .../docker_run.out | 0 .../execute_curl.out | 0 examples/index.json | 67 +++++++++++++++---- .../Cloud.toml | 0 .../build_output.out | 0 .../docker_push.out | 0 .../execute_curl.out | 0 .../kubectl_apply.out | 0 .../kubectl_expose.out | 0 .../kubectl_pods.out | 0 .../kubectl_svc.out | 0 .../kubernetes-hello-world.bal} | 0 .../kubernetes-hello-world.md} | 4 +- .../minikube_ip.out | 0 19 files changed, 59 insertions(+), 18 deletions(-) rename examples/{c2c-docker-deployment => docker-hello-world}/Cloud.toml (100%) rename examples/{c2c-docker-deployment => docker-hello-world}/build_output.out (100%) rename examples/{c2c-docker-deployment/c2c_docker_deployment.bal => docker-hello-world/docker-hello-world.bal} (100%) rename examples/{c2c-docker-deployment/c2c_docker_deployment.md => docker-hello-world/docker-hello-world.md} (91%) rename examples/{c2c-docker-deployment => docker-hello-world}/docker_images.out (100%) rename examples/{c2c-docker-deployment => docker-hello-world}/docker_run.out (100%) rename examples/{c2c-docker-deployment => docker-hello-world}/execute_curl.out (100%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/Cloud.toml (100%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/build_output.out (100%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/docker_push.out (100%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/execute_curl.out (100%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/kubectl_apply.out (100%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/kubectl_expose.out (100%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/kubectl_pods.out (100%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/kubectl_svc.out (100%) rename examples/{c2c-k8s-deployment/c2c_k8s_deployment.bal => kubernetes-hello-world/kubernetes-hello-world.bal} (100%) rename examples/{c2c-k8s-deployment/c2c_k8s_deployment.md => kubernetes-hello-world/kubernetes-hello-world.md} (91%) rename examples/{c2c-k8s-deployment => kubernetes-hello-world}/minikube_ip.out (100%) diff --git a/examples/c2c-docker-deployment/Cloud.toml b/examples/docker-hello-world/Cloud.toml similarity index 100% rename from examples/c2c-docker-deployment/Cloud.toml rename to examples/docker-hello-world/Cloud.toml diff --git a/examples/c2c-docker-deployment/build_output.out b/examples/docker-hello-world/build_output.out similarity index 100% rename from examples/c2c-docker-deployment/build_output.out rename to examples/docker-hello-world/build_output.out diff --git a/examples/c2c-docker-deployment/c2c_docker_deployment.bal b/examples/docker-hello-world/docker-hello-world.bal similarity index 100% rename from examples/c2c-docker-deployment/c2c_docker_deployment.bal rename to examples/docker-hello-world/docker-hello-world.bal diff --git a/examples/c2c-docker-deployment/c2c_docker_deployment.md b/examples/docker-hello-world/docker-hello-world.md similarity index 91% rename from examples/c2c-docker-deployment/c2c_docker_deployment.md rename to examples/docker-hello-world/docker-hello-world.md index aa26d55d08..1ffabc6bbc 100644 --- a/examples/c2c-docker-deployment/c2c_docker_deployment.md +++ b/examples/docker-hello-world/docker-hello-world.md @@ -1,9 +1,9 @@ -# Docker +# Docker Ballerina supports generating Docker artifacts from code without any additional configuration. This simplifies the experience of developing and deploying Ballerina code in the cloud. Code to Cloud builds the containers and required artifacts by deriving the required values from the code. If you want to override the default values taken by the compiler, you can use a `Cloud.toml` file. -For more information, see [Code to Cloud Deployment](/learn/run-in-the-cloud/code-to-cloud/code-to-cloud-deployment/). +For more information, see [Code to Cloud Deployment](/learn/run-in-the-cloud/code-to-cloud-deployment/). -::: code c2c_docker_deployment.bal ::: +::: code docker-hello-world.bal ::: Before you build the package, you need to override some default values taken by the compiler. To do this, create a filed named `Cloud.toml` in the package directory, and add the content below to it. For all the supported key value properties, see [Code to Cloud specification](https://github.com/ballerina-platform/ballerina-spec/blob/master/c2c/code-to-cloud-spec.md). diff --git a/examples/c2c-docker-deployment/docker_images.out b/examples/docker-hello-world/docker_images.out similarity index 100% rename from examples/c2c-docker-deployment/docker_images.out rename to examples/docker-hello-world/docker_images.out diff --git a/examples/c2c-docker-deployment/docker_run.out b/examples/docker-hello-world/docker_run.out similarity index 100% rename from examples/c2c-docker-deployment/docker_run.out rename to examples/docker-hello-world/docker_run.out diff --git a/examples/c2c-docker-deployment/execute_curl.out b/examples/docker-hello-world/execute_curl.out similarity index 100% rename from examples/c2c-docker-deployment/execute_curl.out rename to examples/docker-hello-world/execute_curl.out diff --git a/examples/index.json b/examples/index.json index 3e6e4653fa..e76ca01424 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4313,23 +4313,30 @@ ] }, { - "title": "Code to Cloud", + "title": "Docker", "column": 0, "category": "Deployment", "samples": [ { - "name": "Docker", - "url": "c2c-docker-deployment", + "name": "Hello world", + "url": "docker-hello-world", "verifyBuild": true, "verifyOutput": false, "disableVerificationReason": "Needs prerequisite condition", "disablePlayground": true, "isLearnByExample": false - }, + } + ] + }, + { + "title": "Kubernetes", + "column": 1, + "category": "Deployment", + "samples": [ { - "name": "Kubernetes", - "url": "c2c-k8s-deployment", - "verifyBuild": true, + "name": "Hello world", + "url": "kubernetes-hello-world", + "verifyBuild": false, "verifyOutput": false, "disableVerificationReason": "Needs prerequisite condition", "disablePlayground": true, @@ -4338,13 +4345,22 @@ ] }, { - "title": "Function as a Service", - "column": 1, + "title": "AWS Lambda", + "column": 2, "category": "Deployment", "samples": [ { - "name": "Azure Functions", - "url": "azure-functions-deployment", + "name": "Hello world", + "url": "aws-lambda-hello-world", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "Context execution", + "url": "aws-lambda-context-execution", "verifyBuild": false, "verifyOutput": false, "disableVerificationReason": "Needs prerequisite condition", @@ -4352,8 +4368,33 @@ "isLearnByExample": false }, { - "name": "AWS Lambda", - "url": "aws-lambda-deployment", + "name": "S3 trigger", + "url": "aws-lambda-s3-trigger", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "DynamoDB trigger", + "url": "aws-lambda-dynamodb-trigger", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + } + ] + }, + { + "title": "Azure Functions", + "column": 3, + "category": "Deployment", + "samples": [ + { + "name": "Hello world", + "url": "azure-functions-hello-world", "verifyBuild": false, "verifyOutput": false, "disableVerificationReason": "Needs prerequisite condition", diff --git a/examples/c2c-k8s-deployment/Cloud.toml b/examples/kubernetes-hello-world/Cloud.toml similarity index 100% rename from examples/c2c-k8s-deployment/Cloud.toml rename to examples/kubernetes-hello-world/Cloud.toml diff --git a/examples/c2c-k8s-deployment/build_output.out b/examples/kubernetes-hello-world/build_output.out similarity index 100% rename from examples/c2c-k8s-deployment/build_output.out rename to examples/kubernetes-hello-world/build_output.out diff --git a/examples/c2c-k8s-deployment/docker_push.out b/examples/kubernetes-hello-world/docker_push.out similarity index 100% rename from examples/c2c-k8s-deployment/docker_push.out rename to examples/kubernetes-hello-world/docker_push.out diff --git a/examples/c2c-k8s-deployment/execute_curl.out b/examples/kubernetes-hello-world/execute_curl.out similarity index 100% rename from examples/c2c-k8s-deployment/execute_curl.out rename to examples/kubernetes-hello-world/execute_curl.out diff --git a/examples/c2c-k8s-deployment/kubectl_apply.out b/examples/kubernetes-hello-world/kubectl_apply.out similarity index 100% rename from examples/c2c-k8s-deployment/kubectl_apply.out rename to examples/kubernetes-hello-world/kubectl_apply.out diff --git a/examples/c2c-k8s-deployment/kubectl_expose.out b/examples/kubernetes-hello-world/kubectl_expose.out similarity index 100% rename from examples/c2c-k8s-deployment/kubectl_expose.out rename to examples/kubernetes-hello-world/kubectl_expose.out diff --git a/examples/c2c-k8s-deployment/kubectl_pods.out b/examples/kubernetes-hello-world/kubectl_pods.out similarity index 100% rename from examples/c2c-k8s-deployment/kubectl_pods.out rename to examples/kubernetes-hello-world/kubectl_pods.out diff --git a/examples/c2c-k8s-deployment/kubectl_svc.out b/examples/kubernetes-hello-world/kubectl_svc.out similarity index 100% rename from examples/c2c-k8s-deployment/kubectl_svc.out rename to examples/kubernetes-hello-world/kubectl_svc.out diff --git a/examples/c2c-k8s-deployment/c2c_k8s_deployment.bal b/examples/kubernetes-hello-world/kubernetes-hello-world.bal similarity index 100% rename from examples/c2c-k8s-deployment/c2c_k8s_deployment.bal rename to examples/kubernetes-hello-world/kubernetes-hello-world.bal diff --git a/examples/c2c-k8s-deployment/c2c_k8s_deployment.md b/examples/kubernetes-hello-world/kubernetes-hello-world.md similarity index 91% rename from examples/c2c-k8s-deployment/c2c_k8s_deployment.md rename to examples/kubernetes-hello-world/kubernetes-hello-world.md index e897513ead..b00fbda61c 100644 --- a/examples/c2c-k8s-deployment/c2c_k8s_deployment.md +++ b/examples/kubernetes-hello-world/kubernetes-hello-world.md @@ -1,9 +1,9 @@ # Kubernetes Ballerina supports generating Kubernetes artifacts from code without any additional configuration. This simplifies the experience of developing and deploying Ballerina code in the cloud. Code to Cloud builds the containers and required artifacts by deriving the required values from the code. If you want to override the default values taken by the compiler, you can use a `Cloud.toml` file. -For more information, see [Code to Cloud Deployment](/learn/run-in-the-cloud/code-to-cloud/code-to-cloud-deployment/). +For more information, see [Code to Cloud deployment](/learn/run-in-the-cloud/code-to-cloud-deployment/). -::: code c2c_k8s_deployment.bal ::: +::: kubernetes-hello-world.bal ::: Before you build the package, you need to override some default values taken by the compiler. To do this, create a filed named `Cloud.toml` in the package directory, and add the content below to it. For all the supported key value properties, see [Code to Cloud Specification](https://github.com/ballerina-platform/ballerina-spec/blob/master/c2c/code-to-cloud-spec.md). diff --git a/examples/c2c-k8s-deployment/minikube_ip.out b/examples/kubernetes-hello-world/minikube_ip.out similarity index 100% rename from examples/c2c-k8s-deployment/minikube_ip.out rename to examples/kubernetes-hello-world/minikube_ip.out From a7a1035b1ff6829b828dbe7b5ae7924367e88a3d Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Wed, 3 May 2023 13:40:22 +0530 Subject: [PATCH 02/38] Add AWS Lambda echo and context BBEs --- .../aws-lambda-context-execution.bal | 14 ++++++++++ .../aws-lambda-context-execution.md} | 2 +- .../aws_deploy.out | 0 .../bal_build.out | 2 +- .../bal_new.out | 0 .../invoke_functions.out | 8 ------ .../aws_lambda_deployment.bal | 27 ------------------- .../aws-lambda-hello-world.bal | 9 +++++++ .../aws-lambda-hello-world.md | 22 +++++++++++++++ .../aws-lambda-hello-world/aws_deploy.out | 1 + examples/aws-lambda-hello-world/bal_build.out | 12 +++++++++ examples/aws-lambda-hello-world/bal_new.out | 1 + .../invoke_functions.out | 8 ++++++ 13 files changed, 69 insertions(+), 37 deletions(-) create mode 100644 examples/aws-lambda-context-execution/aws-lambda-context-execution.bal rename examples/{aws-lambda-deployment/aws_lambda_deployment.md => aws-lambda-context-execution/aws-lambda-context-execution.md} (96%) rename examples/{aws-lambda-deployment => aws-lambda-context-execution}/aws_deploy.out (100%) rename examples/{aws-lambda-deployment => aws-lambda-context-execution}/bal_build.out (93%) rename examples/{aws-lambda-deployment => aws-lambda-context-execution}/bal_new.out (100%) rename examples/{aws-lambda-deployment => aws-lambda-context-execution}/invoke_functions.out (71%) delete mode 100644 examples/aws-lambda-deployment/aws_lambda_deployment.bal create mode 100644 examples/aws-lambda-hello-world/aws-lambda-hello-world.bal create mode 100644 examples/aws-lambda-hello-world/aws-lambda-hello-world.md create mode 100644 examples/aws-lambda-hello-world/aws_deploy.out create mode 100644 examples/aws-lambda-hello-world/bal_build.out create mode 100644 examples/aws-lambda-hello-world/bal_new.out create mode 100644 examples/aws-lambda-hello-world/invoke_functions.out diff --git a/examples/aws-lambda-context-execution/aws-lambda-context-execution.bal b/examples/aws-lambda-context-execution/aws-lambda-context-execution.bal new file mode 100644 index 0000000000..6d0961bdea --- /dev/null +++ b/examples/aws-lambda-context-execution/aws-lambda-context-execution.bal @@ -0,0 +1,14 @@ +import ballerinax/awslambda; +import ballerina/io; + +// The `awslambda:Context` object contains request execution context information. +@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() + }; +} diff --git a/examples/aws-lambda-deployment/aws_lambda_deployment.md b/examples/aws-lambda-context-execution/aws-lambda-context-execution.md similarity index 96% rename from examples/aws-lambda-deployment/aws_lambda_deployment.md rename to examples/aws-lambda-context-execution/aws-lambda-context-execution.md index 5f2e2311fd..3e3370fde0 100644 --- a/examples/aws-lambda-deployment/aws_lambda_deployment.md +++ b/examples/aws-lambda-context-execution/aws-lambda-context-execution.md @@ -4,7 +4,7 @@ AWS Lambda is an event driven, serverless computing platform. Ballerina function For more information, see the [AWS Lambda Deployment Guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). -::: code aws_lambda_deployment.bal ::: +::: code aws-lambda-context-execution.bal ::: Create a ballerina package and replace the content of the generated ballerina file with the content above. ::: out bal_new.out ::: diff --git a/examples/aws-lambda-deployment/aws_deploy.out b/examples/aws-lambda-context-execution/aws_deploy.out similarity index 100% rename from examples/aws-lambda-deployment/aws_deploy.out rename to examples/aws-lambda-context-execution/aws_deploy.out diff --git a/examples/aws-lambda-deployment/bal_build.out b/examples/aws-lambda-context-execution/bal_build.out similarity index 93% rename from examples/aws-lambda-deployment/bal_build.out rename to examples/aws-lambda-context-execution/bal_build.out index 28d6ec11dc..509bb8ebda 100644 --- a/examples/aws-lambda-deployment/bal_build.out +++ b/examples/aws-lambda-context-execution/bal_build.out @@ -3,7 +3,7 @@ Compiling source wso2/aws_lambda_deployment:0.1.0 Generating executable - @awslambda:Function: echo, ctxinfo, notifyS3 + @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:///aws_lambda_deployment/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 diff --git a/examples/aws-lambda-deployment/bal_new.out b/examples/aws-lambda-context-execution/bal_new.out similarity index 100% rename from examples/aws-lambda-deployment/bal_new.out rename to examples/aws-lambda-context-execution/bal_new.out diff --git a/examples/aws-lambda-deployment/invoke_functions.out b/examples/aws-lambda-context-execution/invoke_functions.out similarity index 71% rename from examples/aws-lambda-deployment/invoke_functions.out rename to examples/aws-lambda-context-execution/invoke_functions.out index d182a6dafb..0361f200e5 100644 --- a/examples/aws-lambda-deployment/invoke_functions.out +++ b/examples/aws-lambda-context-execution/invoke_functions.out @@ -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", diff --git a/examples/aws-lambda-deployment/aws_lambda_deployment.bal b/examples/aws-lambda-deployment/aws_lambda_deployment.bal deleted file mode 100644 index 54109b090e..0000000000 --- a/examples/aws-lambda-deployment/aws_lambda_deployment.bal +++ /dev/null @@ -1,27 +0,0 @@ -import ballerinax/awslambda; -import ballerina/io; - -// 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 { - return input; -} - -// The `awslambda:Context` object contains request execution context information. -@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() - }; -} - -// If you know the external service that's being used for the function, you can use the built-in types such as -// `S3Event`, `DynamoDBEvent`, `SESEvent` etc. for data binding. -@awslambda:Function -public function notifyS3(awslambda:Context ctx, awslambda:S3Event event) { - io:println(event.Records[0].s3.'object.key); -} diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.bal b/examples/aws-lambda-hello-world/aws-lambda-hello-world.bal new file mode 100644 index 0000000000..687e73a20c --- /dev/null +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.bal @@ -0,0 +1,9 @@ +import ballerina/log; +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 { + log:printInfo(input.toJsonString()); + return input; +} diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md new file mode 100644 index 0000000000..2aeccef4d7 --- /dev/null +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md @@ -0,0 +1,22 @@ +# AWS Lambda + +AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. + +For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). + +::: code aws-lambda-hello-world.bal ::: + +Create a Ballerina package and replace the content of the generated Ballerina file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the AWS Lambda artifacts. +::: out bal_build.out ::: + +Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. + +For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). + +::: out aws_deploy.out ::: + +Invoke the functions. +::: out invoke_functions.out ::: diff --git a/examples/aws-lambda-hello-world/aws_deploy.out b/examples/aws-lambda-hello-world/aws_deploy.out new file mode 100644 index 0000000000..784f118011 --- /dev/null +++ b/examples/aws-lambda-hello-world/aws_deploy.out @@ -0,0 +1 @@ +$ aws lambda create-function --function-name echo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws_lambda_deployment.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 diff --git a/examples/aws-lambda-hello-world/bal_build.out b/examples/aws-lambda-hello-world/bal_build.out new file mode 100644 index 0000000000..5c2e08cd46 --- /dev/null +++ b/examples/aws-lambda-hello-world/bal_build.out @@ -0,0 +1,12 @@ +$ bal build +Compiling source + wso2/aws_lambda_deployment: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:///aws_lambda_deployment/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 diff --git a/examples/aws-lambda-hello-world/bal_new.out b/examples/aws-lambda-hello-world/bal_new.out new file mode 100644 index 0000000000..ac3b9157cc --- /dev/null +++ b/examples/aws-lambda-hello-world/bal_new.out @@ -0,0 +1 @@ +$ bal new aws_lambda_deployment diff --git a/examples/aws-lambda-hello-world/invoke_functions.out b/examples/aws-lambda-hello-world/invoke_functions.out new file mode 100644 index 0000000000..59881e570c --- /dev/null +++ b/examples/aws-lambda-hello-world/invoke_functions.out @@ -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"} \ No newline at end of file From faebcf93135635309c9a95677ccd0d050c155a2a Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Wed, 3 May 2023 13:58:18 +0530 Subject: [PATCH 03/38] Update AWS echo and context BBEs --- .../aws-lambda-context-execution.md | 40 +++++++++++++------ .../aws_deploy.out | 2 - .../bal_build.out | 4 +- .../aws-lambda-context-execution/bal_new.out | 2 +- .../aws-lambda-hello-world.md | 31 ++++++++++---- .../aws-lambda-hello-world/aws_deploy.out | 2 +- examples/aws-lambda-hello-world/bal_build.out | 4 +- examples/aws-lambda-hello-world/bal_new.out | 2 +- 8 files changed, 59 insertions(+), 28 deletions(-) diff --git a/examples/aws-lambda-context-execution/aws-lambda-context-execution.md b/examples/aws-lambda-context-execution/aws-lambda-context-execution.md index 3e3370fde0..c295d8907f 100644 --- a/examples/aws-lambda-context-execution/aws-lambda-context-execution.md +++ b/examples/aws-lambda-context-execution/aws-lambda-context-execution.md @@ -1,23 +1,39 @@ -# AWS Lambda +# Context execution -AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with "@awslambda:Function", which should have the function signature `function (awslambda:Context, json|EventType) returns json|error`. +The example below demonstrates how context information of an AWS function are executed. -For more information, see the [AWS Lambda Deployment Guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +## Set up the prerequisites -::: code aws-lambda-context-execution.bal ::: +For instructions, see [Set up the prerequisites](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-the-prerequisites). + +## Create a Ballerina package + +Execute the command below to create a new Ballerina package. -Create a ballerina package and replace the content of the generated ballerina file with the content above. ::: out bal_new.out ::: -Build the Ballerina program to generate the AWS Lambda artifacts +## Replace the code + +Replace the content of the generated Ballerina file with the content below. + +::: code aws-lambda-hello-world.bal ::: + +## Build the Ballerina program + +Execute the command below to generate the AWS Lambda artifacts. + ::: out bal_build.out ::: -Execute the AWS CLI commands to create and publish the functions; and set your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. -For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +## Deploy the function + +Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. + + >**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). + ::: out aws_deploy.out ::: -Invoke the functions. -::: out invoke_functions.out ::: +## Invoke the function + +Execute the commands below to invoke the function. -To invoke the `notifyS3` function, it needs to be registered in the S3 bucket. -For registration and execution details, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +::: out invoke_functions.out ::: diff --git a/examples/aws-lambda-context-execution/aws_deploy.out b/examples/aws-lambda-context-execution/aws_deploy.out index 9903c8e992..6fcf98ccce 100644 --- a/examples/aws-lambda-context-execution/aws_deploy.out +++ b/examples/aws-lambda-context-execution/aws_deploy.out @@ -1,3 +1 @@ -$ aws lambda create-function --function-name echo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws_lambda_deployment.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 -$ aws lambda create-function --function-name uuid --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws_lambda_deployment.uuid --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 $ aws lambda create-function --function-name ctxinfo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws_lambda_deployment.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 diff --git a/examples/aws-lambda-context-execution/bal_build.out b/examples/aws-lambda-context-execution/bal_build.out index 509bb8ebda..4d565fab2b 100644 --- a/examples/aws-lambda-context-execution/bal_build.out +++ b/examples/aws-lambda-context-execution/bal_build.out @@ -1,12 +1,12 @@ $ bal build Compiling source - wso2/aws_lambda_deployment:0.1.0 + wso2/aws-lambda-context-execution: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:///aws_lambda_deployment/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 + aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///aws-lambda-context-execution/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 diff --git a/examples/aws-lambda-context-execution/bal_new.out b/examples/aws-lambda-context-execution/bal_new.out index ac3b9157cc..9ae5de1568 100644 --- a/examples/aws-lambda-context-execution/bal_new.out +++ b/examples/aws-lambda-context-execution/bal_new.out @@ -1 +1 @@ -$ bal new aws_lambda_deployment +$ bal new aws-lambda-context-execution diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md index 2aeccef4d7..defd01b366 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md @@ -1,22 +1,39 @@ # AWS Lambda -AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. +AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). -For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +## Set up the prerequisites -::: code aws-lambda-hello-world.bal ::: +For instructions, see [Set up the prerequisites](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-the-prerequisites). + +## Create a Ballerina package + +Execute the command below to create a new Ballerina package. -Create a Ballerina package and replace the content of the generated Ballerina file with the content above. ::: out bal_new.out ::: -Build the Ballerina program to generate the AWS Lambda artifacts. +## Replace the code + +Replace the content of the generated Ballerina file with the content below. + +::: code aws-lambda-hello-world.bal ::: + +## Build the Ballerina program + +Execute the command below to generate the AWS Lambda artifacts. + ::: out bal_build.out ::: +## Deploy the function + Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. -For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). + >**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). ::: out aws_deploy.out ::: -Invoke the functions. +## Invoke the function + +Execute the commands below to invoke the function. + ::: out invoke_functions.out ::: diff --git a/examples/aws-lambda-hello-world/aws_deploy.out b/examples/aws-lambda-hello-world/aws_deploy.out index 784f118011..1ea510bb00 100644 --- a/examples/aws-lambda-hello-world/aws_deploy.out +++ b/examples/aws-lambda-hello-world/aws_deploy.out @@ -1 +1 @@ -$ aws lambda create-function --function-name echo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws_lambda_deployment.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 +$ 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 diff --git a/examples/aws-lambda-hello-world/bal_build.out b/examples/aws-lambda-hello-world/bal_build.out index 5c2e08cd46..7a176907a4 100644 --- a/examples/aws-lambda-hello-world/bal_build.out +++ b/examples/aws-lambda-hello-world/bal_build.out @@ -1,12 +1,12 @@ $ bal build Compiling source - wso2/aws_lambda_deployment:0.1.0 + 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:///aws_lambda_deployment/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 + aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///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 diff --git a/examples/aws-lambda-hello-world/bal_new.out b/examples/aws-lambda-hello-world/bal_new.out index ac3b9157cc..3fd4ff56d0 100644 --- a/examples/aws-lambda-hello-world/bal_new.out +++ b/examples/aws-lambda-hello-world/bal_new.out @@ -1 +1 @@ -$ bal new aws_lambda_deployment +$ bal new aws-lambda-hello-world From 039914431c1625c73246baac20288a30787e9068 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Wed, 3 May 2023 14:21:35 +0530 Subject: [PATCH 04/38] Add S3 and DynamoDB BBEs --- .../aws_deploy.out | 2 +- .../aws-lambda-dynamodb-trigger.bal | 11 +++++ .../aws-lambda-dynamodb-trigger.md | 47 +++++++++++++++++++ .../aws_deploy.out | 1 + .../aws-lambda-dynamodb-trigger/bal_build.out | 12 +++++ .../aws-lambda-dynamodb-trigger/bal_new.out | 1 + .../invoke_functions.out | 8 ++++ .../aws-lambda-s3-trigger.bal | 11 +++++ .../aws-lambda-s3-trigger.md | 44 +++++++++++++++++ examples/aws-lambda-s3-trigger/aws_deploy.out | 1 + examples/aws-lambda-s3-trigger/bal_build.out | 12 +++++ examples/aws-lambda-s3-trigger/bal_new.out | 1 + .../invoke_functions.out | 8 ++++ 13 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.bal create mode 100644 examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md create mode 100644 examples/aws-lambda-dynamodb-trigger/aws_deploy.out create mode 100644 examples/aws-lambda-dynamodb-trigger/bal_build.out create mode 100644 examples/aws-lambda-dynamodb-trigger/bal_new.out create mode 100644 examples/aws-lambda-dynamodb-trigger/invoke_functions.out create mode 100644 examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal create mode 100644 examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md create mode 100644 examples/aws-lambda-s3-trigger/aws_deploy.out create mode 100644 examples/aws-lambda-s3-trigger/bal_build.out create mode 100644 examples/aws-lambda-s3-trigger/bal_new.out create mode 100644 examples/aws-lambda-s3-trigger/invoke_functions.out diff --git a/examples/aws-lambda-context-execution/aws_deploy.out b/examples/aws-lambda-context-execution/aws_deploy.out index 6fcf98ccce..a3af4931e7 100644 --- a/examples/aws-lambda-context-execution/aws_deploy.out +++ b/examples/aws-lambda-context-execution/aws_deploy.out @@ -1 +1 @@ -$ aws lambda create-function --function-name ctxinfo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws_lambda_deployment.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 +$ aws lambda create-function --function-name ctxinfo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-context-execution.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 diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.bal b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.bal new file mode 100644 index 0000000000..e0884ff2d1 --- /dev/null +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.bal @@ -0,0 +1,11 @@ +import ballerina/io; +import ballerinax/awslambda; + +// The `@awslambda:Function` annotation marks a function to generate an AWS Lambda function. + +@awslambda:Function +public function notifyDynamoDB(awslambda:Context ctx, + awslambda:DynamoDBEvent event) returns json { + io:println(event.Records[0].dynamodb.Keys.toString()); + return event.Records[0].dynamodb.Keys.toString(); +} diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md new file mode 100644 index 0000000000..e0b2f247f0 --- /dev/null +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -0,0 +1,47 @@ +# AWS Lambda + +AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). + +## Set up the prerequisites + +For instructions, see [Set up the prerequisites](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-the-prerequisites). + +## Create a Ballerina package + +Execute the command below to create a new Ballerina package. + +::: out bal_new.out ::: + +## Replace the code + +Replace the content of the generated Ballerina file with the content below. + +::: code aws-lambda-hello-world.bal ::: + +## Build the Ballerina program + +Execute the command below to generate the AWS Lambda artifacts. + +::: out bal_build.out ::: + +## Deploy the function + +Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. + + >**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). + +::: out aws_deploy.out ::: + +## Invoke the function + +To invoke this function, create a DynamoDB table. +1. Go to **roles**, and add `AWSLambdaDynamoDBExecutionRole` to the created role in the prerequisites. +2. Go to the DynamoDB. +3. Click **Create Table**, enter the table name, partition key, and create the table (If you already have a table created, you can skip this step). +4. Click on the DynamoDB table, 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's enabled, click **Create a trigger**, select the `notifyDynamoDB` from the dropdown, and create a trigger. + +Now, add an entry to the DynamoDB table to invoke the Lambda function. For this, go to **Items** in the DynamoDB, select the table, and click **Create item**. Once the item is entered into the table, go to the Lambda function, and check the logs via CloudWatch to see the object identifier in the logs. + +::: out invoke_functions.out ::: diff --git a/examples/aws-lambda-dynamodb-trigger/aws_deploy.out b/examples/aws-lambda-dynamodb-trigger/aws_deploy.out new file mode 100644 index 0000000000..bd34f36f07 --- /dev/null +++ b/examples/aws-lambda-dynamodb-trigger/aws_deploy.out @@ -0,0 +1 @@ +$ aws lambda create-function --function-name notifysDynamoDB --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-dynamodb-trigger.notifyDynamoDB --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 diff --git a/examples/aws-lambda-dynamodb-trigger/bal_build.out b/examples/aws-lambda-dynamodb-trigger/bal_build.out new file mode 100644 index 0000000000..594e1f9411 --- /dev/null +++ b/examples/aws-lambda-dynamodb-trigger/bal_build.out @@ -0,0 +1,12 @@ +$ bal build +Compiling source + wso2/aws-lambda-dynamodb-trigger:0.1.0 + +Generating executable + @awslambda:Function: notifyDynamoDB + + Run the following command to deploy each Ballerina AWS Lambda function: + aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///aws-lambda-s3-trigger/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 diff --git a/examples/aws-lambda-dynamodb-trigger/bal_new.out b/examples/aws-lambda-dynamodb-trigger/bal_new.out new file mode 100644 index 0000000000..6061dbdef8 --- /dev/null +++ b/examples/aws-lambda-dynamodb-trigger/bal_new.out @@ -0,0 +1 @@ +$ bal new aws-lambda-dynamodb-trigger diff --git a/examples/aws-lambda-dynamodb-trigger/invoke_functions.out b/examples/aws-lambda-dynamodb-trigger/invoke_functions.out new file mode 100644 index 0000000000..6dcc89b4e1 --- /dev/null +++ b/examples/aws-lambda-dynamodb-trigger/invoke_functions.out @@ -0,0 +1,8 @@ +$ echo '{"MESSAGE":"HELLO"}' > input.json +$ aws lambda invoke --function-name notifysDynamoDB --payload fileb://input.json echo-response.txt +{ +"ExecutedVersion": "$LATEST", +"StatusCode": 200 +} +$ cat echo-response.txt +{"MESSAGE":"HELLO"} \ No newline at end of file diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal new file mode 100644 index 0000000000..69d6e2e6b2 --- /dev/null +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal @@ -0,0 +1,11 @@ +import ballerina/io; +import ballerinax/awslambda; + +// The `@awslambda:Function` annotation marks a function to generate an AWS Lambda function. + +@awslambda:Function +public function notifyS3(awslambda:Context ctx, + awslambda:S3Event event) returns json { + io:println(event.Records[0].s3.'object.key); + return event.Records[0].s3.'object.key; +} \ No newline at end of file diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md new file mode 100644 index 0000000000..e6e4d6b428 --- /dev/null +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -0,0 +1,44 @@ +# AWS Lambda + +AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). + +## Set up the prerequisites + +For instructions, see [Set up the prerequisites](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-the-prerequisites). + +## Create a Ballerina package + +Execute the command below to create a new Ballerina package. + +::: out bal_new.out ::: + +## Replace the code + +Replace the content of the generated Ballerina file with the content below. + +::: code aws-lambda-hello-world.bal ::: + +## Build the Ballerina program + +Execute the command below to generate the AWS Lambda artifacts. + +::: out bal_build.out ::: + +## Deploy the function + +Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. + + >**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). + +::: out aws_deploy.out ::: + +## Invoke the function + +To invoke this function, create an S3 bucket in AWS. +1. Go to AWS S3 portal and create a bucket. +2. Click on the created bucket, go to the **Properties** tab, and click on the **Create event notification** under the **Event notifications** section. +3. Enable `All object create events` under event types. Select the Lambda function as the destination, and choose the `notifyS3` Lambda function from the dropdown. + +Now, click **Upload** to upload an object to the S3 bucket, and view the Lambda logs via CloudWatch to see the object name. + +::: out invoke_functions.out ::: diff --git a/examples/aws-lambda-s3-trigger/aws_deploy.out b/examples/aws-lambda-s3-trigger/aws_deploy.out new file mode 100644 index 0000000000..ced418627b --- /dev/null +++ b/examples/aws-lambda-s3-trigger/aws_deploy.out @@ -0,0 +1 @@ +$ aws lambda create-function --function-name notifys3 --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-s3-trigger.notifys3 --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 diff --git a/examples/aws-lambda-s3-trigger/bal_build.out b/examples/aws-lambda-s3-trigger/bal_build.out new file mode 100644 index 0000000000..889f0d7145 --- /dev/null +++ b/examples/aws-lambda-s3-trigger/bal_build.out @@ -0,0 +1,12 @@ +$ bal build +Compiling source + wso2/aws-lambda-s3-trigger:0.1.0 + +Generating executable + @awslambda:Function: notifys3 + + Run the following command to deploy each Ballerina AWS Lambda function: + aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///aws-lambda-s3-trigger/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 diff --git a/examples/aws-lambda-s3-trigger/bal_new.out b/examples/aws-lambda-s3-trigger/bal_new.out new file mode 100644 index 0000000000..cd23cd38c3 --- /dev/null +++ b/examples/aws-lambda-s3-trigger/bal_new.out @@ -0,0 +1 @@ +$ bal new aws-lambda-s3-trigger diff --git a/examples/aws-lambda-s3-trigger/invoke_functions.out b/examples/aws-lambda-s3-trigger/invoke_functions.out new file mode 100644 index 0000000000..3d368a8df7 --- /dev/null +++ b/examples/aws-lambda-s3-trigger/invoke_functions.out @@ -0,0 +1,8 @@ +$ echo '{"MESSAGE":"HELLO"}' > input.json +$ aws lambda invoke --function-name notifys3 --payload fileb://input.json echo-response.txt +{ +"ExecutedVersion": "$LATEST", +"StatusCode": 200 +} +$ cat echo-response.txt +{"MESSAGE":"HELLO"} \ No newline at end of file From a7b33a1130aae4cba8f841ab8ba80a5b1c450a40 Mon Sep 17 00:00:00 2001 From: praneesha Date: Wed, 3 May 2023 14:38:59 +0530 Subject: [PATCH 05/38] Update examples/kubernetes-hello-world/kubernetes-hello-world.md Co-authored-by: Anjana Supun --- examples/kubernetes-hello-world/kubernetes-hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/kubernetes-hello-world/kubernetes-hello-world.md b/examples/kubernetes-hello-world/kubernetes-hello-world.md index b00fbda61c..a42395397b 100644 --- a/examples/kubernetes-hello-world/kubernetes-hello-world.md +++ b/examples/kubernetes-hello-world/kubernetes-hello-world.md @@ -3,7 +3,7 @@ Ballerina supports generating Kubernetes artifacts from code without any additional configuration. This simplifies the experience of developing and deploying Ballerina code in the cloud. Code to Cloud builds the containers and required artifacts by deriving the required values from the code. If you want to override the default values taken by the compiler, you can use a `Cloud.toml` file. For more information, see [Code to Cloud deployment](/learn/run-in-the-cloud/code-to-cloud-deployment/). -::: kubernetes-hello-world.bal ::: +::: code kubernetes-hello-world.bal ::: Before you build the package, you need to override some default values taken by the compiler. To do this, create a filed named `Cloud.toml` in the package directory, and add the content below to it. For all the supported key value properties, see [Code to Cloud Specification](https://github.com/ballerina-platform/ballerina-spec/blob/master/c2c/code-to-cloud-spec.md). From 35f1cd929331771f6b49d6d03d455b9fb6b1e4a8 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Thu, 4 May 2023 15:22:30 +0530 Subject: [PATCH 06/38] Fix build error --- .../aws-lambda-context-execution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-context-execution/aws-lambda-context-execution.md b/examples/aws-lambda-context-execution/aws-lambda-context-execution.md index c295d8907f..ac848983d4 100644 --- a/examples/aws-lambda-context-execution/aws-lambda-context-execution.md +++ b/examples/aws-lambda-context-execution/aws-lambda-context-execution.md @@ -16,7 +16,7 @@ Execute the command below to create a new Ballerina package. Replace the content of the generated Ballerina file with the content below. -::: code aws-lambda-hello-world.bal ::: +::: code aws-lambda-context-execution.bal ::: ## Build the Ballerina program From cbc26ca58e3adb1b86e1be771a4a1f98754e3c59 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Thu, 4 May 2023 16:03:20 +0530 Subject: [PATCH 07/38] Fix more BBE gen errors --- .../aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md | 2 +- examples/aws-lambda-dynamodb-trigger/bal_build.out | 2 +- examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md | 2 +- examples/aws-lambda-s3-trigger/bal_build.out | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index e0b2f247f0..fc444658d2 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -16,7 +16,7 @@ Execute the command below to create a new Ballerina package. Replace the content of the generated Ballerina file with the content below. -::: code aws-lambda-hello-world.bal ::: +::: code aws-lambda-dynamodb-trigger.bal ::: ## Build the Ballerina program diff --git a/examples/aws-lambda-dynamodb-trigger/bal_build.out b/examples/aws-lambda-dynamodb-trigger/bal_build.out index 594e1f9411..1041130382 100644 --- a/examples/aws-lambda-dynamodb-trigger/bal_build.out +++ b/examples/aws-lambda-dynamodb-trigger/bal_build.out @@ -6,7 +6,7 @@ Generating executable @awslambda:Function: notifyDynamoDB Run the following command to deploy each Ballerina AWS Lambda function: - aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///aws-lambda-s3-trigger/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 + aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///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 diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index e6e4d6b428..f5dd2d3cfd 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -16,7 +16,7 @@ Execute the command below to create a new Ballerina package. Replace the content of the generated Ballerina file with the content below. -::: code aws-lambda-hello-world.bal ::: +::: code aws-lambda-s3-trigger.bal ::: ## Build the Ballerina program diff --git a/examples/aws-lambda-s3-trigger/bal_build.out b/examples/aws-lambda-s3-trigger/bal_build.out index 889f0d7145..6a4dd1486e 100644 --- a/examples/aws-lambda-s3-trigger/bal_build.out +++ b/examples/aws-lambda-s3-trigger/bal_build.out @@ -6,7 +6,7 @@ Generating executable @awslambda:Function: notifys3 Run the following command to deploy each Ballerina AWS Lambda function: - aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///aws-lambda-s3-trigger/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 + aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///aws-lambda-s3-trigger/target/bin/aws-ballerina-lambda-functions.zip --handler aws-lambda-s3-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 From c3e04bd7d010461337f4d44dd8f0b95e637a783d Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Thu, 4 May 2023 17:27:29 +0530 Subject: [PATCH 08/38] Fix gen errors in Azure BBE --- examples/azure-functions-deployment/bal_new.out | 1 - .../az_deploy.out | 0 .../azure-functions-hello-world.bal} | 0 .../azure-functions-hello-world.md} | 2 +- .../bal_build.out | 2 +- examples/azure-functions-hello-world/bal_new.out | 1 + .../execute_function.out | 0 7 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 examples/azure-functions-deployment/bal_new.out rename examples/{azure-functions-deployment => azure-functions-hello-world}/az_deploy.out (100%) rename examples/{azure-functions-deployment/azure_functions_deployment.bal => azure-functions-hello-world/azure-functions-hello-world.bal} (100%) rename examples/{azure-functions-deployment/azure_functions_deployment.md => azure-functions-hello-world/azure-functions-hello-world.md} (96%) rename examples/{azure-functions-deployment => azure-functions-hello-world}/bal_build.out (91%) create mode 100644 examples/azure-functions-hello-world/bal_new.out rename examples/{azure-functions-deployment => azure-functions-hello-world}/execute_function.out (100%) diff --git a/examples/azure-functions-deployment/bal_new.out b/examples/azure-functions-deployment/bal_new.out deleted file mode 100644 index 9f1771644c..0000000000 --- a/examples/azure-functions-deployment/bal_new.out +++ /dev/null @@ -1 +0,0 @@ -$ bal new azure_functions_deployment diff --git a/examples/azure-functions-deployment/az_deploy.out b/examples/azure-functions-hello-world/az_deploy.out similarity index 100% rename from examples/azure-functions-deployment/az_deploy.out rename to examples/azure-functions-hello-world/az_deploy.out diff --git a/examples/azure-functions-deployment/azure_functions_deployment.bal b/examples/azure-functions-hello-world/azure-functions-hello-world.bal similarity index 100% rename from examples/azure-functions-deployment/azure_functions_deployment.bal rename to examples/azure-functions-hello-world/azure-functions-hello-world.bal diff --git a/examples/azure-functions-deployment/azure_functions_deployment.md b/examples/azure-functions-hello-world/azure-functions-hello-world.md similarity index 96% rename from examples/azure-functions-deployment/azure_functions_deployment.md rename to examples/azure-functions-hello-world/azure-functions-hello-world.md index ecf26ab6b4..7a3e51bc22 100644 --- a/examples/azure-functions-deployment/azure_functions_deployment.md +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.md @@ -4,7 +4,7 @@ Azure Functions is an event driven, serverless computing platform. Azure Functio For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). -::: code azure_functions_deployment.bal ::: +::: code azure_functions_hello-world.bal ::: Create a Ballerina package and replace the content of the generated BAL file with the content above. ::: out bal_new.out ::: diff --git a/examples/azure-functions-deployment/bal_build.out b/examples/azure-functions-hello-world/bal_build.out similarity index 91% rename from examples/azure-functions-deployment/bal_build.out rename to examples/azure-functions-hello-world/bal_build.out index cc1448aa34..67e8673154 100644 --- a/examples/azure-functions-deployment/bal_build.out +++ b/examples/azure-functions-hello-world/bal_build.out @@ -1,6 +1,6 @@ $ bal build --cloud="azure_functions" Compiling source - wso2/azure_functions_deployment:0.1.0 + wso2/azure-functions-hello-world:0.1.0 Generating executable @azure_functions:Function: timer, get-hello diff --git a/examples/azure-functions-hello-world/bal_new.out b/examples/azure-functions-hello-world/bal_new.out new file mode 100644 index 0000000000..27be8e9b36 --- /dev/null +++ b/examples/azure-functions-hello-world/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-hello-world diff --git a/examples/azure-functions-deployment/execute_function.out b/examples/azure-functions-hello-world/execute_function.out similarity index 100% rename from examples/azure-functions-deployment/execute_function.out rename to examples/azure-functions-hello-world/execute_function.out From 41196f6bdd30aed7f3a90591164bd38226159940 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Thu, 4 May 2023 22:20:04 +0530 Subject: [PATCH 09/38] Fix gen error in Azure BBE --- .../azure-functions-hello-world/azure-functions-hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.md b/examples/azure-functions-hello-world/azure-functions-hello-world.md index 7a3e51bc22..505bba7fb0 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.md +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.md @@ -4,7 +4,7 @@ Azure Functions is an event driven, serverless computing platform. Azure Functio For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). -::: code azure_functions_hello-world.bal ::: +::: code azure-functions-hello-world.bal ::: Create a Ballerina package and replace the content of the generated BAL file with the content above. ::: out bal_new.out ::: From fae60286744fb9559c4da5803f9bec8a099931e9 Mon Sep 17 00:00:00 2001 From: praneesha Date: Sun, 7 May 2023 13:31:14 +0530 Subject: [PATCH 10/38] Update aws-lambda-hello-world.md --- examples/aws-lambda-hello-world/aws-lambda-hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md index defd01b366..a45a0ad991 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md @@ -1,4 +1,4 @@ -# AWS Lambda +# AWS Lambda - Hello World AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). From 5bdd94ab6eb99e84ee188e66fc40bba3cd63be15 Mon Sep 17 00:00:00 2001 From: praneesha Date: Sun, 7 May 2023 13:32:20 +0530 Subject: [PATCH 11/38] Update aws-lambda-context-execution.md --- .../aws-lambda-context-execution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-context-execution/aws-lambda-context-execution.md b/examples/aws-lambda-context-execution/aws-lambda-context-execution.md index ac848983d4..3040c3b3a0 100644 --- a/examples/aws-lambda-context-execution/aws-lambda-context-execution.md +++ b/examples/aws-lambda-context-execution/aws-lambda-context-execution.md @@ -1,4 +1,4 @@ -# Context execution +# AWS Lambda execution context The example below demonstrates how context information of an AWS function are executed. From 48e172dbb95396121bbe88c5a9441dce0f5fdc69 Mon Sep 17 00:00:00 2001 From: praneesha Date: Sun, 7 May 2023 13:32:40 +0530 Subject: [PATCH 12/38] Update aws-lambda-s3-trigger.md --- examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index f5dd2d3cfd..4f9f708186 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -1,4 +1,4 @@ -# AWS Lambda +# AWS Lambda S3 trigger AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). From a5510bb1f0c44d775f34af2c534a8ef970fe9ef5 Mon Sep 17 00:00:00 2001 From: praneesha Date: Sun, 7 May 2023 13:32:56 +0530 Subject: [PATCH 13/38] Update aws-lambda-dynamodb-trigger.md --- .../aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index fc444658d2..8dec3b115f 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -1,4 +1,4 @@ -# AWS Lambda +# AWS Lambda DynamoDB trigger AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). From b261a15f12ac245c188c9dbf8ca5b59e46f99f40 Mon Sep 17 00:00:00 2001 From: praneesha Date: Sun, 7 May 2023 13:33:44 +0530 Subject: [PATCH 14/38] Update azure-functions-hello-world.md --- .../azure-functions-hello-world/azure-functions-hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.md b/examples/azure-functions-hello-world/azure-functions-hello-world.md index 505bba7fb0..d41f3a3189 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.md +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.md @@ -1,4 +1,4 @@ -# Azure Functions +# Azure Functions- Hello world Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. From ba55951defd5b69f87ecea2510ed12f155ea354d Mon Sep 17 00:00:00 2001 From: praneesha Date: Sun, 7 May 2023 13:34:02 +0530 Subject: [PATCH 15/38] Update aws-lambda-hello-world.md --- examples/aws-lambda-hello-world/aws-lambda-hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md index a45a0ad991..7e40328bef 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md @@ -1,4 +1,4 @@ -# AWS Lambda - Hello World +# AWS Lambda - Hello world AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). From 9dc03a5aeab94db053e47fe474a8a78671b6241e Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Sun, 7 May 2023 13:38:41 +0530 Subject: [PATCH 16/38] Rename AWS Lambda execution context BBE --- examples/aws-lambda-context-execution/bal_new.out | 1 - .../aws-lambda-execution-context.bal} | 0 .../aws-lambda-execution-context.md} | 2 +- .../aws_deploy.out | 2 +- .../bal_build.out | 4 ++-- examples/aws-lambda-execution-context/bal_new.out | 1 + .../invoke_functions.out | 0 examples/index.json | 4 ++-- 8 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 examples/aws-lambda-context-execution/bal_new.out rename examples/{aws-lambda-context-execution/aws-lambda-context-execution.bal => aws-lambda-execution-context/aws-lambda-execution-context.bal} (100%) rename examples/{aws-lambda-context-execution/aws-lambda-context-execution.md => aws-lambda-execution-context/aws-lambda-execution-context.md} (96%) rename examples/{aws-lambda-context-execution => aws-lambda-execution-context}/aws_deploy.out (80%) rename examples/{aws-lambda-context-execution => aws-lambda-execution-context}/bal_build.out (86%) create mode 100644 examples/aws-lambda-execution-context/bal_new.out rename examples/{aws-lambda-context-execution => aws-lambda-execution-context}/invoke_functions.out (100%) diff --git a/examples/aws-lambda-context-execution/bal_new.out b/examples/aws-lambda-context-execution/bal_new.out deleted file mode 100644 index 9ae5de1568..0000000000 --- a/examples/aws-lambda-context-execution/bal_new.out +++ /dev/null @@ -1 +0,0 @@ -$ bal new aws-lambda-context-execution diff --git a/examples/aws-lambda-context-execution/aws-lambda-context-execution.bal b/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal similarity index 100% rename from examples/aws-lambda-context-execution/aws-lambda-context-execution.bal rename to examples/aws-lambda-execution-context/aws-lambda-execution-context.bal diff --git a/examples/aws-lambda-context-execution/aws-lambda-context-execution.md b/examples/aws-lambda-execution-context/aws-lambda-execution-context.md similarity index 96% rename from examples/aws-lambda-context-execution/aws-lambda-context-execution.md rename to examples/aws-lambda-execution-context/aws-lambda-execution-context.md index 3040c3b3a0..c95a83f63c 100644 --- a/examples/aws-lambda-context-execution/aws-lambda-context-execution.md +++ b/examples/aws-lambda-execution-context/aws-lambda-execution-context.md @@ -16,7 +16,7 @@ Execute the command below to create a new Ballerina package. Replace the content of the generated Ballerina file with the content below. -::: code aws-lambda-context-execution.bal ::: +::: code aws-lambda-execution-context.bal ::: ## Build the Ballerina program diff --git a/examples/aws-lambda-context-execution/aws_deploy.out b/examples/aws-lambda-execution-context/aws_deploy.out similarity index 80% rename from examples/aws-lambda-context-execution/aws_deploy.out rename to examples/aws-lambda-execution-context/aws_deploy.out index a3af4931e7..b92d5109ed 100644 --- a/examples/aws-lambda-context-execution/aws_deploy.out +++ b/examples/aws-lambda-execution-context/aws_deploy.out @@ -1 +1 @@ -$ aws lambda create-function --function-name ctxinfo --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-context-execution.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 +$ 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 diff --git a/examples/aws-lambda-context-execution/bal_build.out b/examples/aws-lambda-execution-context/bal_build.out similarity index 86% rename from examples/aws-lambda-context-execution/bal_build.out rename to examples/aws-lambda-execution-context/bal_build.out index 4d565fab2b..c007fa3a34 100644 --- a/examples/aws-lambda-context-execution/bal_build.out +++ b/examples/aws-lambda-execution-context/bal_build.out @@ -1,12 +1,12 @@ $ bal build Compiling source - wso2/aws-lambda-context-execution:0.1.0 + 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:///aws-lambda-context-execution/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 + aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///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 diff --git a/examples/aws-lambda-execution-context/bal_new.out b/examples/aws-lambda-execution-context/bal_new.out new file mode 100644 index 0000000000..fdb884a78a --- /dev/null +++ b/examples/aws-lambda-execution-context/bal_new.out @@ -0,0 +1 @@ +$ bal new aws-lambda-execution-context diff --git a/examples/aws-lambda-context-execution/invoke_functions.out b/examples/aws-lambda-execution-context/invoke_functions.out similarity index 100% rename from examples/aws-lambda-context-execution/invoke_functions.out rename to examples/aws-lambda-execution-context/invoke_functions.out diff --git a/examples/index.json b/examples/index.json index e76ca01424..e0a18e8717 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4359,8 +4359,8 @@ "isLearnByExample": false }, { - "name": "Context execution", - "url": "aws-lambda-context-execution", + "name": "Execution context", + "url": "aws-lambda-execution-context", "verifyBuild": false, "verifyOutput": false, "disableVerificationReason": "Needs prerequisite condition", From 8518df99f4e9c3dde1194a6d27dce4e49f78d226 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Sun, 7 May 2023 17:05:31 +0530 Subject: [PATCH 17/38] Add the Azure Functions BBEs --- .../az_deploy.out | 12 +++++++ .../azure-functions-hello-world.bal | 19 ++++++++++ .../azure-functions-hello-world.md | 21 +++++++++++ .../bal_build.out | 14 ++++++++ .../bal_new.out | 1 + .../execute_function.out | 2 ++ .../az_deploy.out | 12 +++++++ .../azure-functions-hello-world.bal | 19 ++++++++++ .../azure-functions-hello-world.md | 21 +++++++++++ .../bal_build.out | 14 ++++++++ .../azure-functions-http-trigger/bal_new.out | 1 + .../execute_function.out | 2 ++ examples/azure-functions-native/az_deploy.out | 12 +++++++ .../azure-functions-hello-world.bal | 19 ++++++++++ .../azure-functions-hello-world.md | 21 +++++++++++ examples/azure-functions-native/bal_build.out | 14 ++++++++ examples/azure-functions-native/bal_new.out | 1 + .../execute_function.out | 2 ++ .../az_deploy.out | 12 +++++++ .../azure-functions-hello-world.bal | 19 ++++++++++ .../azure-functions-hello-world.md | 21 +++++++++++ .../bal_build.out | 14 ++++++++ .../azure-functions-timer-trigger/bal_new.out | 1 + .../execute_function.out | 2 ++ examples/index.json | 36 +++++++++++++++++++ 25 files changed, 312 insertions(+) create mode 100644 examples/azure-functions-cosmosdb-trigger/az_deploy.out create mode 100644 examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.bal create mode 100644 examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.md create mode 100644 examples/azure-functions-cosmosdb-trigger/bal_build.out create mode 100644 examples/azure-functions-cosmosdb-trigger/bal_new.out create mode 100644 examples/azure-functions-cosmosdb-trigger/execute_function.out create mode 100644 examples/azure-functions-http-trigger/az_deploy.out create mode 100644 examples/azure-functions-http-trigger/azure-functions-hello-world.bal create mode 100644 examples/azure-functions-http-trigger/azure-functions-hello-world.md create mode 100644 examples/azure-functions-http-trigger/bal_build.out create mode 100644 examples/azure-functions-http-trigger/bal_new.out create mode 100644 examples/azure-functions-http-trigger/execute_function.out create mode 100644 examples/azure-functions-native/az_deploy.out create mode 100644 examples/azure-functions-native/azure-functions-hello-world.bal create mode 100644 examples/azure-functions-native/azure-functions-hello-world.md create mode 100644 examples/azure-functions-native/bal_build.out create mode 100644 examples/azure-functions-native/bal_new.out create mode 100644 examples/azure-functions-native/execute_function.out create mode 100644 examples/azure-functions-timer-trigger/az_deploy.out create mode 100644 examples/azure-functions-timer-trigger/azure-functions-hello-world.bal create mode 100644 examples/azure-functions-timer-trigger/azure-functions-hello-world.md create mode 100644 examples/azure-functions-timer-trigger/bal_build.out create mode 100644 examples/azure-functions-timer-trigger/bal_new.out create mode 100644 examples/azure-functions-timer-trigger/execute_function.out diff --git a/examples/azure-functions-cosmosdb-trigger/az_deploy.out b/examples/azure-functions-cosmosdb-trigger/az_deploy.out new file mode 100644 index 0000000000..968f927b8e --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/az_deploy.out @@ -0,0 +1,12 @@ +$ func azure functionapp publish bal-bbe --script-root target/azure_functions +Getting site publishing info... +Creating archive for current directory... +Uploading 28.67 MB [##############################################################################] +Upload completed successfully. +Deployment completed successfully. +Syncing triggers... +Functions in bal-bbe: + get-hello - [httpTrigger] + Invoke url: https://bal-bbe.azurewebsites.net/hello + + timer - [timerTrigger] diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.bal b/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.bal new file mode 100644 index 0000000000..0c961713d3 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.bal @@ -0,0 +1,19 @@ +import ballerinax/azure_functions as af; + +// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +service / on new af:HttpListener() { + resource function azure-functions-cosmosdb-trigger(string name) returns string { + return "Hello, " + name + "!"; + } +} + +// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer +// details will be stored in the selected queue storage for every invocation. +@af:TimerTrigger {schedule: "*/10 * * * * *"} +listener af:TimerListener timerListener = new af:TimerListener(); + +service "timer" on timerListener { + remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { + return "Message Status, " + metadata.IsPastDue.toString(); + } +} diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.md b/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.md new file mode 100644 index 0000000000..74ecd6b2ba --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.md @@ -0,0 +1,21 @@ +# Azure Functions- Hello world + +Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. + +For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). + +::: code azure-functions-cosmosdb-trigger.bal ::: + +Create a Ballerina package and replace the content of the generated BAL file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the Azure Functions artifacts. +::: out bal_build.out ::: + +Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +::: out az_deploy.out ::: + +Invoke the `HTTP Trigger` functions. +::: out execute_function.out ::: + +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-cosmosdb-trigger/bal_build.out b/examples/azure-functions-cosmosdb-trigger/bal_build.out new file mode 100644 index 0000000000..eb94c67478 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/bal_build.out @@ -0,0 +1,14 @@ +$ bal build --cloud="azure_functions" +Compiling source + wso2/azure-functions-cosmosdb-trigger:0.1.0 + +Generating executable + @azure_functions:Function: timer, get-hello + + Execute the command below to deploy the function locally. + func start --script-root target/azure_functions --java + + Execute the command below to deploy Ballerina Azure Functions. + func azure functionapp publish --script-root target/azure_functions + + target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-cosmosdb-trigger/bal_new.out b/examples/azure-functions-cosmosdb-trigger/bal_new.out new file mode 100644 index 0000000000..e79bf8f658 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-cosmosdb-trigger diff --git a/examples/azure-functions-cosmosdb-trigger/execute_function.out b/examples/azure-functions-cosmosdb-trigger/execute_function.out new file mode 100644 index 0000000000..0da4052046 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/execute_function.out @@ -0,0 +1,2 @@ +$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack +Hello, Jack! diff --git a/examples/azure-functions-http-trigger/az_deploy.out b/examples/azure-functions-http-trigger/az_deploy.out new file mode 100644 index 0000000000..968f927b8e --- /dev/null +++ b/examples/azure-functions-http-trigger/az_deploy.out @@ -0,0 +1,12 @@ +$ func azure functionapp publish bal-bbe --script-root target/azure_functions +Getting site publishing info... +Creating archive for current directory... +Uploading 28.67 MB [##############################################################################] +Upload completed successfully. +Deployment completed successfully. +Syncing triggers... +Functions in bal-bbe: + get-hello - [httpTrigger] + Invoke url: https://bal-bbe.azurewebsites.net/hello + + timer - [timerTrigger] diff --git a/examples/azure-functions-http-trigger/azure-functions-hello-world.bal b/examples/azure-functions-http-trigger/azure-functions-hello-world.bal new file mode 100644 index 0000000000..5d5a48faa9 --- /dev/null +++ b/examples/azure-functions-http-trigger/azure-functions-hello-world.bal @@ -0,0 +1,19 @@ +import ballerinax/azure_functions as af; + +// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +service / on new af:HttpListener() { + resource function azure-functions-timer-trigger(string name) returns string { + return "Hello, " + name + "!"; + } +} + +// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer +// details will be stored in the selected queue storage for every invocation. +@af:TimerTrigger {schedule: "*/10 * * * * *"} +listener af:TimerListener timerListener = new af:TimerListener(); + +service "timer" on timerListener { + remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { + return "Message Status, " + metadata.IsPastDue.toString(); + } +} diff --git a/examples/azure-functions-http-trigger/azure-functions-hello-world.md b/examples/azure-functions-http-trigger/azure-functions-hello-world.md new file mode 100644 index 0000000000..2da9ec3be3 --- /dev/null +++ b/examples/azure-functions-http-trigger/azure-functions-hello-world.md @@ -0,0 +1,21 @@ +# Azure Functions- Hello world + +Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. + +For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). + +::: code azure-functions-timer-trigger.bal ::: + +Create a Ballerina package and replace the content of the generated BAL file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the Azure Functions artifacts. +::: out bal_build.out ::: + +Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +::: out az_deploy.out ::: + +Invoke the `HTTP Trigger` functions. +::: out execute_function.out ::: + +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-http-trigger/bal_build.out b/examples/azure-functions-http-trigger/bal_build.out new file mode 100644 index 0000000000..2680763fc1 --- /dev/null +++ b/examples/azure-functions-http-trigger/bal_build.out @@ -0,0 +1,14 @@ +$ bal build --cloud="azure_functions" +Compiling source + wso2/azure-functions-timer-trigger:0.1.0 + +Generating executable + @azure_functions:Function: timer, get-hello + + Execute the command below to deploy the function locally. + func start --script-root target/azure_functions --java + + Execute the command below to deploy Ballerina Azure Functions. + func azure functionapp publish --script-root target/azure_functions + + target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-http-trigger/bal_new.out b/examples/azure-functions-http-trigger/bal_new.out new file mode 100644 index 0000000000..a58faf07b6 --- /dev/null +++ b/examples/azure-functions-http-trigger/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-timer-trigger diff --git a/examples/azure-functions-http-trigger/execute_function.out b/examples/azure-functions-http-trigger/execute_function.out new file mode 100644 index 0000000000..0da4052046 --- /dev/null +++ b/examples/azure-functions-http-trigger/execute_function.out @@ -0,0 +1,2 @@ +$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack +Hello, Jack! diff --git a/examples/azure-functions-native/az_deploy.out b/examples/azure-functions-native/az_deploy.out new file mode 100644 index 0000000000..968f927b8e --- /dev/null +++ b/examples/azure-functions-native/az_deploy.out @@ -0,0 +1,12 @@ +$ func azure functionapp publish bal-bbe --script-root target/azure_functions +Getting site publishing info... +Creating archive for current directory... +Uploading 28.67 MB [##############################################################################] +Upload completed successfully. +Deployment completed successfully. +Syncing triggers... +Functions in bal-bbe: + get-hello - [httpTrigger] + Invoke url: https://bal-bbe.azurewebsites.net/hello + + timer - [timerTrigger] diff --git a/examples/azure-functions-native/azure-functions-hello-world.bal b/examples/azure-functions-native/azure-functions-hello-world.bal new file mode 100644 index 0000000000..3716f84bcd --- /dev/null +++ b/examples/azure-functions-native/azure-functions-hello-world.bal @@ -0,0 +1,19 @@ +import ballerinax/azure_functions as af; + +// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +service / on new af:HttpListener() { + resource function azure-functions-native(string name) returns string { + return "Hello, " + name + "!"; + } +} + +// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer +// details will be stored in the selected queue storage for every invocation. +@af:TimerTrigger {schedule: "*/10 * * * * *"} +listener af:TimerListener timerListener = new af:TimerListener(); + +service "timer" on timerListener { + remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { + return "Message Status, " + metadata.IsPastDue.toString(); + } +} diff --git a/examples/azure-functions-native/azure-functions-hello-world.md b/examples/azure-functions-native/azure-functions-hello-world.md new file mode 100644 index 0000000000..02e99e69e9 --- /dev/null +++ b/examples/azure-functions-native/azure-functions-hello-world.md @@ -0,0 +1,21 @@ +# Azure Functions- Hello world + +Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. + +For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). + +::: code azure-functions-native.bal ::: + +Create a Ballerina package and replace the content of the generated BAL file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the Azure Functions artifacts. +::: out bal_build.out ::: + +Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +::: out az_deploy.out ::: + +Invoke the `HTTP Trigger` functions. +::: out execute_function.out ::: + +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-native/bal_build.out b/examples/azure-functions-native/bal_build.out new file mode 100644 index 0000000000..953a764597 --- /dev/null +++ b/examples/azure-functions-native/bal_build.out @@ -0,0 +1,14 @@ +$ bal build --cloud="azure_functions" +Compiling source + wso2/azure-functions-native:0.1.0 + +Generating executable + @azure_functions:Function: timer, get-hello + + Execute the command below to deploy the function locally. + func start --script-root target/azure_functions --java + + Execute the command below to deploy Ballerina Azure Functions. + func azure functionapp publish --script-root target/azure_functions + + target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-native/bal_new.out b/examples/azure-functions-native/bal_new.out new file mode 100644 index 0000000000..a256d15dce --- /dev/null +++ b/examples/azure-functions-native/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-native diff --git a/examples/azure-functions-native/execute_function.out b/examples/azure-functions-native/execute_function.out new file mode 100644 index 0000000000..0da4052046 --- /dev/null +++ b/examples/azure-functions-native/execute_function.out @@ -0,0 +1,2 @@ +$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack +Hello, Jack! diff --git a/examples/azure-functions-timer-trigger/az_deploy.out b/examples/azure-functions-timer-trigger/az_deploy.out new file mode 100644 index 0000000000..968f927b8e --- /dev/null +++ b/examples/azure-functions-timer-trigger/az_deploy.out @@ -0,0 +1,12 @@ +$ func azure functionapp publish bal-bbe --script-root target/azure_functions +Getting site publishing info... +Creating archive for current directory... +Uploading 28.67 MB [##############################################################################] +Upload completed successfully. +Deployment completed successfully. +Syncing triggers... +Functions in bal-bbe: + get-hello - [httpTrigger] + Invoke url: https://bal-bbe.azurewebsites.net/hello + + timer - [timerTrigger] diff --git a/examples/azure-functions-timer-trigger/azure-functions-hello-world.bal b/examples/azure-functions-timer-trigger/azure-functions-hello-world.bal new file mode 100644 index 0000000000..f90074aa51 --- /dev/null +++ b/examples/azure-functions-timer-trigger/azure-functions-hello-world.bal @@ -0,0 +1,19 @@ +import ballerinax/azure_functions as af; + +// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +service / on new af:HttpListener() { + resource function azure-functions-http-trigger(string name) returns string { + return "Hello, " + name + "!"; + } +} + +// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer +// details will be stored in the selected queue storage for every invocation. +@af:TimerTrigger {schedule: "*/10 * * * * *"} +listener af:TimerListener timerListener = new af:TimerListener(); + +service "timer" on timerListener { + remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { + return "Message Status, " + metadata.IsPastDue.toString(); + } +} diff --git a/examples/azure-functions-timer-trigger/azure-functions-hello-world.md b/examples/azure-functions-timer-trigger/azure-functions-hello-world.md new file mode 100644 index 0000000000..67a52b9fc8 --- /dev/null +++ b/examples/azure-functions-timer-trigger/azure-functions-hello-world.md @@ -0,0 +1,21 @@ +# Azure Functions- Hello world + +Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. + +For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). + +::: code azure-functions-http-trigger.bal ::: + +Create a Ballerina package and replace the content of the generated BAL file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the Azure Functions artifacts. +::: out bal_build.out ::: + +Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +::: out az_deploy.out ::: + +Invoke the `HTTP Trigger` functions. +::: out execute_function.out ::: + +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-timer-trigger/bal_build.out b/examples/azure-functions-timer-trigger/bal_build.out new file mode 100644 index 0000000000..a27fbffaf3 --- /dev/null +++ b/examples/azure-functions-timer-trigger/bal_build.out @@ -0,0 +1,14 @@ +$ bal build --cloud="azure_functions" +Compiling source + wso2/azure-functions-http-trigger:0.1.0 + +Generating executable + @azure_functions:Function: timer, get-hello + + Execute the command below to deploy the function locally. + func start --script-root target/azure_functions --java + + Execute the command below to deploy Ballerina Azure Functions. + func azure functionapp publish --script-root target/azure_functions + + target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-timer-trigger/bal_new.out b/examples/azure-functions-timer-trigger/bal_new.out new file mode 100644 index 0000000000..c358b8cb28 --- /dev/null +++ b/examples/azure-functions-timer-trigger/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-http-trigger diff --git a/examples/azure-functions-timer-trigger/execute_function.out b/examples/azure-functions-timer-trigger/execute_function.out new file mode 100644 index 0000000000..0da4052046 --- /dev/null +++ b/examples/azure-functions-timer-trigger/execute_function.out @@ -0,0 +1,2 @@ +$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack +Hello, Jack! diff --git a/examples/index.json b/examples/index.json index e0a18e8717..31724e25f7 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4400,6 +4400,42 @@ "disableVerificationReason": "Needs prerequisite condition", "disablePlayground": true, "isLearnByExample": false + }, + { + "name": "Timer trigger", + "url": "azure-functions-timer-trigger", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "HTTP trigger", + "url": "azure-functions-http-trigger", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "HTTP trigger", + "url": "azure-functions-cosmosdb-trigger", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "HTTP trigger", + "url": "azure-functions-native", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false } ] } From ec95b7889edcff745bb7f76504a098e87446257e Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Sun, 7 May 2023 17:09:22 +0530 Subject: [PATCH 18/38] Update MD files --- ...ons-hello-world.bal => azure-functions-cosmosdb-trigger.bal} | 0 ...tions-hello-world.md => azure-functions-cosmosdb-trigger.md} | 2 +- .../azure-functions-hello-world/azure-functions-hello-world.md | 2 +- .../azure-functions-http-trigger/azure-functions-hello-world.md | 2 +- ...nctions-hello-world.bal => azure-functions-http-trigger.bal} | 0 examples/azure-functions-native/azure-functions-hello-world.md | 2 +- ...ctions-hello-world.bal => azure-functions-timer-trigger.bal} | 0 ...unctions-hello-world.md => azure-functions-timer-trigger.md} | 2 +- 8 files changed, 5 insertions(+), 5 deletions(-) rename examples/azure-functions-cosmosdb-trigger/{azure-functions-hello-world.bal => azure-functions-cosmosdb-trigger.bal} (100%) rename examples/azure-functions-cosmosdb-trigger/{azure-functions-hello-world.md => azure-functions-cosmosdb-trigger.md} (96%) rename examples/azure-functions-http-trigger/{azure-functions-hello-world.bal => azure-functions-http-trigger.bal} (100%) rename examples/azure-functions-timer-trigger/{azure-functions-hello-world.bal => azure-functions-timer-trigger.bal} (100%) rename examples/azure-functions-timer-trigger/{azure-functions-hello-world.md => azure-functions-timer-trigger.md} (97%) diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.bal b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal similarity index 100% rename from examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.bal rename to examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.md b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md similarity index 96% rename from examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.md rename to examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md index 74ecd6b2ba..f87cc9b194 100644 --- a/examples/azure-functions-cosmosdb-trigger/azure-functions-hello-world.md +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md @@ -1,4 +1,4 @@ -# Azure Functions- Hello world +# Azure Functions Cosmos DB trigger Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.md b/examples/azure-functions-hello-world/azure-functions-hello-world.md index d41f3a3189..8b71a31cf3 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.md +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.md @@ -1,4 +1,4 @@ -# Azure Functions- Hello world +# Azure Functions - Hello world Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. diff --git a/examples/azure-functions-http-trigger/azure-functions-hello-world.md b/examples/azure-functions-http-trigger/azure-functions-hello-world.md index 2da9ec3be3..bda3bb0927 100644 --- a/examples/azure-functions-http-trigger/azure-functions-hello-world.md +++ b/examples/azure-functions-http-trigger/azure-functions-hello-world.md @@ -1,4 +1,4 @@ -# Azure Functions- Hello world +# Azure Functions- HTTP trigger Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. diff --git a/examples/azure-functions-http-trigger/azure-functions-hello-world.bal b/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal similarity index 100% rename from examples/azure-functions-http-trigger/azure-functions-hello-world.bal rename to examples/azure-functions-http-trigger/azure-functions-http-trigger.bal diff --git a/examples/azure-functions-native/azure-functions-hello-world.md b/examples/azure-functions-native/azure-functions-hello-world.md index 02e99e69e9..606aee6694 100644 --- a/examples/azure-functions-native/azure-functions-hello-world.md +++ b/examples/azure-functions-native/azure-functions-hello-world.md @@ -1,4 +1,4 @@ -# Azure Functions- Hello world +# Azure Functions native Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. diff --git a/examples/azure-functions-timer-trigger/azure-functions-hello-world.bal b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal similarity index 100% rename from examples/azure-functions-timer-trigger/azure-functions-hello-world.bal rename to examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal diff --git a/examples/azure-functions-timer-trigger/azure-functions-hello-world.md b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md similarity index 97% rename from examples/azure-functions-timer-trigger/azure-functions-hello-world.md rename to examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md index 67a52b9fc8..a5c889f620 100644 --- a/examples/azure-functions-timer-trigger/azure-functions-hello-world.md +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md @@ -1,4 +1,4 @@ -# Azure Functions- Hello world +# Azure Functions timer trigger Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. From 207f0518191bc27bd66bd9e2ba6ab474ce9a1913 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Mon, 8 May 2023 07:39:49 +0530 Subject: [PATCH 19/38] Fix file names of Azure BBEs --- ...functions-hello-world.md => azure-functions-http-trigger.md} | 2 +- ...ure-functions-hello-world.bal => azure-functions-native.bal} | 0 ...azure-functions-hello-world.md => azure-functions-native.md} | 0 .../azure-functions-timer-trigger.md | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename examples/azure-functions-http-trigger/{azure-functions-hello-world.md => azure-functions-http-trigger.md} (96%) rename examples/azure-functions-native/{azure-functions-hello-world.bal => azure-functions-native.bal} (100%) rename examples/azure-functions-native/{azure-functions-hello-world.md => azure-functions-native.md} (100%) diff --git a/examples/azure-functions-http-trigger/azure-functions-hello-world.md b/examples/azure-functions-http-trigger/azure-functions-http-trigger.md similarity index 96% rename from examples/azure-functions-http-trigger/azure-functions-hello-world.md rename to examples/azure-functions-http-trigger/azure-functions-http-trigger.md index bda3bb0927..56143d3ed1 100644 --- a/examples/azure-functions-http-trigger/azure-functions-hello-world.md +++ b/examples/azure-functions-http-trigger/azure-functions-http-trigger.md @@ -4,7 +4,7 @@ Azure Functions is an event driven, serverless computing platform. Azure Functio For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). -::: code azure-functions-timer-trigger.bal ::: +::: code azure-functions-http-trigger.bal ::: Create a Ballerina package and replace the content of the generated BAL file with the content above. ::: out bal_new.out ::: diff --git a/examples/azure-functions-native/azure-functions-hello-world.bal b/examples/azure-functions-native/azure-functions-native.bal similarity index 100% rename from examples/azure-functions-native/azure-functions-hello-world.bal rename to examples/azure-functions-native/azure-functions-native.bal diff --git a/examples/azure-functions-native/azure-functions-hello-world.md b/examples/azure-functions-native/azure-functions-native.md similarity index 100% rename from examples/azure-functions-native/azure-functions-hello-world.md rename to examples/azure-functions-native/azure-functions-native.md diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md index a5c889f620..8212447b6f 100644 --- a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md @@ -4,7 +4,7 @@ Azure Functions is an event driven, serverless computing platform. Azure Functio For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). -::: code azure-functions-http-trigger.bal ::: +::: code azure-functions-timer-trigger.bal ::: Create a Ballerina package and replace the content of the generated BAL file with the content above. ::: out bal_new.out ::: From a28bc3a822debdcfe436c1577373a6e5158b940b Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Mon, 8 May 2023 19:10:55 +0530 Subject: [PATCH 20/38] Fix tips and hyperlinks rendering issues --- .../aws-lambda-dynamodb-trigger.md | 6 +++--- .../aws-lambda-execution-context.md | 2 +- .../aws-lambda-hello-world.md | 2 +- .../aws-lambda-s3-trigger.md | 4 ++-- examples/azure-functions-native/az_deploy.out | 12 ----------- .../azure-functions-native.bal | 19 ----------------- .../azure-functions-native.md | 21 ------------------- examples/azure-functions-native/bal_build.out | 14 ------------- examples/azure-functions-native/bal_new.out | 1 - .../execute_function.out | 2 -- examples/index.json | 11 +--------- 11 files changed, 8 insertions(+), 86 deletions(-) delete mode 100644 examples/azure-functions-native/az_deploy.out delete mode 100644 examples/azure-functions-native/azure-functions-native.bal delete mode 100644 examples/azure-functions-native/azure-functions-native.md delete mode 100644 examples/azure-functions-native/bal_build.out delete mode 100644 examples/azure-functions-native/bal_new.out delete mode 100644 examples/azure-functions-native/execute_function.out diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index 8dec3b115f..23462f1652 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -28,15 +28,15 @@ Execute the command below to generate the AWS Lambda artifacts. Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. - >**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +>**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). ::: out aws_deploy.out ::: ## Invoke the function To invoke this function, create a DynamoDB table. -1. Go to **roles**, and add `AWSLambdaDynamoDBExecutionRole` to the created role in the prerequisites. -2. Go to the DynamoDB. +1. Go to **roles**, and add `AWSLambdaDynamoDBExecutionRole` to the created role in the prerequisites. +2. Go to the DynamoDB. 3. Click **Create Table**, enter the table name, partition key, and create the table (If you already have a table created, you can skip this step). 4. Click on the DynamoDB table, and then click the **Exports and streams** tab. 5. Click **enable DynamoDB stream details**, and select the key attributes only for the event type. diff --git a/examples/aws-lambda-execution-context/aws-lambda-execution-context.md b/examples/aws-lambda-execution-context/aws-lambda-execution-context.md index c95a83f63c..a2c92ab257 100644 --- a/examples/aws-lambda-execution-context/aws-lambda-execution-context.md +++ b/examples/aws-lambda-execution-context/aws-lambda-execution-context.md @@ -28,7 +28,7 @@ Execute the command below to generate the AWS Lambda artifacts. Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. - >**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +>**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). ::: out aws_deploy.out ::: diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md index 7e40328bef..56f206f22c 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md @@ -28,7 +28,7 @@ Execute the command below to generate the AWS Lambda artifacts. Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. - >**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +>**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). ::: out aws_deploy.out ::: diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index 4f9f708186..7a9112f125 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -28,14 +28,14 @@ Execute the command below to generate the AWS Lambda artifacts. Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. - >**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +>**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). ::: out aws_deploy.out ::: ## Invoke the function To invoke this function, create an S3 bucket in AWS. -1. Go to AWS S3 portal and create a bucket. +1. Go to AWS S3 portal and create a bucket. 2. Click on the created bucket, go to the **Properties** tab, and click on the **Create event notification** under the **Event notifications** section. 3. Enable `All object create events` under event types. Select the Lambda function as the destination, and choose the `notifyS3` Lambda function from the dropdown. diff --git a/examples/azure-functions-native/az_deploy.out b/examples/azure-functions-native/az_deploy.out deleted file mode 100644 index 968f927b8e..0000000000 --- a/examples/azure-functions-native/az_deploy.out +++ /dev/null @@ -1,12 +0,0 @@ -$ func azure functionapp publish bal-bbe --script-root target/azure_functions -Getting site publishing info... -Creating archive for current directory... -Uploading 28.67 MB [##############################################################################] -Upload completed successfully. -Deployment completed successfully. -Syncing triggers... -Functions in bal-bbe: - get-hello - [httpTrigger] - Invoke url: https://bal-bbe.azurewebsites.net/hello - - timer - [timerTrigger] diff --git a/examples/azure-functions-native/azure-functions-native.bal b/examples/azure-functions-native/azure-functions-native.bal deleted file mode 100644 index 3716f84bcd..0000000000 --- a/examples/azure-functions-native/azure-functions-native.bal +++ /dev/null @@ -1,19 +0,0 @@ -import ballerinax/azure_functions as af; - -// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. -service / on new af:HttpListener() { - resource function azure-functions-native(string name) returns string { - return "Hello, " + name + "!"; - } -} - -// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer -// details will be stored in the selected queue storage for every invocation. -@af:TimerTrigger {schedule: "*/10 * * * * *"} -listener af:TimerListener timerListener = new af:TimerListener(); - -service "timer" on timerListener { - remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { - return "Message Status, " + metadata.IsPastDue.toString(); - } -} diff --git a/examples/azure-functions-native/azure-functions-native.md b/examples/azure-functions-native/azure-functions-native.md deleted file mode 100644 index 606aee6694..0000000000 --- a/examples/azure-functions-native/azure-functions-native.md +++ /dev/null @@ -1,21 +0,0 @@ -# Azure Functions native - -Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. - -For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). - -::: code azure-functions-native.bal ::: - -Create a Ballerina package and replace the content of the generated BAL file with the content above. -::: out bal_new.out ::: - -Build the Ballerina program to generate the Azure Functions artifacts. -::: out bal_build.out ::: - -Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). -::: out az_deploy.out ::: - -Invoke the `HTTP Trigger` functions. -::: out execute_function.out ::: - -The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-native/bal_build.out b/examples/azure-functions-native/bal_build.out deleted file mode 100644 index 953a764597..0000000000 --- a/examples/azure-functions-native/bal_build.out +++ /dev/null @@ -1,14 +0,0 @@ -$ bal build --cloud="azure_functions" -Compiling source - wso2/azure-functions-native:0.1.0 - -Generating executable - @azure_functions:Function: timer, get-hello - - Execute the command below to deploy the function locally. - func start --script-root target/azure_functions --java - - Execute the command below to deploy Ballerina Azure Functions. - func azure functionapp publish --script-root target/azure_functions - - target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-native/bal_new.out b/examples/azure-functions-native/bal_new.out deleted file mode 100644 index a256d15dce..0000000000 --- a/examples/azure-functions-native/bal_new.out +++ /dev/null @@ -1 +0,0 @@ -$ bal new azure-functions-native diff --git a/examples/azure-functions-native/execute_function.out b/examples/azure-functions-native/execute_function.out deleted file mode 100644 index 0da4052046..0000000000 --- a/examples/azure-functions-native/execute_function.out +++ /dev/null @@ -1,2 +0,0 @@ -$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack -Hello, Jack! diff --git a/examples/index.json b/examples/index.json index 31724e25f7..cf706e8154 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4420,22 +4420,13 @@ "isLearnByExample": false }, { - "name": "HTTP trigger", + "name": "Cosmos DB trigger", "url": "azure-functions-cosmosdb-trigger", "verifyBuild": false, "verifyOutput": false, "disableVerificationReason": "Needs prerequisite condition", "disablePlayground": true, "isLearnByExample": false - }, - { - "name": "HTTP trigger", - "url": "azure-functions-native", - "verifyBuild": false, - "verifyOutput": false, - "disableVerificationReason": "Needs prerequisite condition", - "disablePlayground": true, - "isLearnByExample": false } ] } From 5ae2294bd793790bf4c111aed688f4971982ac3e Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Mon, 8 May 2023 19:58:42 +0530 Subject: [PATCH 21/38] Add target blank in MD format --- .../aws-lambda-dynamodb-trigger.md | 4 ++-- examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index 23462f1652..10e1e6b521 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -35,8 +35,8 @@ Execute the AWS CLI commands to create and publish the functions by setting your ## Invoke the function To invoke this function, create a DynamoDB table. -1. Go to **roles**, and add `AWSLambdaDynamoDBExecutionRole` to the created role in the prerequisites. -2. Go to the DynamoDB. +1. Go to [**roles**](https://console.aws.amazon.com/iamv2/home#/roles){:target="_blank"}, and add `AWSLambdaDynamoDBExecutionRole` to the created role in the prerequisites. +2. Go to the [DynamoDB](https://us-west-1.console.aws.amazon.com/dynamodbv2){:target="_blank"}. 3. Click **Create Table**, enter the table name, partition key, and create the table (If you already have a table created, you can skip this step). 4. Click on the DynamoDB table, and then click the **Exports and streams** tab. 5. Click **enable DynamoDB stream details**, and select the key attributes only for the event type. diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index 7a9112f125..fceb9892aa 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -35,7 +35,7 @@ Execute the AWS CLI commands to create and publish the functions by setting your ## Invoke the function To invoke this function, create an S3 bucket in AWS. -1. Go to AWS S3 portal and create a bucket. +1. Go to [AWS S3](https://s3.console.aws.amazon.com/s3/){:target="_blank"} portal and create a bucket. 2. Click on the created bucket, go to the **Properties** tab, and click on the **Create event notification** under the **Event notifications** section. 3. Enable `All object create events` under event types. Select the Lambda function as the destination, and choose the `notifyS3` Lambda function from the dropdown. From 5f807fd377070bdcd9dadf9fb2421f5489095ec9 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Mon, 8 May 2023 21:16:59 +0530 Subject: [PATCH 22/38] Remove target_blank from hyperlinks --- .../aws-lambda-dynamodb-trigger.md | 6 +++--- examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index 10e1e6b521..fa1b93b5d8 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -35,9 +35,9 @@ Execute the AWS CLI commands to create and publish the functions by setting your ## Invoke the function To invoke this function, create a DynamoDB table. -1. Go to [**roles**](https://console.aws.amazon.com/iamv2/home#/roles){:target="_blank"}, and add `AWSLambdaDynamoDBExecutionRole` to the created role in the prerequisites. -2. Go to the [DynamoDB](https://us-west-1.console.aws.amazon.com/dynamodbv2){:target="_blank"}. -3. Click **Create Table**, enter the table name, partition key, and create the table (If you already have a table created, you can skip this step). +1. Go to [**roles**](https://console.aws.amazon.com/iamv2/home#/roles), and add `AWSLambdaDynamoDBExecutionRole` to the created role in the prerequisites. +2. Go to the [DynamoDB](https://us-west-1.console.aws.amazon.com/dynamodbv2). +3. Click **Create Table**, enter the table name, partition key, and create the table (if you already have a table created, you can skip this step). 4. Click on the DynamoDB table, 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's enabled, click **Create a trigger**, select the `notifyDynamoDB` from the dropdown, and create a trigger. diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index fceb9892aa..814c393e92 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -35,7 +35,7 @@ Execute the AWS CLI commands to create and publish the functions by setting your ## Invoke the function To invoke this function, create an S3 bucket in AWS. -1. Go to [AWS S3](https://s3.console.aws.amazon.com/s3/){:target="_blank"} portal and create a bucket. +1. Go to [AWS S3](https://s3.console.aws.amazon.com/s3/) portal and create a bucket. 2. Click on the created bucket, go to the **Properties** tab, and click on the **Create event notification** under the **Event notifications** section. 3. Enable `All object create events` under event types. Select the Lambda function as the destination, and choose the `notifyS3` Lambda function from the dropdown. From 169f0d380d4330850423ff7d634bbdd1d4e73eae Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Tue, 9 May 2023 19:08:25 +0530 Subject: [PATCH 23/38] Update Azure BBEs --- .../aws-lambda-dynamodb-trigger.md | 2 +- .../azure-functions-cosmosdb-trigger.bal | 27 ++++++++-------- .../azure-functions-cosmosdb-trigger.md | 31 ++++++++++++++++--- .../execute_function.out | 2 -- .../azure-functions-hello-world.bal | 11 ------- .../azure-functions-http-trigger.bal | 27 +++++++--------- .../azure-functions-http-trigger.md | 8 +++-- .../execute_function.out | 7 +++-- 8 files changed, 63 insertions(+), 52 deletions(-) delete mode 100644 examples/azure-functions-cosmosdb-trigger/execute_function.out diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index fa1b93b5d8..2d44bccf0d 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -42,6 +42,6 @@ To invoke this function, create a DynamoDB table. 5. Click **enable DynamoDB stream details**, and select the key attributes only for the event type. 6. Once it's enabled, click **Create a trigger**, select the `notifyDynamoDB` from the dropdown, and create a trigger. -Now, add an entry to the DynamoDB table to invoke the Lambda function. For this, go to **Items** in the DynamoDB, select the table, and click **Create item**. Once the item is entered into the table, go to the Lambda function, and check the logs via CloudWatch to see the object identifier in the logs. +Now, add an entry to the DynamoDB table to invoke the Lambda function. For this, go to [**Items**](https://us-west-1.console.aws.amazon.com/dynamodbv2) in the DynamoDB, select the table, and click **Create item**. Once the item is entered into the table, go to the Lambda function, and check the logs via CloudWatch to see the object identifier in the logs. ::: out invoke_functions.out ::: diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal index 0c961713d3..00c391e514 100644 --- a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal @@ -1,19 +1,18 @@ +import ballerina/log; import ballerinax/azure_functions as af; -// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. -service / on new af:HttpListener() { - resource function azure-functions-cosmosdb-trigger(string name) returns string { - return "Hello, " + name + "!"; - } -} +public type DBEntry record { + string id; + string name; +}; -// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer -// details will be stored in the selected queue storage for every invocation. -@af:TimerTrigger {schedule: "*/10 * * * * *"} -listener af:TimerListener timerListener = new af:TimerListener(); +@af:CosmosDBTrigger {connectionStringSetting: "CosmosDBConnection", databaseName: "db1", collectionName: "c1"} +listener af:CosmosDBListener cosmosEp = new (); -service "timer" on timerListener { - remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { - return "Message Status, " + metadata.IsPastDue.toString(); +service "cosmos" on cosmosEp { + remote function onUpdate(DBEntry[] entries) returns @af:QueueOutput {queueName: "people"} string { + string name = entries[0].name; + log:printInfo(entries.toJsonString()); + return "Hello, " + name; } -} +} \ No newline at end of file diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md index f87cc9b194..1f9178ac9d 100644 --- a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md @@ -1,9 +1,29 @@ # Azure Functions Cosmos DB trigger -Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. +The following Ballerina code gives an example of using a Cosmos DB trigger to invoke the function and a queue output binding to write an entry to a queue. + +Before writing and deploying the code, create a Cosmos DB and a queue to make use of those services later. +1. You can reuse the queue you created in the above [`HTTP trigger` -> `Queue output`](/learn/by-example/azure-functions/http-trigger/) example. +2. Create an [Azure Cosmos DB account](https://portal.azure.com/#create/Microsoft.DocumentDB) and select Cosmos DB Core. +3. Once the database is created, go to the **Data Explorer**, and select **Create Container**. +4. Enter `db1` as Database ID and `c1` as the collection ID, and click **Ok**. + +**Note:** If you want to change these values, make sure to change them in the code as well. +5. Go to the **Keys** tab of the Cosmos DB page. +6. Copy the value of the `PRIMARY CONNECTION STRING`. +7. Click the **Configuration** tab on the Function app page. +8. Select **New Application Setting**, and paste the data you copied above as the value. For the key, use the value of the `connectionStringSetting` key and save. + +Example application setting is as follows. +``` +Name - `CosmosDBConnection` +Value - `AccountEndpoint=https://db-cosmos.documents.azure.com:443/;AccountKey=12345asda;` +``` For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). +Now, as all the infrastructure required are up and running and configured, start building and deploying the Azure function. + ::: code azure-functions-cosmosdb-trigger.bal ::: Create a Ballerina package and replace the content of the generated BAL file with the content above. @@ -15,7 +35,10 @@ Build the Ballerina program to generate the Azure Functions artifacts. Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). ::: out az_deploy.out ::: -Invoke the `HTTP Trigger` functions. -::: out execute_function.out ::: +Once the function is deployed, add an item to the collection. +1. Navigate to the collection created in the **Data Explorer**. +2. Click **New Item** to add a new item to the collection. +3. Go to the queue page and observe the added new entry. + +>**Info:** Additionally, for debugging purposes, view the logs under the **Logs stream** in the function app. -The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-cosmosdb-trigger/execute_function.out b/examples/azure-functions-cosmosdb-trigger/execute_function.out deleted file mode 100644 index 0da4052046..0000000000 --- a/examples/azure-functions-cosmosdb-trigger/execute_function.out +++ /dev/null @@ -1,2 +0,0 @@ -$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack -Hello, Jack! diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.bal b/examples/azure-functions-hello-world/azure-functions-hello-world.bal index 8c9c37e2aa..73a1ad3c27 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.bal +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.bal @@ -6,14 +6,3 @@ service / on new af:HttpListener() { return "Hello, " + name + "!"; } } - -// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer -// details will be stored in the selected queue storage for every invocation. -@af:TimerTrigger {schedule: "*/10 * * * * *"} -listener af:TimerListener timerListener = new af:TimerListener(); - -service "timer" on timerListener { - remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { - return "Message Status, " + metadata.IsPastDue.toString(); - } -} diff --git a/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal b/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal index 5d5a48faa9..9f5fda5ba3 100644 --- a/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal +++ b/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal @@ -1,19 +1,16 @@ +import ballerina/http; import ballerinax/azure_functions as af; -// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. -service / on new af:HttpListener() { - resource function azure-functions-timer-trigger(string name) returns string { - return "Hello, " + name + "!"; - } -} +public type Person record { + string name; + int age; +}; -// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer -// details will be stored in the selected queue storage for every invocation. -@af:TimerTrigger {schedule: "*/10 * * * * *"} -listener af:TimerListener timerListener = new af:TimerListener(); - -service "timer" on timerListener { - remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { - return "Message Status, " + metadata.IsPastDue.toString(); +service / on new af:HttpListener() { + resource function post queue(@http:Payload Person person) returns [@af:HttpOutput http:Created, @af:QueueOutput {queueName: "people"} string] { + http:Created httpRes = { + body: person.name + " Added to the Queue!" + }; + return [httpRes, person.name + " is " + person.age.toString() + " years old."]; } -} +} \ No newline at end of file diff --git a/examples/azure-functions-http-trigger/azure-functions-http-trigger.md b/examples/azure-functions-http-trigger/azure-functions-http-trigger.md index 56143d3ed1..2356ebea6e 100644 --- a/examples/azure-functions-http-trigger/azure-functions-http-trigger.md +++ b/examples/azure-functions-http-trigger/azure-functions-http-trigger.md @@ -1,8 +1,10 @@ # Azure Functions- HTTP trigger -Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. +The following Ballerina code gives an example of using an HTTP trigger to invoke the function and uses multiple output bindings to return the HTTP response and queue output binding to write an entry to a queue. -For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). +First, create a queue to hold the outputs of the function by accessing the storage account that was created alongside the function app in the prerequisites. Select Queues in the sidebar in the storage accounts. Click the Add queue button, and enter the same value as the value of the queueName property in the below QueueOutput annotation. + +For more information, see the [Azure Functions deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). ::: code azure-functions-http-trigger.bal ::: @@ -18,4 +20,4 @@ Execute the Azure CLI command given by the compiler to publish the functions (re Invoke the `HTTP Trigger` functions. ::: out execute_function.out ::: -The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). +Refresh the queue page in the portal and view the added entry. diff --git a/examples/azure-functions-http-trigger/execute_function.out b/examples/azure-functions-http-trigger/execute_function.out index 0da4052046..ed4539d051 100644 --- a/examples/azure-functions-http-trigger/execute_function.out +++ b/examples/azure-functions-http-trigger/execute_function.out @@ -1,2 +1,5 @@ -$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack -Hello, Jack! +$ curl --header "Content-Type: application/json" \ + --request POST \ + --data '{"name":"Jack","age":21}' \ + "https://.azurewebsites.net/queue" +Jack Added to the Queue! \ No newline at end of file From ce0bc516ba164191fb540754dadbcfdb473d9ee7 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Tue, 9 May 2023 21:49:13 +0530 Subject: [PATCH 24/38] Fix structure and formatting of all C2C BBEs --- .../aws-lambda-dynamodb-trigger.md | 41 ++++++------- .../invoke_functions.out | 8 --- .../aws-lambda-execution-context.md | 22 +++---- .../aws-lambda-hello-world.md | 22 +++---- .../aws-lambda-s3-trigger.md | 37 ++++++------ .../invoke_functions.out | 8 --- .../azure-functions-cosmosdb-trigger.md | 57 +++++++++++++------ .../azure-functions-hello-world.md | 40 ++++++++++--- .../azure-functions-hello-world/bal_build.out | 2 +- .../azure-functions-http-trigger.md | 41 +++++++++---- .../azure-functions-timer-trigger.bal | 2 +- .../azure-functions-timer-trigger.md | 36 ++++++++---- .../bal_build.out | 2 +- .../execute_function.out | 2 - 14 files changed, 195 insertions(+), 125 deletions(-) delete mode 100644 examples/aws-lambda-dynamodb-trigger/invoke_functions.out delete mode 100644 examples/aws-lambda-s3-trigger/invoke_functions.out delete mode 100644 examples/azure-functions-timer-trigger/execute_function.out diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index 2d44bccf0d..e206c538cf 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -1,24 +1,26 @@ # AWS Lambda DynamoDB trigger -AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +This sample 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](/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). -## Create a Ballerina package +## Write the function -Execute the command below to create a new Ballerina package. +Follow the steps below to write the function. -::: out bal_new.out ::: +1. Execute the command below to create a new Ballerina package. -## Replace the code +::: out bal_new.out ::: -Replace the content of the generated Ballerina file with the content below. +2. Replace the content of the generated Ballerina file with the content below. ::: code aws-lambda-dynamodb-trigger.bal ::: -## Build the Ballerina program +## Build the function Execute the command below to generate the AWS Lambda artifacts. @@ -26,22 +28,21 @@ Execute the command below to generate the AWS Lambda artifacts. ## Deploy the function -Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. +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. ->**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +>**Tip:** For instructions on getting the values, see [Set up an AWS account](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-an-aws-account). ::: out aws_deploy.out ::: ## Invoke the function -To invoke this function, create a DynamoDB table. -1. Go to [**roles**](https://console.aws.amazon.com/iamv2/home#/roles), and add `AWSLambdaDynamoDBExecutionRole` to the created role in the prerequisites. -2. Go to the [DynamoDB](https://us-west-1.console.aws.amazon.com/dynamodbv2). -3. Click **Create Table**, enter the table name, partition key, and create the table (if you already have a table created, you can skip this step). -4. Click on the DynamoDB table, 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's enabled, click **Create a trigger**, select the `notifyDynamoDB` from the dropdown, and create a trigger. - -Now, add an entry to the DynamoDB table to invoke the Lambda function. For this, go to [**Items**](https://us-west-1.console.aws.amazon.com/dynamodbv2) in the DynamoDB, select the table, and click **Create item**. Once the item is entered into the table, go to the Lambda function, and check the logs via CloudWatch to see the object identifier in the logs. +Follow the instructions below to create a DynamoDB table for invoking this function. -::: out invoke_functions.out ::: +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 `notifyDynamoDB` 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. diff --git a/examples/aws-lambda-dynamodb-trigger/invoke_functions.out b/examples/aws-lambda-dynamodb-trigger/invoke_functions.out deleted file mode 100644 index 6dcc89b4e1..0000000000 --- a/examples/aws-lambda-dynamodb-trigger/invoke_functions.out +++ /dev/null @@ -1,8 +0,0 @@ -$ echo '{"MESSAGE":"HELLO"}' > input.json -$ aws lambda invoke --function-name notifysDynamoDB --payload fileb://input.json echo-response.txt -{ -"ExecutedVersion": "$LATEST", -"StatusCode": 200 -} -$ cat echo-response.txt -{"MESSAGE":"HELLO"} \ No newline at end of file diff --git a/examples/aws-lambda-execution-context/aws-lambda-execution-context.md b/examples/aws-lambda-execution-context/aws-lambda-execution-context.md index a2c92ab257..73422a59c6 100644 --- a/examples/aws-lambda-execution-context/aws-lambda-execution-context.md +++ b/examples/aws-lambda-execution-context/aws-lambda-execution-context.md @@ -1,24 +1,26 @@ # AWS Lambda execution context -The example below demonstrates how context information of an AWS function are executed. +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](/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). -## Create a Ballerina package +## Write the function -Execute the command below to create a new Ballerina package. +Follow the steps below to write the function. -::: out bal_new.out ::: +1. Execute the command below to create a new Ballerina package. -## Replace the code +::: out bal_new.out ::: -Replace the content of the generated Ballerina file with the content below. +2. Replace the content of the generated Ballerina file with the content below. ::: code aws-lambda-execution-context.bal ::: -## Build the Ballerina program +## Build the function Execute the command below to generate the AWS Lambda artifacts. @@ -26,9 +28,9 @@ Execute the command below to generate the AWS Lambda artifacts. ## Deploy the function -Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. +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. ->**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +>**Tip:** For instructions on getting the values, see [Set up an AWS account](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-an-aws-account). ::: out aws_deploy.out ::: diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md index 56f206f22c..96ed5353a4 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md @@ -1,24 +1,26 @@ # AWS Lambda - Hello world -AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +This example demonstrates how to expose 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](/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). -## Create a Ballerina package +## Write the function -Execute the command below to create a new Ballerina package. +Follow the steps below to write the function. -::: out bal_new.out ::: +1. Execute the command below to create a new Ballerina package. -## Replace the code +::: out bal_new.out ::: -Replace the content of the generated Ballerina file with the content below. +2. Replace the content of the generated Ballerina file with the content below. ::: code aws-lambda-hello-world.bal ::: -## Build the Ballerina program +## Build the function Execute the command below to generate the AWS Lambda artifacts. @@ -26,9 +28,9 @@ Execute the command below to generate the AWS Lambda artifacts. ## Deploy the function -Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. +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. ->**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +>**Tip:** For instructions on getting the values, see [Set up an AWS account](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-an-aws-account). ::: out aws_deploy.out ::: diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index 814c393e92..37f67faf97 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -1,24 +1,26 @@ # AWS Lambda S3 trigger -AWS Lambda is an event driven, serverless computing platform. Ballerina functions can be deployed in AWS Lambda by annotating a Ballerina function with `@awslambda:Function`, which should have the `function (awslambda:Context, json|EventType) returns json|error` function signature. For more information, see the [AWS Lambda learn guide](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +This sample creates a function, which will be executed for each object creation in AWS S3. + +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](/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). -## Create a Ballerina package +## Write the function -Execute the command below to create a new Ballerina package. +Follow the steps below to write the function. -::: out bal_new.out ::: +1. Execute the command below to create a new Ballerina package. -## Replace the code +::: out bal_new.out ::: -Replace the content of the generated Ballerina file with the content below. +2. Replace the content of the generated Ballerina file with the content below. ::: code aws-lambda-s3-trigger.bal ::: -## Build the Ballerina program +## Build the function Execute the command below to generate the AWS Lambda artifacts. @@ -26,19 +28,20 @@ Execute the command below to generate the AWS Lambda artifacts. ## Deploy the function -Execute the AWS CLI commands to create and publish the functions by setting your respective AWS `$LAMBDA_ROLE_ARN`, `$REGION_ID`, and `$FUNCTION_NAME` values. +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. ->**Tip:** For instructions on getting the value for the`$LAMBDA_ROLE_ARN`, see [AWS Lambda deployment](/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). +>**Tip:** For instructions on getting the values, see [Set up an AWS account](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-an-aws-account). ::: out aws_deploy.out ::: ## Invoke the function -To invoke this function, create an S3 bucket in AWS. -1. Go to [AWS S3](https://s3.console.aws.amazon.com/s3/) portal and create a bucket. -2. Click on the created bucket, go to the **Properties** tab, and click on the **Create event notification** under the **Event notifications** section. -3. Enable `All object create events` under event types. Select the Lambda function as the destination, and choose the `notifyS3` Lambda function from the dropdown. - -Now, click **Upload** to upload an object to the S3 bucket, and view the Lambda logs via CloudWatch to see the object name. +Follow the instructions below to create an S3 bucket in AWS for invoking this function. -::: out invoke_functions.out ::: +1. Go to the [AWS S3](https://s3.console.aws.amazon.com/s3/) portal and create a bucket. +2. Click on the created bucket, go to the **Properties** tab, and click **Create event notification** under the **Event notifications** section. +3. Enable **All object create events** under event types. +4. Select the AWS Lambda function as the destination. +5. Select the `notifyS3` Lambda function from the dropdown. +6. Click **Upload** to upload an object to the S3 bucket. +7. Go to the AWS Lambda function and check the logs via CloudWatch to see the object name in the logs. diff --git a/examples/aws-lambda-s3-trigger/invoke_functions.out b/examples/aws-lambda-s3-trigger/invoke_functions.out deleted file mode 100644 index 3d368a8df7..0000000000 --- a/examples/aws-lambda-s3-trigger/invoke_functions.out +++ /dev/null @@ -1,8 +0,0 @@ -$ echo '{"MESSAGE":"HELLO"}' > input.json -$ aws lambda invoke --function-name notifys3 --payload fileb://input.json echo-response.txt -{ -"ExecutedVersion": "$LATEST", -"StatusCode": 200 -} -$ cat echo-response.txt -{"MESSAGE":"HELLO"} \ No newline at end of file diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md index 1f9178ac9d..61e707dabe 100644 --- a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md @@ -1,41 +1,62 @@ # Azure Functions Cosmos DB trigger -The following Ballerina code gives an example of using a Cosmos DB trigger to invoke the function and a queue output binding to write an entry to a queue. +This example demonstrates using a Cosmos DB trigger to invoke an AWS Lambda function and a queue output binding to write an entry to a queue. -Before writing and deploying the code, create a Cosmos DB and a queue to make use of those services later. -1. You can reuse the queue you created in the above [`HTTP trigger` -> `Queue output`](/learn/by-example/azure-functions/http-trigger/) example. -2. Create an [Azure Cosmos DB account](https://portal.azure.com/#create/Microsoft.DocumentDB) and select Cosmos DB Core. -3. Once the database is created, go to the **Data Explorer**, and select **Create Container**. -4. Enter `db1` as Database ID and `c1` as the collection ID, and click **Ok**. +For more information, see the [Azure Functions deployment guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/). -**Note:** If you want to change these values, make sure to change them in the code as well. -5. Go to the **Keys** tab of the Cosmos DB page. -6. Copy the value of the `PRIMARY CONNECTION STRING`. -7. Click the **Configuration** tab on the Function app page. -8. Select **New Application Setting**, and paste the data you copied above as the value. For the key, use the value of the `connectionStringSetting` key and save. +## Set up the prerequisites + +Follow the steps below to create a Cosmos DB and a queue to make use of those services later in this example. + +1. Set up the [general prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). +2. Create the queue in the [HTTP trigger](/learn/by-example/azure-functions/http-trigger/) example to resue it in this one. +3. Create an [Azure Cosmos DB account](https://portal.azure.com/#create/Microsoft.DocumentDB) and select **Cosmos DB Core**. +4. Once the database is created, go to the **Data Explorer**, and select **Create Container**. +5. Enter `db1` as the Database ID, `c1` as the collection ID, and click **Ok**. +>**Note:** If you want to change these values, change them in the code as well. +6. Go to the **Keys** tab of the Cosmos DB page. +7. Copy the value of the `PRIMARY CONNECTION STRING`. +8. Click the **Configuration** tab on the function app page. +9. Select **New Application Setting**, and paste the data you copied above as the value. +>**Tip:** For the key, use the value of the `connectionStringSetting` key and save. Example application setting is as follows. + ``` Name - `CosmosDBConnection` Value - `AccountEndpoint=https://db-cosmos.documents.azure.com:443/;AccountKey=12345asda;` ``` -For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). - Now, as all the infrastructure required are up and running and configured, start building and deploying the Azure function. -::: code azure-functions-cosmosdb-trigger.bal ::: +## Write the function + +Follow the steps below to write the function. + +1. Execute the command below to create a new Ballerina package. -Create a Ballerina package and replace the content of the generated BAL file with the content above. ::: out bal_new.out ::: -Build the Ballerina program to generate the Azure Functions artifacts. +2. Replace the content of the generated Ballerina file with the content below. + +::: code azure-functions-cosmosdb-trigger.bal ::: + +## Build the function + +Execute the command below to generate the Azure Functions artifacts. + ::: out bal_build.out ::: -Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). -::: out az_deploy.out ::: +## Deploy the function + +Execute the Azure CLI command given by the compiler to create and publish the functions by replacing the sample app name given in the command with your respective Azure ``. + +>**Tip:** For instructions on getting the values, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). + +## Invoke the function Once the function is deployed, add an item to the collection. + 1. Navigate to the collection created in the **Data Explorer**. 2. Click **New Item** to add a new item to the collection. 3. Go to the queue page and observe the added new entry. diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.md b/examples/azure-functions-hello-world/azure-functions-hello-world.md index 8b71a31cf3..cbb4f677f7 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.md +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.md @@ -1,21 +1,43 @@ # Azure Functions - Hello world -Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. +This example demonstrates how to expose a simple echo function in Azure Functions. -For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). +For more information, see the [Azure deployment guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/). -::: code azure-functions-hello-world.bal ::: +## Set up the prerequisites + +For instructions, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#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. -Create a Ballerina package and replace the content of the generated BAL file with the content above. ::: out bal_new.out ::: -Build the Ballerina program to generate the Azure Functions artifacts. +2. Replace the content of the generated Ballerina file with the content below. + +>**Info:** In the code sample shown above, it has an empty service path and resource path named `hello`. The accessor is `get`. It expects a request with a query parameter for the field `name`. The required artifact generation and data binding will be handled by the `ballerinax/azure_functions` package automatically. + +::: code azure-functions-hello-world.bal ::: + +## Build the function + +Execute the command below to generate the Azure Functions artifacts. + ::: out bal_build.out ::: -Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +## Deploy the function + +Execute the Azure CLI command given by the compiler to create and publish the functions by replacing the sample app name given in the command with your respective Azure ``. + +>**Tip:** For instructions on getting the values, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). + ::: out az_deploy.out ::: -Invoke the `HTTP Trigger` functions. -::: out execute_function.out ::: +## Invoke the function -The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). +Execute the commands below to invoke the function. + +::: out execute_function.out ::: diff --git a/examples/azure-functions-hello-world/bal_build.out b/examples/azure-functions-hello-world/bal_build.out index 67e8673154..bfb0dbc3d6 100644 --- a/examples/azure-functions-hello-world/bal_build.out +++ b/examples/azure-functions-hello-world/bal_build.out @@ -3,7 +3,7 @@ Compiling source wso2/azure-functions-hello-world:0.1.0 Generating executable - @azure_functions:Function: timer, get-hello + @azure_functions:Function: get-hello Execute the command below to deploy the function locally. func start --script-root target/azure_functions --java diff --git a/examples/azure-functions-http-trigger/azure-functions-http-trigger.md b/examples/azure-functions-http-trigger/azure-functions-http-trigger.md index 2356ebea6e..c9aef5f579 100644 --- a/examples/azure-functions-http-trigger/azure-functions-http-trigger.md +++ b/examples/azure-functions-http-trigger/azure-functions-http-trigger.md @@ -1,23 +1,44 @@ # Azure Functions- HTTP trigger -The following Ballerina code gives an example of using an HTTP trigger to invoke the function and uses multiple output bindings to return the HTTP response and queue output binding to write an entry to a queue. +This example demonstrates using an HTTP trigger to invoke an Azure function with multiple output bindings to return the HTTP response and queue output binding to write an entry to a queue. -First, create a queue to hold the outputs of the function by accessing the storage account that was created alongside the function app in the prerequisites. Select Queues in the sidebar in the storage accounts. Click the Add queue button, and enter the same value as the value of the queueName property in the below QueueOutput annotation. +For more information, see the [Azure Functions deployment guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/). -For more information, see the [Azure Functions deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). +## Set up the prerequisites -::: code azure-functions-http-trigger.bal ::: +1. Set up the [general prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). +2. Accessing the storage account that was created alongside the function app in step 1, and create a queue to hold the outputs of the function. +3. Select **Queues** in the sidebar in the storage accounts. +4. Click the **Add queue** button, and enter the same value as the value of the `queueName` property in the `QueueOutput` annotation in the [Ballerina source below](https://ballerina.io/learn/by-example/azure-functions-trigger/#write-the-function). + +## Write the function + +Follow the steps below to write the function. + +1. Execute the command below to create a new Ballerina package. -Create a Ballerina package and replace the content of the generated BAL file with the content above. ::: out bal_new.out ::: -Build the Ballerina program to generate the Azure Functions artifacts. +2. Replace the content of the generated Ballerina file with the content below. + +::: code azure-functions-http-trigger.bal ::: + +## Build the function + +Execute the command below to generate the Azure Functions artifacts. + ::: out bal_build.out ::: -Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). -::: out az_deploy.out ::: +## Deploy the function + +Execute the Azure CLI command given by the compiler to create and publish the functions by replacing the sample app name given in the command with your respective Azure ``. + +>**Tip:** For instructions on getting the values, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). + +## Invoke the function + +Execute the commands below to invoke the function. -Invoke the `HTTP Trigger` functions. ::: out execute_function.out ::: -Refresh the queue page in the portal and view the added entry. +>**Tip:** Refresh the queue page in the portal and view the added entry. diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal index f90074aa51..5d5a48faa9 100644 --- a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal @@ -2,7 +2,7 @@ import ballerinax/azure_functions as af; // This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. service / on new af:HttpListener() { - resource function azure-functions-http-trigger(string name) returns string { + resource function azure-functions-timer-trigger(string name) returns string { return "Hello, " + name + "!"; } } diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md index 8212447b6f..19809f36f4 100644 --- a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md @@ -1,21 +1,37 @@ # Azure Functions timer trigger -Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. +This example demonstrates how a function can be scheduled to execute periodically by the Azure Functions app. Once the function is executed, the timer details will be stored in the selected queue storage for every invocation. -For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). +For more information, see the [Azure deployment guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/). -::: code azure-functions-timer-trigger.bal ::: +## Set up the prerequisites + +For instructions, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#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. -Create a Ballerina package and replace the content of the generated BAL file with the content above. ::: out bal_new.out ::: -Build the Ballerina program to generate the Azure Functions artifacts. +2. Replace the content of the generated Ballerina file with the content below. + +::: code azure-functions-timer-trigger.bal ::: + +## Build the function + +Execute the command below to generate the Azure Functions artifacts. + ::: out bal_build.out ::: -Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). -::: out az_deploy.out ::: +## Deploy the function + +Execute the Azure CLI command given by the compiler to create and publish the functions by replacing the sample app name given in the command with your respective Azure ``. + +>**Tip:** For instructions on getting the values, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). -Invoke the `HTTP Trigger` functions. -::: out execute_function.out ::: +## Invoke the function -The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. diff --git a/examples/azure-functions-timer-trigger/bal_build.out b/examples/azure-functions-timer-trigger/bal_build.out index a27fbffaf3..b11ce9a914 100644 --- a/examples/azure-functions-timer-trigger/bal_build.out +++ b/examples/azure-functions-timer-trigger/bal_build.out @@ -3,7 +3,7 @@ Compiling source wso2/azure-functions-http-trigger:0.1.0 Generating executable - @azure_functions:Function: timer, get-hello + @azure_functions:Function: timer Execute the command below to deploy the function locally. func start --script-root target/azure_functions --java diff --git a/examples/azure-functions-timer-trigger/execute_function.out b/examples/azure-functions-timer-trigger/execute_function.out deleted file mode 100644 index 0da4052046..0000000000 --- a/examples/azure-functions-timer-trigger/execute_function.out +++ /dev/null @@ -1,2 +0,0 @@ -$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack -Hello, Jack! From 6b3d21e4bc8ff834c4e3d70c0de1e1e29d793455 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Tue, 9 May 2023 23:17:13 +0530 Subject: [PATCH 25/38] Add metatags files to all C2C BBEs --- .../aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md | 2 +- .../aws-lambda-dynamodb-trigger.metatags | 2 ++ .../aws-lambda-execution-context.metatags | 2 ++ examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags | 2 ++ examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md | 2 +- examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags | 2 ++ .../azure-functions-cosmosdb-trigger.metatags | 2 ++ .../azure-functions-hello-world.metatags | 2 ++ .../azure-functions-http-trigger.metatags | 2 ++ .../azure-functions-timer-trigger.metatags | 2 ++ 10 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.metatags create mode 100644 examples/aws-lambda-execution-context/aws-lambda-execution-context.metatags create mode 100644 examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags create mode 100644 examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags create mode 100644 examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.metatags create mode 100644 examples/azure-functions-hello-world/azure-functions-hello-world.metatags create mode 100644 examples/azure-functions-http-trigger/azure-functions-http-trigger.metatags create mode 100644 examples/azure-functions-timer-trigger/azure-functions-timer-trigger.metatags diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index e206c538cf..9be8b6e6a3 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -1,6 +1,6 @@ # AWS Lambda DynamoDB trigger -This sample creates a function, which will be executed for each entry added to a database in the DynamoDB. +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/). diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.metatags b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.metatags new file mode 100644 index 0000000000..00806a5bdd --- /dev/null +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.metatags @@ -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, bbe, aws lambda, dynamodb, diff --git a/examples/aws-lambda-execution-context/aws-lambda-execution-context.metatags b/examples/aws-lambda-execution-context/aws-lambda-execution-context.metatags new file mode 100644 index 0000000000..d4fbe6944c --- /dev/null +++ b/examples/aws-lambda-execution-context/aws-lambda-execution-context.metatags @@ -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 diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags b/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags new file mode 100644 index 0000000000..101dd8f1f1 --- /dev/null +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags @@ -0,0 +1,2 @@ +description: This example demonstrates how to expose a simple echo function in AWS Lambda. +keywords: ballerina, ballerina by example, bbe, aws lambda diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index 37f67faf97..12761b50cd 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -1,6 +1,6 @@ # AWS Lambda S3 trigger -This sample creates a function, which will be executed for each object creation in AWS S3. +This example creates a function, which will be executed for each object creation in AWS S3. For more information, see the [AWS Lambda learn guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/). diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags new file mode 100644 index 0000000000..f5625bdf8c --- /dev/null +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags @@ -0,0 +1,2 @@ +description: This example creates a function, which will be executed for each object creation in AWS S3. +keywords: ballerina, ballerina by example, bbe, aws lambda, s3, trigger diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.metatags b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.metatags new file mode 100644 index 0000000000..3258599bc3 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.metatags @@ -0,0 +1,2 @@ +description: This example demonstrates using a Cosmos DB trigger to invoke an AWS Lambda function and a queue output binding to write an entry to a queue. +keywords: ballerina, ballerina by example, bbe, aws lambda, cosmos db, trigger diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.metatags b/examples/azure-functions-hello-world/azure-functions-hello-world.metatags new file mode 100644 index 0000000000..e2905fb680 --- /dev/null +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.metatags @@ -0,0 +1,2 @@ +description: This example demonstrates how to expose a simple echo function in Azure Functions. +keywords: ballerina, ballerina by example, bbe, aws lambda diff --git a/examples/azure-functions-http-trigger/azure-functions-http-trigger.metatags b/examples/azure-functions-http-trigger/azure-functions-http-trigger.metatags new file mode 100644 index 0000000000..0fd392ee22 --- /dev/null +++ b/examples/azure-functions-http-trigger/azure-functions-http-trigger.metatags @@ -0,0 +1,2 @@ +description: This example demonstrates using an HTTP trigger to invoke an Azure function with multiple output bindings to return the HTTP response and queue output binding to write an entry to a queue. +keywords: ballerina, ballerina by example, bbe, aws lambda, http, trigger diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.metatags b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.metatags new file mode 100644 index 0000000000..c10e03f87b --- /dev/null +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.metatags @@ -0,0 +1,2 @@ +description: This example demonstrates how a function can be scheduled to execute periodically by the Azure Functions app. +keywords: ballerina, ballerina by example, bbe, aws lambda, timer, trigger From 73b4b5e3a7bbb4ce84fc328d2a0bd171ded128e5 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Wed, 10 May 2023 14:44:25 +0530 Subject: [PATCH 26/38] Fix build error and take observability section up --- .../azure-functions-cosmosdb-trigger.md | 8 +- examples/index.json | 82 +++++++++---------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md index 61e707dabe..7231806ec2 100644 --- a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md @@ -20,12 +20,10 @@ Follow the steps below to create a Cosmos DB and a queue to make use of those se 9. Select **New Application Setting**, and paste the data you copied above as the value. >**Tip:** For the key, use the value of the `connectionStringSetting` key and save. -Example application setting is as follows. +Example application settings are as follows. -``` -Name - `CosmosDBConnection` -Value - `AccountEndpoint=https://db-cosmos.documents.azure.com:443/;AccountKey=12345asda;` -``` +- Name - `CosmosDBConnection` +- Value - `AccountEndpoint=https://db-cosmos.documents.azure.com:443/;AccountKey=12345asda;` Now, as all the infrastructure required are up and running and configured, start building and deploying the Azure function. diff --git a/examples/index.json b/examples/index.json index cf706e8154..0149b0e29c 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4271,47 +4271,6 @@ } ] }, - { - "title": "Tracing", - "column": 0, - "category": "Observability", - "samples": [ - { - "name": "Distributed tracing", - "url": "tracing", - "verifyBuild": false, - "verifyOutput": false, - "disableVerificationReason": "Includes ballerinax components", - "disablePlayground": true, - "isLearnByExample": false - }, - { - "name": "Counter-based metrics", - "url": "counter-metrics", - "verifyBuild": false, - "verifyOutput": false, - "disableVerificationReason": "Includes ballerinax components", - "disablePlayground": true, - "isLearnByExample": false - } - ] - }, - { - "title": "Metrics", - "column": 1, - "category": "Observability", - "samples": [ - { - "name": "Gauge-based metrics", - "url": "gauge-metrics", - "verifyBuild": false, - "verifyOutput": false, - "disableVerificationReason": "Includes ballerinax components", - "disablePlayground": true, - "isLearnByExample": false - } - ] - }, { "title": "Docker", "column": 0, @@ -4429,5 +4388,46 @@ "isLearnByExample": false } ] + }, + { + "title": "Tracing", + "column": 0, + "category": "Observability", + "samples": [ + { + "name": "Distributed tracing", + "url": "tracing", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Includes ballerinax components", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "Counter-based metrics", + "url": "counter-metrics", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Includes ballerinax components", + "disablePlayground": true, + "isLearnByExample": false + } + ] + }, + { + "title": "Metrics", + "column": 1, + "category": "Observability", + "samples": [ + { + "name": "Gauge-based metrics", + "url": "gauge-metrics", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Includes ballerinax components", + "disablePlayground": true, + "isLearnByExample": false + } + ] } ] From 65a0680971e6ae7e9013671112e31e63fa2e99c6 Mon Sep 17 00:00:00 2001 From: Praneesha Chandrasiri Date: Thu, 11 May 2023 16:30:09 +0530 Subject: [PATCH 27/38] Review and update bal codes --- .../aws-lambda-dynamodb-trigger.bal | 7 ++----- .../aws-lambda-dynamodb-trigger.md | 2 +- examples/aws-lambda-dynamodb-trigger/aws_deploy.out | 2 +- examples/aws-lambda-dynamodb-trigger/bal_build.out | 2 +- .../aws-lambda-execution-context.bal | 1 - examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal | 7 ++----- examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md | 2 +- examples/aws-lambda-s3-trigger/aws_deploy.out | 2 +- examples/aws-lambda-s3-trigger/bal_build.out | 2 +- examples/azure-functions-cosmosdb-trigger/bal_build.out | 2 +- .../azure-functions-hello-world.bal | 3 ++- .../azure-functions-timer-trigger.bal | 7 ------- 12 files changed, 13 insertions(+), 26 deletions(-) diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.bal b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.bal index e0884ff2d1..42776fcc6c 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.bal +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.bal @@ -1,11 +1,8 @@ import ballerina/io; import ballerinax/awslambda; -// The `@awslambda:Function` annotation marks a function to generate an AWS Lambda function. - @awslambda:Function -public function notifyDynamoDB(awslambda:Context ctx, - awslambda:DynamoDBEvent event) returns json { +public function dynamoDBTrigger(awslambda:Context ctx, + awslambda:DynamoDBEvent event) { io:println(event.Records[0].dynamodb.Keys.toString()); - return event.Records[0].dynamodb.Keys.toString(); } diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index 9be8b6e6a3..34c423410f 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -43,6 +43,6 @@ Follow the instructions below to create a DynamoDB table for invoking this funct 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 `notifyDynamoDB` from the dropdown, and create a trigger. +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. diff --git a/examples/aws-lambda-dynamodb-trigger/aws_deploy.out b/examples/aws-lambda-dynamodb-trigger/aws_deploy.out index bd34f36f07..0069df5061 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws_deploy.out +++ b/examples/aws-lambda-dynamodb-trigger/aws_deploy.out @@ -1 +1 @@ -$ aws lambda create-function --function-name notifysDynamoDB --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-dynamodb-trigger.notifyDynamoDB --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 +$ 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 diff --git a/examples/aws-lambda-dynamodb-trigger/bal_build.out b/examples/aws-lambda-dynamodb-trigger/bal_build.out index 1041130382..8fd10e70c7 100644 --- a/examples/aws-lambda-dynamodb-trigger/bal_build.out +++ b/examples/aws-lambda-dynamodb-trigger/bal_build.out @@ -3,7 +3,7 @@ Compiling source wso2/aws-lambda-dynamodb-trigger:0.1.0 Generating executable - @awslambda:Function: notifyDynamoDB + @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:///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 diff --git a/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal b/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal index 6d0961bdea..ffbe324623 100644 --- a/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal +++ b/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal @@ -1,5 +1,4 @@ import ballerinax/awslambda; -import ballerina/io; // The `awslambda:Context` object contains request execution context information. @awslambda:Function diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal index 69d6e2e6b2..a4a11a117b 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal @@ -1,11 +1,8 @@ import ballerina/io; import ballerinax/awslambda; -// The `@awslambda:Function` annotation marks a function to generate an AWS Lambda function. - @awslambda:Function -public function notifyS3(awslambda:Context ctx, - awslambda:S3Event event) returns json { +public function s3Trigger(awslambda:Context ctx, + awslambda:S3Event event) { io:println(event.Records[0].s3.'object.key); - return event.Records[0].s3.'object.key; } \ No newline at end of file diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index 12761b50cd..603d43c20f 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -42,6 +42,6 @@ Follow the instructions below to create an S3 bucket in AWS for invoking this fu 2. Click on the created bucket, go to the **Properties** tab, and click **Create event notification** under the **Event notifications** section. 3. Enable **All object create events** under event types. 4. Select the AWS Lambda function as the destination. -5. Select the `notifyS3` Lambda function from the dropdown. +5. Select the `s3Trigger` Lambda function from the dropdown. 6. Click **Upload** to upload an object to the S3 bucket. 7. Go to the AWS Lambda function and check the logs via CloudWatch to see the object name in the logs. diff --git a/examples/aws-lambda-s3-trigger/aws_deploy.out b/examples/aws-lambda-s3-trigger/aws_deploy.out index ced418627b..b1b14c6f1a 100644 --- a/examples/aws-lambda-s3-trigger/aws_deploy.out +++ b/examples/aws-lambda-s3-trigger/aws_deploy.out @@ -1 +1 @@ -$ aws lambda create-function --function-name notifys3 --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-s3-trigger.notifys3 --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 +$ aws lambda create-function --function-name s3Trigger --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-s3-trigger.s3Trigger --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 diff --git a/examples/aws-lambda-s3-trigger/bal_build.out b/examples/aws-lambda-s3-trigger/bal_build.out index 6a4dd1486e..192b860d1f 100644 --- a/examples/aws-lambda-s3-trigger/bal_build.out +++ b/examples/aws-lambda-s3-trigger/bal_build.out @@ -3,7 +3,7 @@ Compiling source wso2/aws-lambda-s3-trigger:0.1.0 Generating executable - @awslambda:Function: notifys3 + @awslambda:Function: s3Trigger Run the following command to deploy each Ballerina AWS Lambda function: aws lambda create-function --function-name $FUNCTION_NAME --zip-file fileb:///aws-lambda-s3-trigger/target/bin/aws-ballerina-lambda-functions.zip --handler aws-lambda-s3-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 diff --git a/examples/azure-functions-cosmosdb-trigger/bal_build.out b/examples/azure-functions-cosmosdb-trigger/bal_build.out index eb94c67478..3b36378a03 100644 --- a/examples/azure-functions-cosmosdb-trigger/bal_build.out +++ b/examples/azure-functions-cosmosdb-trigger/bal_build.out @@ -3,7 +3,7 @@ Compiling source wso2/azure-functions-cosmosdb-trigger:0.1.0 Generating executable - @azure_functions:Function: timer, get-hello + @azure_functions:Function: cosmos Execute the command below to deploy the function locally. func start --script-root target/azure_functions --java diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.bal b/examples/azure-functions-hello-world/azure-functions-hello-world.bal index 73a1ad3c27..b79c6f33d3 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.bal +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.bal @@ -1,6 +1,7 @@ import ballerinax/azure_functions as af; -// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +// This function gets triggered by an HTTP call with the name query parameter and +// returns a processed HTTP output to the caller. service / on new af:HttpListener() { resource function get hello(string name) returns string { return "Hello, " + name + "!"; diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal index 5d5a48faa9..bc2d6377bf 100644 --- a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal @@ -1,12 +1,5 @@ import ballerinax/azure_functions as af; -// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. -service / on new af:HttpListener() { - resource function azure-functions-timer-trigger(string name) returns string { - return "Hello, " + name + "!"; - } -} - // This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer // details will be stored in the selected queue storage for every invocation. @af:TimerTrigger {schedule: "*/10 * * * * *"} From 94dbbbc8bcab877018df2656e50d9f97bc0689b5 Mon Sep 17 00:00:00 2001 From: praneesha Date: Fri, 7 Jul 2023 14:01:25 +0530 Subject: [PATCH 28/38] Update examples/aws-lambda-hello-world/aws-lambda-hello-world.md Co-authored-by: Anjana Supun --- examples/aws-lambda-hello-world/aws-lambda-hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md index 96ed5353a4..e3e99b3aff 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md @@ -1,6 +1,6 @@ # AWS Lambda - Hello world -This example demonstrates how to expose a simple echo function in AWS Lambda. +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/). From 46b96d90e7920742194ffd782e2d5763ed2cb8fc Mon Sep 17 00:00:00 2001 From: praneesha Date: Fri, 7 Jul 2023 14:01:36 +0530 Subject: [PATCH 29/38] Update examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags Co-authored-by: Anjana Supun --- examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags b/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags index 101dd8f1f1..9daa0c0210 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags @@ -1,2 +1,2 @@ -description: This example demonstrates how to expose a simple echo function in AWS Lambda. +description: This example demonstrates how to write a simple echo function in AWS Lambda. keywords: ballerina, ballerina by example, bbe, aws lambda From 96767394fc8dbd421991cf95d8a9461e6f32a4f3 Mon Sep 17 00:00:00 2001 From: praneesha Date: Fri, 7 Jul 2023 14:01:47 +0530 Subject: [PATCH 30/38] Update examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags Co-authored-by: Anjana Supun --- examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags b/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags index 9daa0c0210..8bb3559706 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.metatags @@ -1,2 +1,2 @@ description: This example demonstrates how to write a simple echo function in AWS Lambda. -keywords: ballerina, ballerina by example, bbe, aws lambda +keywords: ballerina, ballerina by example, serverless, aws lambda, cloud, function as a service From 9bb765fa6e04241bb643935f5faa42fa0263b861 Mon Sep 17 00:00:00 2001 From: praneesha Date: Fri, 7 Jul 2023 14:02:01 +0530 Subject: [PATCH 31/38] Update examples/azure-functions-hello-world/azure-functions-hello-world.metatags Co-authored-by: Anjana Supun --- .../azure-functions-hello-world.metatags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.metatags b/examples/azure-functions-hello-world/azure-functions-hello-world.metatags index e2905fb680..4a7a12ff31 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.metatags +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.metatags @@ -1,2 +1,2 @@ description: This example demonstrates how to expose a simple echo function in Azure Functions. -keywords: ballerina, ballerina by example, bbe, aws lambda +keywords: ballerina, ballerina by example, azure functions, function as a service, serverless From 3e5b6cf1b4d58a1c998109d09b711fec11aeaa8e Mon Sep 17 00:00:00 2001 From: praneesha Date: Fri, 7 Jul 2023 14:02:44 +0530 Subject: [PATCH 32/38] Update examples/azure-functions-hello-world/azure-functions-hello-world.metatags Co-authored-by: Anjana Supun --- .../azure-functions-hello-world.metatags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.metatags b/examples/azure-functions-hello-world/azure-functions-hello-world.metatags index 4a7a12ff31..94c8e451fe 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.metatags +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.metatags @@ -1,2 +1,2 @@ -description: This example demonstrates how to expose a simple echo function in Azure Functions. +description: This example demonstrates how to write a hello world function with http trigger and output in Azure Functions. keywords: ballerina, ballerina by example, azure functions, function as a service, serverless From 5c41c98caa163ddef904fa4edea8f3efd5bcf5a2 Mon Sep 17 00:00:00 2001 From: praneesha Date: Fri, 7 Jul 2023 15:32:23 +0530 Subject: [PATCH 33/38] Address review comments --- .../aws-lambda-dynamodb-trigger.md | 2 -- .../aws-lambda-dynamodb-trigger.metatags | 2 +- .../aws-lambda-execution-context.bal | 1 - .../aws-lambda-execution-context.md | 2 -- .../aws-lambda-execution-context.metatags | 2 +- examples/aws-lambda-hello-world/aws-lambda-hello-world.bal | 4 ++-- examples/aws-lambda-hello-world/aws-lambda-hello-world.md | 2 -- examples/aws-lambda-hello-world/invoke_functions.out | 2 +- examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal | 2 +- examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md | 2 -- .../aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags | 2 +- .../azure-functions-cosmosdb-trigger.bal | 4 ++-- .../azure-functions-cosmosdb-trigger.md | 2 -- .../azure-functions-cosmosdb-trigger.metatags | 2 +- .../azure-functions-hello-world.md | 4 +--- .../az_deploy.out | 2 -- .../azure-functions-http-trigger-with-queue.bal} | 2 +- .../azure-functions-http-trigger-with-queue.md} | 6 ++---- .../azure-functions-http-trigger-with-queue.metatags} | 2 +- .../bal_build.out | 0 .../azure-functions-http-trigger-with-queue/bal_new.out | 1 + .../execute_function.out | 2 +- examples/azure-functions-http-trigger/bal_new.out | 1 - .../azure-functions-timer-trigger.md | 2 -- .../azure-functions-timer-trigger.metatags | 2 +- examples/index.json | 4 ++-- 26 files changed, 20 insertions(+), 39 deletions(-) rename examples/{azure-functions-http-trigger => azure-functions-http-trigger-with-queue}/az_deploy.out (94%) rename examples/{azure-functions-http-trigger/azure-functions-http-trigger.bal => azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.bal} (99%) rename examples/{azure-functions-http-trigger/azure-functions-http-trigger.md => azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.md} (86%) rename examples/{azure-functions-http-trigger/azure-functions-http-trigger.metatags => azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.metatags} (64%) rename examples/{azure-functions-http-trigger => azure-functions-http-trigger-with-queue}/bal_build.out (100%) create mode 100644 examples/azure-functions-http-trigger-with-queue/bal_new.out rename examples/{azure-functions-http-trigger => azure-functions-http-trigger-with-queue}/execute_function.out (86%) delete mode 100644 examples/azure-functions-http-trigger/bal_new.out diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md index 34c423410f..a8d57fbdc9 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.md @@ -30,8 +30,6 @@ Execute the command below to generate the AWS Lambda artifacts. 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. ->**Tip:** For instructions on getting the values, see [Set up an AWS account](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-an-aws-account). - ::: out aws_deploy.out ::: ## Invoke the function diff --git a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.metatags b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.metatags index 00806a5bdd..ad99d516d2 100644 --- a/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.metatags +++ b/examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigger.metatags @@ -1,2 +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, bbe, aws lambda, dynamodb, +keywords: ballerina, ballerina by example, aws lambda, dynamodb, serverless, cloud, function as a service diff --git a/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal b/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal index ffbe324623..36bb967d82 100644 --- a/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal +++ b/examples/aws-lambda-execution-context/aws-lambda-execution-context.bal @@ -1,6 +1,5 @@ import ballerinax/awslambda; -// The `awslambda:Context` object contains request execution context information. @awslambda:Function public function ctxinfo(awslambda:Context ctx, json input) returns json|error { return { diff --git a/examples/aws-lambda-execution-context/aws-lambda-execution-context.md b/examples/aws-lambda-execution-context/aws-lambda-execution-context.md index 73422a59c6..24fbc442fa 100644 --- a/examples/aws-lambda-execution-context/aws-lambda-execution-context.md +++ b/examples/aws-lambda-execution-context/aws-lambda-execution-context.md @@ -30,8 +30,6 @@ Execute the command below to generate the AWS Lambda artifacts. 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. ->**Tip:** For instructions on getting the values, see [Set up an AWS account](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-an-aws-account). - ::: out aws_deploy.out ::: ## Invoke the function diff --git a/examples/aws-lambda-execution-context/aws-lambda-execution-context.metatags b/examples/aws-lambda-execution-context/aws-lambda-execution-context.metatags index d4fbe6944c..d75a357ce1 100644 --- a/examples/aws-lambda-execution-context/aws-lambda-execution-context.metatags +++ b/examples/aws-lambda-execution-context/aws-lambda-execution-context.metatags @@ -1,2 +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 +keywords: ballerina, ballerina by example, aws lambda, execution context, serverless, cloud, function as a service diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.bal b/examples/aws-lambda-hello-world/aws-lambda-hello-world.bal index 687e73a20c..252c7878f8 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.bal +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.bal @@ -1,9 +1,9 @@ -import ballerina/log; +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 { - log:printInfo(input.toJsonString()); + io:println(input.toJsonString()); return input; } diff --git a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md index e3e99b3aff..c20fd64db5 100644 --- a/examples/aws-lambda-hello-world/aws-lambda-hello-world.md +++ b/examples/aws-lambda-hello-world/aws-lambda-hello-world.md @@ -30,8 +30,6 @@ Execute the command below to generate the AWS Lambda artifacts. 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. ->**Tip:** For instructions on getting the values, see [Set up an AWS account](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-an-aws-account). - ::: out aws_deploy.out ::: ## Invoke the function diff --git a/examples/aws-lambda-hello-world/invoke_functions.out b/examples/aws-lambda-hello-world/invoke_functions.out index 59881e570c..c45754e688 100644 --- a/examples/aws-lambda-hello-world/invoke_functions.out +++ b/examples/aws-lambda-hello-world/invoke_functions.out @@ -5,4 +5,4 @@ $ aws lambda invoke --function-name echo --payload fileb://input.json echo-respo "StatusCode": 200 } $ cat echo-response.txt -{"MESSAGE":"HELLO"} \ No newline at end of file +{"MESSAGE":"HELLO"} diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal index a4a11a117b..e6160d6e75 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal @@ -5,4 +5,4 @@ import ballerinax/awslambda; public function s3Trigger(awslambda:Context ctx, awslambda:S3Event event) { io:println(event.Records[0].s3.'object.key); -} \ No newline at end of file +} diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md index 603d43c20f..abe3bfcd4a 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md @@ -30,8 +30,6 @@ Execute the command below to generate the AWS Lambda artifacts. 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. ->**Tip:** For instructions on getting the values, see [Set up an AWS account](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/aws-lambda/#set-up-an-aws-account). - ::: out aws_deploy.out ::: ## Invoke the function diff --git a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags index f5625bdf8c..17fd5bcb3c 100644 --- a/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags +++ b/examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.metatags @@ -1,2 +1,2 @@ description: This example creates a function, which will be executed for each object creation in AWS S3. -keywords: ballerina, ballerina by example, bbe, aws lambda, s3, trigger +keywords: ballerina, ballerina by example, aws lambda, s3, trigger, serverless, cloud, function as a service diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal index 00c391e514..30ffd4e072 100644 --- a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal @@ -1,4 +1,4 @@ -import ballerina/log; +import ballerina/io; import ballerinax/azure_functions as af; public type DBEntry record { @@ -12,7 +12,7 @@ listener af:CosmosDBListener cosmosEp = new (); service "cosmos" on cosmosEp { remote function onUpdate(DBEntry[] entries) returns @af:QueueOutput {queueName: "people"} string { string name = entries[0].name; - log:printInfo(entries.toJsonString()); + io:println(entries.toJsonString()); return "Hello, " + name; } } \ No newline at end of file diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md index 7231806ec2..6c8a16a3f8 100644 --- a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md @@ -49,8 +49,6 @@ Execute the command below to generate the Azure Functions artifacts. Execute the Azure CLI command given by the compiler to create and publish the functions by replacing the sample app name given in the command with your respective Azure ``. ->**Tip:** For instructions on getting the values, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). - ## Invoke the function Once the function is deployed, add an item to the collection. diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.metatags b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.metatags index 3258599bc3..8a9cb7e4cf 100644 --- a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.metatags +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.metatags @@ -1,2 +1,2 @@ description: This example demonstrates using a Cosmos DB trigger to invoke an AWS Lambda function and a queue output binding to write an entry to a queue. -keywords: ballerina, ballerina by example, bbe, aws lambda, cosmos db, trigger +keywords: ballerina, ballerina by example, aws lambda, cosmos db, trigger, serverless, cloud, function as a service diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.md b/examples/azure-functions-hello-world/azure-functions-hello-world.md index cbb4f677f7..a43ab7162c 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.md +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.md @@ -1,6 +1,6 @@ # Azure Functions - Hello world -This example demonstrates how to expose a simple echo function in Azure Functions. +This example demonstrates how to write a simple echo function in Azure Functions. For more information, see the [Azure deployment guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/). @@ -32,8 +32,6 @@ Execute the command below to generate the Azure Functions artifacts. Execute the Azure CLI command given by the compiler to create and publish the functions by replacing the sample app name given in the command with your respective Azure ``. ->**Tip:** For instructions on getting the values, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). - ::: out az_deploy.out ::: ## Invoke the function diff --git a/examples/azure-functions-http-trigger/az_deploy.out b/examples/azure-functions-http-trigger-with-queue/az_deploy.out similarity index 94% rename from examples/azure-functions-http-trigger/az_deploy.out rename to examples/azure-functions-http-trigger-with-queue/az_deploy.out index 968f927b8e..cdd093ffbd 100644 --- a/examples/azure-functions-http-trigger/az_deploy.out +++ b/examples/azure-functions-http-trigger-with-queue/az_deploy.out @@ -8,5 +8,3 @@ Syncing triggers... Functions in bal-bbe: get-hello - [httpTrigger] Invoke url: https://bal-bbe.azurewebsites.net/hello - - timer - [timerTrigger] diff --git a/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal b/examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.bal similarity index 99% rename from examples/azure-functions-http-trigger/azure-functions-http-trigger.bal rename to examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.bal index 9f5fda5ba3..2ad7b7ee2f 100644 --- a/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal +++ b/examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.bal @@ -13,4 +13,4 @@ service / on new af:HttpListener() { }; return [httpRes, person.name + " is " + person.age.toString() + " years old."]; } -} \ No newline at end of file +} diff --git a/examples/azure-functions-http-trigger/azure-functions-http-trigger.md b/examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.md similarity index 86% rename from examples/azure-functions-http-trigger/azure-functions-http-trigger.md rename to examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.md index c9aef5f579..3184f6156d 100644 --- a/examples/azure-functions-http-trigger/azure-functions-http-trigger.md +++ b/examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.md @@ -1,4 +1,4 @@ -# Azure Functions- HTTP trigger +# Azure Functions- HTTP trigger with queue This example demonstrates using an HTTP trigger to invoke an Azure function with multiple output bindings to return the HTTP response and queue output binding to write an entry to a queue. @@ -21,7 +21,7 @@ Follow the steps below to write the function. 2. Replace the content of the generated Ballerina file with the content below. -::: code azure-functions-http-trigger.bal ::: +::: code azure-functions-http-trigger-with-queue.bal ::: ## Build the function @@ -33,8 +33,6 @@ Execute the command below to generate the Azure Functions artifacts. Execute the Azure CLI command given by the compiler to create and publish the functions by replacing the sample app name given in the command with your respective Azure ``. ->**Tip:** For instructions on getting the values, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). - ## Invoke the function Execute the commands below to invoke the function. diff --git a/examples/azure-functions-http-trigger/azure-functions-http-trigger.metatags b/examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.metatags similarity index 64% rename from examples/azure-functions-http-trigger/azure-functions-http-trigger.metatags rename to examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.metatags index 0fd392ee22..bfb22ffc2f 100644 --- a/examples/azure-functions-http-trigger/azure-functions-http-trigger.metatags +++ b/examples/azure-functions-http-trigger-with-queue/azure-functions-http-trigger-with-queue.metatags @@ -1,2 +1,2 @@ description: This example demonstrates using an HTTP trigger to invoke an Azure function with multiple output bindings to return the HTTP response and queue output binding to write an entry to a queue. -keywords: ballerina, ballerina by example, bbe, aws lambda, http, trigger +keywords: ballerina, ballerina by example, aws lambda, http, trigger, serverless, cloud, function as a service diff --git a/examples/azure-functions-http-trigger/bal_build.out b/examples/azure-functions-http-trigger-with-queue/bal_build.out similarity index 100% rename from examples/azure-functions-http-trigger/bal_build.out rename to examples/azure-functions-http-trigger-with-queue/bal_build.out diff --git a/examples/azure-functions-http-trigger-with-queue/bal_new.out b/examples/azure-functions-http-trigger-with-queue/bal_new.out new file mode 100644 index 0000000000..3425a3298e --- /dev/null +++ b/examples/azure-functions-http-trigger-with-queue/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-http-trigger-with-queue diff --git a/examples/azure-functions-http-trigger/execute_function.out b/examples/azure-functions-http-trigger-with-queue/execute_function.out similarity index 86% rename from examples/azure-functions-http-trigger/execute_function.out rename to examples/azure-functions-http-trigger-with-queue/execute_function.out index ed4539d051..168340bfc7 100644 --- a/examples/azure-functions-http-trigger/execute_function.out +++ b/examples/azure-functions-http-trigger-with-queue/execute_function.out @@ -2,4 +2,4 @@ $ curl --header "Content-Type: application/json" \ --request POST \ --data '{"name":"Jack","age":21}' \ "https://.azurewebsites.net/queue" -Jack Added to the Queue! \ No newline at end of file +Jack Added to the Queue! diff --git a/examples/azure-functions-http-trigger/bal_new.out b/examples/azure-functions-http-trigger/bal_new.out deleted file mode 100644 index a58faf07b6..0000000000 --- a/examples/azure-functions-http-trigger/bal_new.out +++ /dev/null @@ -1 +0,0 @@ -$ bal new azure-functions-timer-trigger diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md index 19809f36f4..adfaa79be2 100644 --- a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md @@ -30,8 +30,6 @@ Execute the command below to generate the Azure Functions artifacts. Execute the Azure CLI command given by the compiler to create and publish the functions by replacing the sample app name given in the command with your respective Azure ``. ->**Tip:** For instructions on getting the values, see [Set up the prerequisites](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/#set-up-the-prerequisites). - ## Invoke the function The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.metatags b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.metatags index c10e03f87b..6646778ffd 100644 --- a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.metatags +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.metatags @@ -1,2 +1,2 @@ description: This example demonstrates how a function can be scheduled to execute periodically by the Azure Functions app. -keywords: ballerina, ballerina by example, bbe, aws lambda, timer, trigger +keywords: ballerina, ballerina by example, aws lambda, timer, trigger, serverless, cloud, function as a service diff --git a/examples/index.json b/examples/index.json index 0149b0e29c..d9fef78ae0 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4370,8 +4370,8 @@ "isLearnByExample": false }, { - "name": "HTTP trigger", - "url": "azure-functions-http-trigger", + "name": "HTTP trigger with queue", + "url": "azure-functions-http-trigger-with-queue", "verifyBuild": false, "verifyOutput": false, "disableVerificationReason": "Needs prerequisite condition", From 609cb573c5b0869ba9b819431cc78315c6e54f99 Mon Sep 17 00:00:00 2001 From: praneesha Date: Fri, 7 Jul 2023 15:38:00 +0530 Subject: [PATCH 34/38] Update the Azure hello world description --- .../azure-functions-hello-world.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.md b/examples/azure-functions-hello-world/azure-functions-hello-world.md index a43ab7162c..8ce7bb1c0d 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.md +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.md @@ -2,6 +2,12 @@ This example demonstrates how to write a simple echo function in Azure Functions. +In Ballerina, triggers are represented by listeners. When the `af:HttpListener` gets attached to the service, it implies that the function is an HTTP Trigger. The resource method behaves exactly the same as a service written from `ballerina/http`. It supports `http:Payload` and `http:Header` annotations for parameters. Input binding annotations can be used to annotate parameters to make use of external services in Azure. If no annotations are specified for a parameter, it is identified as a query parameter. + +Output bindings are defined in the return type definition. For services with the `HttpListener` attachment, `HttpOutput` is the default output binding. You can override the default behavior by specifying them explicitly in the return type. + +In the code sample shown above, it has an empty service path and resource path named `hello`. The accessor is `get`. It expects a request with a query parameter for the field name. The required artifact generation and data binding will be handled by the `ballerinax/azure_functions` package automatically. + For more information, see the [Azure deployment guide](https://ballerina.io/learn/run-in-the-cloud/function-as-a-service/azure-functions/). ## Set up the prerequisites @@ -18,8 +24,6 @@ Follow the steps below to write the function. 2. Replace the content of the generated Ballerina file with the content below. ->**Info:** In the code sample shown above, it has an empty service path and resource path named `hello`. The accessor is `get`. It expects a request with a query parameter for the field `name`. The required artifact generation and data binding will be handled by the `ballerinax/azure_functions` package automatically. - ::: code azure-functions-hello-world.bal ::: ## Build the function From c03a76dd5ab647791c696115074a50eacace713e Mon Sep 17 00:00:00 2001 From: praneesha Date: Tue, 11 Jul 2023 13:07:28 +0530 Subject: [PATCH 35/38] Add aggregation BBEs to the FaaS review branch --- examples/aggregation/aggregation.bal | 37 +++++++++++++++++++++++ examples/aggregation/aggregation.md | 21 +++++++++++++ examples/aggregation/aggregation.metatags | 2 ++ examples/aggregation/aggregation.out | 4 +++ 4 files changed, 64 insertions(+) create mode 100644 examples/aggregation/aggregation.bal create mode 100644 examples/aggregation/aggregation.md create mode 100644 examples/aggregation/aggregation.metatags create mode 100644 examples/aggregation/aggregation.out diff --git a/examples/aggregation/aggregation.bal b/examples/aggregation/aggregation.bal new file mode 100644 index 0000000000..c7451256f3 --- /dev/null +++ b/examples/aggregation/aggregation.bal @@ -0,0 +1,37 @@ +import ballerina/io; + +public function main() returns error? { + var orders = [ + {orderId: 1, itemName: "A", price: 23.4, quantity: 2}, + {orderId: 1, itemName: "A", price: 20.4, quantity: 1}, + {orderId: 2, itemName: "B", price: 21.5, quantity: 3}, + {orderId: 1, itemName: "B", price: 21.5, quantity: 3} + ]; + + var items = from var {orderId, itemName} in orders + // The `group by` clause create groups for each `orderId`. + // The `itemName` is a non-grouping key and it becomes a sequence variable. + group by orderId + select [itemName]; + + // List of items per `orderId` + io:println(items); + + var quantities = from var {itemName, quantity} in orders + // The `group by` clause create groups for each `itemName`. + // The `quantity` is a non-grouping key and it becomes a sequence variable. + group by itemName + select {itemName, quantity: sum(quantity)}; + + // List of quantity per item + io:println(quantities); + + var income = from var {price, quantity} in orders + let var totPrice = price*quantity + // The `collect` clause creates a single group and all variables become + // non-grouping keys + collect sum(totPrice); + + // Total Income from orders + io:println(income); +} diff --git a/examples/aggregation/aggregation.md b/examples/aggregation/aggregation.md new file mode 100644 index 0000000000..ff5b269936 --- /dev/null +++ b/examples/aggregation/aggregation.md @@ -0,0 +1,21 @@ +# Aggregation + +The `group by` clause in the query expression can group the elements in a collection. Grouping happens based on the grouping keys provided in `group by` clause. For each group, grouping keys are unique. All other variables other than grouping keys are called non-grouping keys. For each group, non-grouping keys become sequence variables. Those variables can be used as a list or an argument to a rest parameter of a langlib function. + +The `collect` clause collects the collection into one group. All the variables become aggregated variables and those variables can be used as a list or an argument to a rest parameter of a langlib function same as in `group by`. + +::: code aggregation.bal ::: + +::: out aggregation.out ::: + +## Related links +- [Query expressions](/learn/by-example/query-expressions) +- [Let clause in query expression](/learn/by-example/let-clause) +- [Limit clause in query expression](/learn/by-example/limit-clause) +- [Joining iterable objects using query](/learn/by-example/joining-iterable-objects) +- [Querying tables](/learn/by-example/querying-tables) +- [Create maps with query expression](/learn/by-example/create-maps-with-query) +- [Create tables with query expression](/learn/by-example/create-tables-with-query) +- [Create streams with query expression](/learn/by-example/create-streams-with-query) +- [On conflict clause in query expression](/learn/by-example/on-conflict-clause) +- [Nested query expressions](/learn/by-example/nested-query-expressions) diff --git a/examples/aggregation/aggregation.metatags b/examples/aggregation/aggregation.metatags new file mode 100644 index 0000000000..e6146e8607 --- /dev/null +++ b/examples/aggregation/aggregation.metatags @@ -0,0 +1,2 @@ +description: This BBE demonstrates how to group a collection, how to handle non grouping keys. +keywords: ballerina, ballerina by example, bbe, group, non-grouping keys, aggregate, collect diff --git a/examples/aggregation/aggregation.out b/examples/aggregation/aggregation.out new file mode 100644 index 0000000000..2636263ed2 --- /dev/null +++ b/examples/aggregation/aggregation.out @@ -0,0 +1,4 @@ +$ bal run aggregation.bal +[["A","A","B"],["B"]] +[{"itemName":"A","quantity":3},{"itemName":"B","quantity":6}] +196.2 From de6f3e7c3bd6be98d58c412371c26b398d91d46e Mon Sep 17 00:00:00 2001 From: praneesha Date: Wed, 12 Jul 2023 13:51:15 +0530 Subject: [PATCH 36/38] Remove aggregation BBEs --- examples/aggregation/aggregation.bal | 37 ----------------------- examples/aggregation/aggregation.md | 21 ------------- examples/aggregation/aggregation.metatags | 2 -- examples/aggregation/aggregation.out | 4 --- 4 files changed, 64 deletions(-) delete mode 100644 examples/aggregation/aggregation.bal delete mode 100644 examples/aggregation/aggregation.md delete mode 100644 examples/aggregation/aggregation.metatags delete mode 100644 examples/aggregation/aggregation.out diff --git a/examples/aggregation/aggregation.bal b/examples/aggregation/aggregation.bal deleted file mode 100644 index c7451256f3..0000000000 --- a/examples/aggregation/aggregation.bal +++ /dev/null @@ -1,37 +0,0 @@ -import ballerina/io; - -public function main() returns error? { - var orders = [ - {orderId: 1, itemName: "A", price: 23.4, quantity: 2}, - {orderId: 1, itemName: "A", price: 20.4, quantity: 1}, - {orderId: 2, itemName: "B", price: 21.5, quantity: 3}, - {orderId: 1, itemName: "B", price: 21.5, quantity: 3} - ]; - - var items = from var {orderId, itemName} in orders - // The `group by` clause create groups for each `orderId`. - // The `itemName` is a non-grouping key and it becomes a sequence variable. - group by orderId - select [itemName]; - - // List of items per `orderId` - io:println(items); - - var quantities = from var {itemName, quantity} in orders - // The `group by` clause create groups for each `itemName`. - // The `quantity` is a non-grouping key and it becomes a sequence variable. - group by itemName - select {itemName, quantity: sum(quantity)}; - - // List of quantity per item - io:println(quantities); - - var income = from var {price, quantity} in orders - let var totPrice = price*quantity - // The `collect` clause creates a single group and all variables become - // non-grouping keys - collect sum(totPrice); - - // Total Income from orders - io:println(income); -} diff --git a/examples/aggregation/aggregation.md b/examples/aggregation/aggregation.md deleted file mode 100644 index ff5b269936..0000000000 --- a/examples/aggregation/aggregation.md +++ /dev/null @@ -1,21 +0,0 @@ -# Aggregation - -The `group by` clause in the query expression can group the elements in a collection. Grouping happens based on the grouping keys provided in `group by` clause. For each group, grouping keys are unique. All other variables other than grouping keys are called non-grouping keys. For each group, non-grouping keys become sequence variables. Those variables can be used as a list or an argument to a rest parameter of a langlib function. - -The `collect` clause collects the collection into one group. All the variables become aggregated variables and those variables can be used as a list or an argument to a rest parameter of a langlib function same as in `group by`. - -::: code aggregation.bal ::: - -::: out aggregation.out ::: - -## Related links -- [Query expressions](/learn/by-example/query-expressions) -- [Let clause in query expression](/learn/by-example/let-clause) -- [Limit clause in query expression](/learn/by-example/limit-clause) -- [Joining iterable objects using query](/learn/by-example/joining-iterable-objects) -- [Querying tables](/learn/by-example/querying-tables) -- [Create maps with query expression](/learn/by-example/create-maps-with-query) -- [Create tables with query expression](/learn/by-example/create-tables-with-query) -- [Create streams with query expression](/learn/by-example/create-streams-with-query) -- [On conflict clause in query expression](/learn/by-example/on-conflict-clause) -- [Nested query expressions](/learn/by-example/nested-query-expressions) diff --git a/examples/aggregation/aggregation.metatags b/examples/aggregation/aggregation.metatags deleted file mode 100644 index e6146e8607..0000000000 --- a/examples/aggregation/aggregation.metatags +++ /dev/null @@ -1,2 +0,0 @@ -description: This BBE demonstrates how to group a collection, how to handle non grouping keys. -keywords: ballerina, ballerina by example, bbe, group, non-grouping keys, aggregate, collect diff --git a/examples/aggregation/aggregation.out b/examples/aggregation/aggregation.out deleted file mode 100644 index 2636263ed2..0000000000 --- a/examples/aggregation/aggregation.out +++ /dev/null @@ -1,4 +0,0 @@ -$ bal run aggregation.bal -[["A","A","B"],["B"]] -[{"itemName":"A","quantity":3},{"itemName":"B","quantity":6}] -196.2 From 06548962869eed2bb165ec03d1ed14f4cdb3bae1 Mon Sep 17 00:00:00 2001 From: praneesha Date: Wed, 12 Jul 2023 14:44:15 +0530 Subject: [PATCH 37/38] Revert "Remove manually added aggregation BBEs" --- examples/aggregation/aggregation.bal | 37 +++++++++++++++++++ examples/aggregation/aggregation.md | 21 +++++++++++ examples/aggregation/aggregation.metatags | 2 + examples/aggregation/aggregation.out | 4 ++ .../graphql_client_error_handling.md | 2 +- .../graphql_client_security_basic_auth.md | 2 +- .../graphql_client_security_mutual_ssl.md | 2 +- ...ent_security_oauth2_password_grant_type.md | 2 +- ...security_self_signed_jwt_authentication.md | 2 +- .../graphql_client_security_ssl_tls.md | 2 +- examples/graphql-context/graphql_context.md | 2 +- .../graphql_field_interceptors.md | 2 +- .../graphql_file_upload.md | 2 +- examples/graphql-graphiql/graphql_graphiql.md | 4 +- .../graphql_input_constraint_validation.md | 2 +- .../graphql_interceptor_configurations.md | 3 +- ...phql_service_basic_auth_file_user_store.md | 2 +- ...phql_service_basic_auth_ldap_user_store.md | 2 +- .../graphql_service_error_handling.md | 2 +- .../graphql_service_field_object.md | 2 +- .../graphql_service_interceptors.md | 2 +- .../graphql_service_jwt_auth.md | 2 +- .../graphql_service_mutual_ssl.md | 2 +- .../graphql_service_oauth2.md | 2 +- .../graphql_service_ssl_tls.md | 2 +- examples/index.json | 6 +-- ..._pub.client.out => nats_jetstream_pub.out} | 0 gradle.properties | 2 +- 28 files changed, 90 insertions(+), 27 deletions(-) create mode 100644 examples/aggregation/aggregation.bal create mode 100644 examples/aggregation/aggregation.md create mode 100644 examples/aggregation/aggregation.metatags create mode 100644 examples/aggregation/aggregation.out rename examples/nats-jetstream-pub/{nats_jetstream_pub.client.out => nats_jetstream_pub.out} (100%) diff --git a/examples/aggregation/aggregation.bal b/examples/aggregation/aggregation.bal new file mode 100644 index 0000000000..c7451256f3 --- /dev/null +++ b/examples/aggregation/aggregation.bal @@ -0,0 +1,37 @@ +import ballerina/io; + +public function main() returns error? { + var orders = [ + {orderId: 1, itemName: "A", price: 23.4, quantity: 2}, + {orderId: 1, itemName: "A", price: 20.4, quantity: 1}, + {orderId: 2, itemName: "B", price: 21.5, quantity: 3}, + {orderId: 1, itemName: "B", price: 21.5, quantity: 3} + ]; + + var items = from var {orderId, itemName} in orders + // The `group by` clause create groups for each `orderId`. + // The `itemName` is a non-grouping key and it becomes a sequence variable. + group by orderId + select [itemName]; + + // List of items per `orderId` + io:println(items); + + var quantities = from var {itemName, quantity} in orders + // The `group by` clause create groups for each `itemName`. + // The `quantity` is a non-grouping key and it becomes a sequence variable. + group by itemName + select {itemName, quantity: sum(quantity)}; + + // List of quantity per item + io:println(quantities); + + var income = from var {price, quantity} in orders + let var totPrice = price*quantity + // The `collect` clause creates a single group and all variables become + // non-grouping keys + collect sum(totPrice); + + // Total Income from orders + io:println(income); +} diff --git a/examples/aggregation/aggregation.md b/examples/aggregation/aggregation.md new file mode 100644 index 0000000000..ff5b269936 --- /dev/null +++ b/examples/aggregation/aggregation.md @@ -0,0 +1,21 @@ +# Aggregation + +The `group by` clause in the query expression can group the elements in a collection. Grouping happens based on the grouping keys provided in `group by` clause. For each group, grouping keys are unique. All other variables other than grouping keys are called non-grouping keys. For each group, non-grouping keys become sequence variables. Those variables can be used as a list or an argument to a rest parameter of a langlib function. + +The `collect` clause collects the collection into one group. All the variables become aggregated variables and those variables can be used as a list or an argument to a rest parameter of a langlib function same as in `group by`. + +::: code aggregation.bal ::: + +::: out aggregation.out ::: + +## Related links +- [Query expressions](/learn/by-example/query-expressions) +- [Let clause in query expression](/learn/by-example/let-clause) +- [Limit clause in query expression](/learn/by-example/limit-clause) +- [Joining iterable objects using query](/learn/by-example/joining-iterable-objects) +- [Querying tables](/learn/by-example/querying-tables) +- [Create maps with query expression](/learn/by-example/create-maps-with-query) +- [Create tables with query expression](/learn/by-example/create-tables-with-query) +- [Create streams with query expression](/learn/by-example/create-streams-with-query) +- [On conflict clause in query expression](/learn/by-example/on-conflict-clause) +- [Nested query expressions](/learn/by-example/nested-query-expressions) diff --git a/examples/aggregation/aggregation.metatags b/examples/aggregation/aggregation.metatags new file mode 100644 index 0000000000..e6146e8607 --- /dev/null +++ b/examples/aggregation/aggregation.metatags @@ -0,0 +1,2 @@ +description: This BBE demonstrates how to group a collection, how to handle non grouping keys. +keywords: ballerina, ballerina by example, bbe, group, non-grouping keys, aggregate, collect diff --git a/examples/aggregation/aggregation.out b/examples/aggregation/aggregation.out new file mode 100644 index 0000000000..2636263ed2 --- /dev/null +++ b/examples/aggregation/aggregation.out @@ -0,0 +1,4 @@ +$ bal run aggregation.bal +[["A","A","B"],["B"]] +[{"itemName":"A","quantity":3},{"itemName":"B","quantity":6}] +196.2 diff --git a/examples/graphql-client-error-handling/graphql_client_error_handling.md b/examples/graphql-client-error-handling/graphql_client_error_handling.md index 08c312f748..4e48d61c4a 100644 --- a/examples/graphql-client-error-handling/graphql_client_error_handling.md +++ b/examples/graphql-client-error-handling/graphql_client_error_handling.md @@ -13,4 +13,4 @@ Run the client program by executing the following command. ## Related links - [`graphql:ClientError` error - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ClientError) -- [GraphQL client error handling - Specification](/spec/graphql/#63-client-error-handling) +- [GraphQL client error handling - Specification](/spec/graphql/#255-client-error-handling) diff --git a/examples/graphql-client-security-basic-auth/graphql_client_security_basic_auth.md b/examples/graphql-client-security-basic-auth/graphql_client_security_basic_auth.md index f1a8c25e89..19112c40b7 100644 --- a/examples/graphql-client-security-basic-auth/graphql_client_security_basic_auth.md +++ b/examples/graphql-client-security-basic-auth/graphql_client_security_basic_auth.md @@ -14,4 +14,4 @@ Run the client program by executing the following command. ## Related links - [`graphql:CredentialsConfig` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#CredentialsConfig) - [`auth` module - API documentation](https://lib.ballerina.io/ballerina/auth/latest/) -- [GraphQL client basic authentication - Specification](/spec/graphql/#821-basic-authentication) +- [GraphQL client basic authentication - Specification](/spec/graphql/#1221-basic-authentication) diff --git a/examples/graphql-client-security-mutual-ssl/graphql_client_security_mutual_ssl.md b/examples/graphql-client-security-mutual-ssl/graphql_client_security_mutual_ssl.md index 7859100bf6..0787e65790 100644 --- a/examples/graphql-client-security-mutual-ssl/graphql_client_security_mutual_ssl.md +++ b/examples/graphql-client-security-mutual-ssl/graphql_client_security_mutual_ssl.md @@ -13,4 +13,4 @@ Run the client program by executing the following command. ## Related links - [`graphql:ClientSecureSocket` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ClientSecureSocket) -- [GraphQL client mutual SSL - Specification](/spec/graphql/#8322-mutual-ssl) +- [GraphQL client mutual SSL - Specification](/spec/graphql/#12322-mutual-ssl) diff --git a/examples/graphql-client-security-oauth2-password-grant-type/graphql_client_security_oauth2_password_grant_type.md b/examples/graphql-client-security-oauth2-password-grant-type/graphql_client_security_oauth2_password_grant_type.md index eaeac0b2da..efcaca7052 100644 --- a/examples/graphql-client-security-oauth2-password-grant-type/graphql_client_security_oauth2_password_grant_type.md +++ b/examples/graphql-client-security-oauth2-password-grant-type/graphql_client_security_oauth2_password_grant_type.md @@ -14,4 +14,4 @@ Run the client program by executing the command below. ## Related links - [`graphql:OAuth2PasswordGrantConfig` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#OAuth2PasswordGrantConfig) - [`oauth2` module - API documentation](https://lib.ballerina.io/ballerina/oauth2/latest/) -- [GraphQL client OAuth2 password grant type - Specification](/spec/graphql/#8242-password-grant-type) +- [GraphQL client OAuth2 password grant type - Specification](/spec/graphql/#12242-password-grant-type) diff --git a/examples/graphql-client-security-self-signed-jwt-authentication/graphql_client_security_self_signed_jwt_authentication.md b/examples/graphql-client-security-self-signed-jwt-authentication/graphql_client_security_self_signed_jwt_authentication.md index 3aebd64b4a..ad209bb24e 100644 --- a/examples/graphql-client-security-self-signed-jwt-authentication/graphql_client_security_self_signed_jwt_authentication.md +++ b/examples/graphql-client-security-self-signed-jwt-authentication/graphql_client_security_self_signed_jwt_authentication.md @@ -14,4 +14,4 @@ Run the client program by executing the command below. ## Related links - [`graphql:JwtIssuerConfig` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#JwtIssuerConfig) - [`jwt` module - API documentation](https://lib.ballerina.io/ballerina/jwt/latest/) -- [GraphQL client self signed JWT authentication - Specification](/spec/graphql/#823-self-signed-jwt-authentication) +- [GraphQL client self signed JWT authentication - Specification](/spec/graphql/#1223-self-signed-jwt-authentication) diff --git a/examples/graphql-client-security-ssl-tls/graphql_client_security_ssl_tls.md b/examples/graphql-client-security-ssl-tls/graphql_client_security_ssl_tls.md index bcb1192dfe..b7488a2ec7 100644 --- a/examples/graphql-client-security-ssl-tls/graphql_client_security_ssl_tls.md +++ b/examples/graphql-client-security-ssl-tls/graphql_client_security_ssl_tls.md @@ -13,4 +13,4 @@ Run the client program by executing the following command. ## Related links - [`graphql:ClientSecureSocket` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ClientSecureSocket) -- [GraphQL client SSL/TLS - Specification](/spec/graphql/#8311-ssltls) +- [GraphQL client SSL/TLS - Specification](/spec/graphql/#12321-ssltls) diff --git a/examples/graphql-context/graphql_context.md b/examples/graphql-context/graphql_context.md index 5d82991fec..b7d11f47ad 100644 --- a/examples/graphql-context/graphql_context.md +++ b/examples/graphql-context/graphql_context.md @@ -27,4 +27,4 @@ Now, send the same document with the `scope` header value set to `unknown`. This ## Related links - [`graphql:Context` object - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#Context) -- [GraphQL context - Specification](/spec/graphql/#101-context-object) +- [GraphQL context - Specification](/spec/graphql/#8-context-object) diff --git a/examples/graphql-field-interceptors/graphql_field_interceptors.md b/examples/graphql-field-interceptors/graphql_field_interceptors.md index 0677296c23..3a84260756 100644 --- a/examples/graphql-field-interceptors/graphql_field_interceptors.md +++ b/examples/graphql-field-interceptors/graphql_field_interceptors.md @@ -22,4 +22,4 @@ To send the document, execute the following cURL command in a separate terminal. ## Related links - [`graphql:Interceptor` object - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#Interceptor) -- [GraphQL field interceptors - Specification](/spec/graphql/#10332-field-interceptors) +- [GraphQL interceptors - Specification](/spec/graphql/#11-interceptors) diff --git a/examples/graphql-file-upload/graphql_file_upload.md b/examples/graphql-file-upload/graphql_file_upload.md index 068bc0c291..f8024b3b7e 100644 --- a/examples/graphql-file-upload/graphql_file_upload.md +++ b/examples/graphql-file-upload/graphql_file_upload.md @@ -25,4 +25,4 @@ This will create a directory `uploads` where the service is running, and then sa ## Related links - [`graphql:Upload` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#Upload) - [GraphQL multipart request specification](https://github.com/jaydenseric/graphql-multipart-request-spec) -- [GraphQL file upload - Specification](/spec/graphql/#104-file-upload) +- [GraphQL file upload - Specification](/spec/graphql/#6-file-upload) diff --git a/examples/graphql-graphiql/graphql_graphiql.md b/examples/graphql-graphiql/graphql_graphiql.md index 18df839583..c3cbcd939e 100644 --- a/examples/graphql-graphiql/graphql_graphiql.md +++ b/examples/graphql-graphiql/graphql_graphiql.md @@ -17,5 +17,5 @@ To access the GraphiQL client, open a browser and access `http://localhost:9090/ ## Related links - [`graphql:ServiceConfig` annotation - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ServiceConfig) - [`graphql:GraphiQL` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#Graphiql) -- [GraphQL GraphiQL client - Specification](/spec/graphql/#91-graphiql-client) -- [GraphQL GraphiQL client configuration - Specification](/spec/graphql/#715-graphiql-configurations) +- [GraphQL GraphiQL client - Configuration](/spec/graphql/#1015-graphiql-configurations) +- [GraphQL GraphiQL client - Specification](/spec/graphql/#141-graphiql-client) diff --git a/examples/graphql-input-constraint-validation/graphql_input_constraint_validation.md b/examples/graphql-input-constraint-validation/graphql_input_constraint_validation.md index 9e8d83d478..af82c598ba 100644 --- a/examples/graphql-input-constraint-validation/graphql_input_constraint_validation.md +++ b/examples/graphql-input-constraint-validation/graphql_input_constraint_validation.md @@ -20,6 +20,6 @@ To send the document, execute the following cURL command in a separate terminal. ## Related links - [Constraint annotation - API documentation](https://lib.ballerina.io/ballerina/constraint/latest#Annotations) -- [GraphQL constraint config - Specification](/spec/graphql/#1018-constraint-configurations) +- [GraphQL constraint config - API documentation](https://ballerina.io/spec/graphql/#1018-constraint-configurations) - [`constraint` module - API documentation](https://lib.ballerina.io/ballerina/constraint/latest) - [`graphql` module - API documentation](https://lib.ballerina.io/ballerina/graphql/latest) diff --git a/examples/graphql-interceptor-configurations/graphql_interceptor_configurations.md b/examples/graphql-interceptor-configurations/graphql_interceptor_configurations.md index 2b6508c842..8be707e01f 100644 --- a/examples/graphql-interceptor-configurations/graphql_interceptor_configurations.md +++ b/examples/graphql-interceptor-configurations/graphql_interceptor_configurations.md @@ -25,5 +25,4 @@ To send the document, execute the following cURL command in a separate terminal. ## Related links - [`graphql:InterceptorConfig` annotation - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#InterceptorConfig) -- [GraphQL interceptor configuration - Specification](/spec/graphql/#73-interceptor-configuration) -- [GraphQL interceptors - Specification](/spec/graphql/#103-interceptors) +- [GraphQL interceptors - Specification](/spec/graphql/#11-interceptors) diff --git a/examples/graphql-service-basic-auth-file-user-store/graphql_service_basic_auth_file_user_store.md b/examples/graphql-service-basic-auth-file-user-store/graphql_service_basic_auth_file_user_store.md index a327c62154..83cb181695 100644 --- a/examples/graphql-service-basic-auth-file-user-store/graphql_service_basic_auth_file_user_store.md +++ b/examples/graphql-service-basic-auth-file-user-store/graphql_service_basic_auth_file_user_store.md @@ -20,4 +20,4 @@ Run the service by executing the command below. - [`graphql:ServiceConfig` annotation - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ServiceConfig) - [`graphql:FileUserStoreConfigWithScopes` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#FileUserStoreConfigWithScopes) - [`auth` module - API documentation](https://lib.ballerina.io/ballerina/auth/latest/) -- [GraphQL service basic authentication - file user store - Specification](/spec/graphql/#8111-basic-authentication---file-user-store) +- [GraphQL service basic authentication - file user store - Specification](/spec/graphql/#12111-basic-authentication---file-user-store) diff --git a/examples/graphql-service-basic-auth-ldap-user-store/graphql_service_basic_auth_ldap_user_store.md b/examples/graphql-service-basic-auth-ldap-user-store/graphql_service_basic_auth_ldap_user_store.md index 2eba39022a..dec50f0e3c 100644 --- a/examples/graphql-service-basic-auth-ldap-user-store/graphql_service_basic_auth_ldap_user_store.md +++ b/examples/graphql-service-basic-auth-ldap-user-store/graphql_service_basic_auth_ldap_user_store.md @@ -19,4 +19,4 @@ Run the service by executing the command below. - [`graphql:ServiceConfig` annotation - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ServiceConfig) - [`graphql:LdapUserStoreConfigWithScopes` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#LdapUserStoreConfigWithScopes) - [`auth` module - API documentation](https://lib.ballerina.io/ballerina/auth/latest/) -- [GraphQL service basic authentication - LDAP user store - Specification](/spec/graphql/#8112-basic-authentication---ldap-user-store) +- [GraphQL service basic authentication - LDAP user store - Specification](/spec/graphql/#12112-basic-authentication---ldap-user-store) diff --git a/examples/graphql-service-error-handling/graphql_service_error_handling.md b/examples/graphql-service-error-handling/graphql_service_error_handling.md index 286f95a277..06b8962b77 100644 --- a/examples/graphql-service-error-handling/graphql_service_error_handling.md +++ b/examples/graphql-service-error-handling/graphql_service_error_handling.md @@ -32,4 +32,4 @@ Check the response to see how the `data` field is set to null due to propagating ## Related links - [`graphql` module - API documentation](https://lib.ballerina.io/ballerina/graphql/latest) -- [GraphQL error handling - Specification](/spec/graphql/#62-service-error-handling) +- [GraphQL error handling - Specification](/spec/graphql/#72-service-error-handling) diff --git a/examples/graphql-service-field-object/graphql_service_field_object.md b/examples/graphql-service-field-object/graphql_service_field_object.md index 434a5cfbd9..8b7fce5754 100644 --- a/examples/graphql-service-field-object/graphql_service_field_object.md +++ b/examples/graphql-service-field-object/graphql_service_field_object.md @@ -41,4 +41,4 @@ This will print a log message in the server terminal similar to the following lo ## Related links - [`graphql:Field` object - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#Field) -- [GraphQL field - Specification](/spec/graphql/#102-field-object) +- [GraphQL field - Specification](/spec/graphql/#9-field-object) diff --git a/examples/graphql-service-interceptors/graphql_service_interceptors.md b/examples/graphql-service-interceptors/graphql_service_interceptors.md index 34f7aab36e..dc1b207bbc 100644 --- a/examples/graphql-service-interceptors/graphql_service_interceptors.md +++ b/examples/graphql-service-interceptors/graphql_service_interceptors.md @@ -22,4 +22,4 @@ To send the document, execute the following cURL command in a separate terminal. ## Related links - [`graphql:Interceptor` object - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#Interceptor) -- [GraphQL service interceptors - Specification](/spec/graphql/#10331-service-interceptors) +- [GraphQL interceptors - Specification](/spec/graphql/#11-interceptors) diff --git a/examples/graphql-service-jwt-auth/graphql_service_jwt_auth.md b/examples/graphql-service-jwt-auth/graphql_service_jwt_auth.md index afc068d380..2628d12ebe 100644 --- a/examples/graphql-service-jwt-auth/graphql_service_jwt_auth.md +++ b/examples/graphql-service-jwt-auth/graphql_service_jwt_auth.md @@ -14,4 +14,4 @@ Run the service by executing the command below. - [`graphql:ServiceConfig` annotation - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ServiceConfig) - [`graphql:JwtValidatorConfigWithScopes` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#JwtValidatorConfigWithScopes) - [`jwt` module - API documentation](https://lib.ballerina.io/ballerina/jwt/latest/) -- [GraphQL service JWT authentication - Specification](/spec/graphql/#8113-jwt-authentication) +- [GraphQL service JWT authentication - Specification](/spec/graphql/#12113-jwt-authentication) diff --git a/examples/graphql-service-mutual-ssl/graphql_service_mutual_ssl.md b/examples/graphql-service-mutual-ssl/graphql_service_mutual_ssl.md index 4a4fcfc646..d5f3d2b557 100644 --- a/examples/graphql-service-mutual-ssl/graphql_service_mutual_ssl.md +++ b/examples/graphql-service-mutual-ssl/graphql_service_mutual_ssl.md @@ -13,4 +13,4 @@ Run the service by executing the command below. ## Related links - [`graphql:ListenerConfiguration` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ListenerConfiguration) - [`graphql:ListenerSecureSocket` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ListenerSecureSocket) -- [GraphQL service mutual SSL - Specification](/spec/graphql/#8312-mutual-ssl) +- [GraphQL service mutual SSL - Specification](/spec/graphql/#12312-mutual-ssl) diff --git a/examples/graphql-service-oauth2/graphql_service_oauth2.md b/examples/graphql-service-oauth2/graphql_service_oauth2.md index 7c95fb0740..c44981e0a8 100644 --- a/examples/graphql-service-oauth2/graphql_service_oauth2.md +++ b/examples/graphql-service-oauth2/graphql_service_oauth2.md @@ -17,4 +17,4 @@ Run the service by executing the command below. - [`graphql:ServiceConfig` annotation - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ServiceConfig) - [`graphql:OAuth2IntrospectionConfigWithScopes` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#OAuth2IntrospectionConfigWithScopes) - [`oauth2` module - API documentation](https://lib.ballerina.io/ballerina/oauth2/latest/) -- [GraphQL service OAuth2 - Specification](/spec/graphql/#8114-oauth2) +- [GraphQL service OAuth2 - Specification](/spec/graphql/#12114-oauth2) diff --git a/examples/graphql-service-ssl-tls/graphql_service_ssl_tls.md b/examples/graphql-service-ssl-tls/graphql_service_ssl_tls.md index 6c4c2a9363..465c6812ac 100644 --- a/examples/graphql-service-ssl-tls/graphql_service_ssl_tls.md +++ b/examples/graphql-service-ssl-tls/graphql_service_ssl_tls.md @@ -13,4 +13,4 @@ Run the service by executing the command below. ## Related links - [`graphql:ListenerConfiguration` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ListenerConfiguration) - [`graphql:ListenerSecureSocket` record - API documentation](https://lib.ballerina.io/ballerina/graphql/latest#ListenerSecureSocket) -- [GraphQL service SSL/TLS - Specification](/spec/graphql/#8311-ssltls) +- [GraphQL service SSL/TLS - Specification](/spec/graphql/#12311-ssltls) diff --git a/examples/index.json b/examples/index.json index 373b0d84c7..a32bb1f660 100644 --- a/examples/index.json +++ b/examples/index.json @@ -3167,7 +3167,7 @@ "isLearnByExample": false }, { - "name": "Constraint validations", + "name": "Constraint validation", "url": "nats-service-constraint-validation", "verifyBuild": false, "verifyOutput": false, @@ -3177,7 +3177,7 @@ }, { "name": "Consume JetStream message", - "url": "nats-jetstream-sub", + "url": "nats-jestream-sub", "verifyBuild": false, "verifyOutput": false, "disableVerificationReason": "Includes ballerinax components", @@ -3211,7 +3211,7 @@ }, { "name": "Publish message", - "url": "nats-jetstream-pub", + "url": "nats-jestream-pub", "verifyBuild": false, "verifyOutput": false, "disableVerificationReason": "Includes ballerinax components", diff --git a/examples/nats-jetstream-pub/nats_jetstream_pub.client.out b/examples/nats-jetstream-pub/nats_jetstream_pub.out similarity index 100% rename from examples/nats-jetstream-pub/nats_jetstream_pub.client.out rename to examples/nats-jetstream-pub/nats_jetstream_pub.out diff --git a/gradle.properties b/gradle.properties index 38539ac022..e342fb972b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ group=org.ballerinalang version=2201.7.0-SNAPSHOT codeName=swan-lake -ballerinaLangVersion=2201.8.0-20230712-000400-d08328e9 +ballerinaLangVersion=2201.8.0-20230709-001900-fbfe9ee2 ballerinaJreVersion=1.1.0 dependencyJREVersion=jdk-11.0.18+10-jre specVersion=2023R1 From f4256449fb1963cbf597d950db8bf418fd4eb6f4 Mon Sep 17 00:00:00 2001 From: praneesha Date: Wed, 12 Jul 2023 14:44:58 +0530 Subject: [PATCH 38/38] Revert "Add aggregation BBEs to the FaaS review branch" --- examples/aggregation/aggregation.bal | 37 ----------------------- examples/aggregation/aggregation.md | 21 ------------- examples/aggregation/aggregation.metatags | 2 -- examples/aggregation/aggregation.out | 4 --- 4 files changed, 64 deletions(-) delete mode 100644 examples/aggregation/aggregation.bal delete mode 100644 examples/aggregation/aggregation.md delete mode 100644 examples/aggregation/aggregation.metatags delete mode 100644 examples/aggregation/aggregation.out diff --git a/examples/aggregation/aggregation.bal b/examples/aggregation/aggregation.bal deleted file mode 100644 index c7451256f3..0000000000 --- a/examples/aggregation/aggregation.bal +++ /dev/null @@ -1,37 +0,0 @@ -import ballerina/io; - -public function main() returns error? { - var orders = [ - {orderId: 1, itemName: "A", price: 23.4, quantity: 2}, - {orderId: 1, itemName: "A", price: 20.4, quantity: 1}, - {orderId: 2, itemName: "B", price: 21.5, quantity: 3}, - {orderId: 1, itemName: "B", price: 21.5, quantity: 3} - ]; - - var items = from var {orderId, itemName} in orders - // The `group by` clause create groups for each `orderId`. - // The `itemName` is a non-grouping key and it becomes a sequence variable. - group by orderId - select [itemName]; - - // List of items per `orderId` - io:println(items); - - var quantities = from var {itemName, quantity} in orders - // The `group by` clause create groups for each `itemName`. - // The `quantity` is a non-grouping key and it becomes a sequence variable. - group by itemName - select {itemName, quantity: sum(quantity)}; - - // List of quantity per item - io:println(quantities); - - var income = from var {price, quantity} in orders - let var totPrice = price*quantity - // The `collect` clause creates a single group and all variables become - // non-grouping keys - collect sum(totPrice); - - // Total Income from orders - io:println(income); -} diff --git a/examples/aggregation/aggregation.md b/examples/aggregation/aggregation.md deleted file mode 100644 index ff5b269936..0000000000 --- a/examples/aggregation/aggregation.md +++ /dev/null @@ -1,21 +0,0 @@ -# Aggregation - -The `group by` clause in the query expression can group the elements in a collection. Grouping happens based on the grouping keys provided in `group by` clause. For each group, grouping keys are unique. All other variables other than grouping keys are called non-grouping keys. For each group, non-grouping keys become sequence variables. Those variables can be used as a list or an argument to a rest parameter of a langlib function. - -The `collect` clause collects the collection into one group. All the variables become aggregated variables and those variables can be used as a list or an argument to a rest parameter of a langlib function same as in `group by`. - -::: code aggregation.bal ::: - -::: out aggregation.out ::: - -## Related links -- [Query expressions](/learn/by-example/query-expressions) -- [Let clause in query expression](/learn/by-example/let-clause) -- [Limit clause in query expression](/learn/by-example/limit-clause) -- [Joining iterable objects using query](/learn/by-example/joining-iterable-objects) -- [Querying tables](/learn/by-example/querying-tables) -- [Create maps with query expression](/learn/by-example/create-maps-with-query) -- [Create tables with query expression](/learn/by-example/create-tables-with-query) -- [Create streams with query expression](/learn/by-example/create-streams-with-query) -- [On conflict clause in query expression](/learn/by-example/on-conflict-clause) -- [Nested query expressions](/learn/by-example/nested-query-expressions) diff --git a/examples/aggregation/aggregation.metatags b/examples/aggregation/aggregation.metatags deleted file mode 100644 index e6146e8607..0000000000 --- a/examples/aggregation/aggregation.metatags +++ /dev/null @@ -1,2 +0,0 @@ -description: This BBE demonstrates how to group a collection, how to handle non grouping keys. -keywords: ballerina, ballerina by example, bbe, group, non-grouping keys, aggregate, collect diff --git a/examples/aggregation/aggregation.out b/examples/aggregation/aggregation.out deleted file mode 100644 index 2636263ed2..0000000000 --- a/examples/aggregation/aggregation.out +++ /dev/null @@ -1,4 +0,0 @@ -$ bal run aggregation.bal -[["A","A","B"],["B"]] -[{"itemName":"A","quantity":3},{"itemName":"B","quantity":6}] -196.2