Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Address review comments of FaaS BBEs #4676

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions examples/aws-lambda-hello-world/aws-lambda-hello-world.bal
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 0 additions & 2 deletions examples/aws-lambda-hello-world/aws-lambda-hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/aws-lambda-hello-world/invoke_functions.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ $ aws lambda invoke --function-name echo --payload fileb://input.json echo-respo
"StatusCode": 200
}
$ cat echo-response.txt
{"MESSAGE":"HELLO"}
{"MESSAGE":"HELLO"}
2 changes: 1 addition & 1 deletion examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.bal
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import ballerinax/awslambda;
public function s3Trigger(awslambda:Context ctx,
awslambda:S3Event event) {
io:println(event.Records[0].s3.'object.key);
}
}
2 changes: 0 additions & 2 deletions examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ballerina/log;
import ballerina/io;
import ballerinax/azure_functions as af;

public type DBEntry record {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<function_app_name>`.

>**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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# 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.

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/).

Expand All @@ -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
Expand All @@ -32,8 +36,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 `<function_app_name>`.

>**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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ Syncing triggers...
Functions in bal-bbe:
get-hello - [httpTrigger]
Invoke url: https://bal-bbe.azurewebsites.net/hello

timer - [timerTrigger]
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ service / on new af:HttpListener() {
};
return [httpRes, person.name + " is " + person.age.toString() + " years old."];
}
}
}
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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

Expand All @@ -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 `<function_app_name>`.

>**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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ bal new azure-functions-http-trigger-with-queue
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ $ curl --header "Content-Type: application/json" \
--request POST \
--data '{"name":"Jack","age":21}' \
"https://<function_app_name>.azurewebsites.net/queue"
Jack Added to the Queue!
Jack Added to the Queue!
1 change: 0 additions & 1 deletion examples/azure-functions-http-trigger/bal_new.out

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 `<function_app_name>`.

>**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.
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions examples/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down