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

[Master] - Revamp FaaS BBEs #4720

Merged
merged 103 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
a9e8148
Add the FaaS BBE changes
Jul 12, 2023
5b77825
Add the index.json file changes
Jul 12, 2023
f53f740
Merge pull request #4704 from praneesha/add-faas-bbes
Jul 12, 2023
92eecb4
Update aws-lambda-execution-context.bal
Jul 12, 2023
ec506b1
Update aws-lambda-execution-context.bal
Jul 12, 2023
aba7c3c
Update AF Hello World BBE
Jul 13, 2023
6ad47cc
Merge pull request #4706 from praneesha/add-faas-bbes
Jul 13, 2023
5fef737
Update index.json
Jul 13, 2023
0ebe604
Update index.json
Jul 13, 2023
dd10f8e
Update index.json
Jul 13, 2023
aed1e25
Update index.json
Jul 13, 2023
56b3761
Update index.json
Jul 13, 2023
89b6fbe
Update index.json
Jul 13, 2023
57233f8
Update index.json
Jul 13, 2023
f7141c2
Update index.json
Jul 13, 2023
617bba1
Update aws-lambda-execution-context.bal
Jul 13, 2023
a1ae6c5
Update aws-lambda-execution-context.bal
Jul 13, 2023
c16ecec
Update aws-lambda-s3-trigger.bal
Jul 13, 2023
1cbf907
Update aws-lambda-dynamodb-trigger.bal
Jul 13, 2023
d60ead5
Update aws-lambda-hello-world.bal
Jul 13, 2023
44f085f
Update aws-lambda-execution-context.bal
Jul 13, 2023
1237cb3
Update bal_new.out
Jul 13, 2023
a98b1da
Update aws-lambda-execution-context.bal
Jul 13, 2023
24b7a94
Update aws-lambda-s3-trigger.md
Jul 14, 2023
a1deb90
Update aws-lambda-s3-trigger.md
Jul 14, 2023
dab5dde
Update aws-lambda-s3-trigger.md
Jul 14, 2023
e2ec351
Update aws-lambda-s3-trigger.md
Jul 14, 2023
91ede82
Update aws-lambda-s3-trigger.md
Jul 14, 2023
ea82731
Update aws-lambda-s3-trigger.md
Jul 14, 2023
87b9e68
Update aws-lambda-s3-trigger.md
Jul 14, 2023
d697601
Update aws-lambda-s3-trigger.md
Jul 14, 2023
8d2576f
Update aws-lambda-s3-trigger.bal
Jul 14, 2023
e8b3f18
Update aws-lambda-s3-trigger.bal
Jul 14, 2023
340dd24
Update aws-lambda-s3-trigger.bal
Jul 14, 2023
3799993
Update aws-lambda-dynamodb-trigger.bal
Jul 14, 2023
6b87ef2
Update aws-lambda-dynamodb-trigger.md
Jul 14, 2023
869b375
Update aws-lambda-dynamodb-trigger.md
Jul 14, 2023
d1f3e20
Update aws-lambda-dynamodb-trigger.md
Jul 14, 2023
c4e947d
Update aws-lambda-dynamodb-trigger.md
Jul 14, 2023
6b9ca41
Update aws-lambda-s3-trigger.md
Jul 14, 2023
5a318fb
Update azure-functions-hello-world.bal
Jul 14, 2023
b9fe102
Update azure-functions-http-trigger-with-queue.bal
Jul 14, 2023
a1883ad
Update azure-functions-timer-trigger.bal
Jul 14, 2023
44f5b9b
Update azure-functions-cosmosdb-trigger.bal
Jul 14, 2023
0eabb97
Update azure-functions-hello-world.md
Jul 14, 2023
6bb7f22
Update azure-functions-timer-trigger.md
Jul 14, 2023
6157396
Update azure-functions-timer-trigger.bal
Jul 14, 2023
15a7696
Update azure-functions-timer-trigger.bal
Jul 14, 2023
4976599
Update azure-functions-timer-trigger.bal
Jul 14, 2023
159c06d
Update azure-functions-timer-trigger.md
Jul 14, 2023
887a88e
Update azure-functions-timer-trigger.bal
Jul 14, 2023
3803c36
Update azure-functions-timer-trigger.md
Jul 14, 2023
5d81059
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
1edcf4e
Update azure-functions-timer-trigger.md
Jul 14, 2023
5b0fa07
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
7622a01
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
aae886c
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
534a37a
Update azure-functions-hello-world.md
Jul 14, 2023
ce7ea26
Update azure-functions-timer-trigger.md
Jul 14, 2023
2f023fc
Update azure-functions-hello-world.md
Jul 14, 2023
9d5a77c
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
af5efe7
Update azure-functions-cosmosdb-trigger.bal
Jul 14, 2023
024593a
Update azure-functions-cosmosdb-trigger.bal
Jul 14, 2023
ca21e64
Update azure-functions-cosmosdb-trigger.md
Jul 14, 2023
a0084dd
Update azure-functions-cosmosdb-trigger.md
Jul 14, 2023
4f00f8b
Update azure-functions-cosmosdb-trigger.md
Jul 14, 2023
068dde4
Update azure-functions-cosmosdb-trigger.md
Jul 14, 2023
820d5a3
Update azure-functions-cosmosdb-trigger.md
Jul 14, 2023
a72800f
Update azure-functions-cosmosdb-trigger.md
Jul 14, 2023
9499688
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
5f4ab90
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
498f74e
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
b21eedf
Update azure-functions-http-trigger-with-queue.md
Jul 14, 2023
e4be4e5
Update azure-functions-hello-world.bal
Jul 14, 2023
cd57be2
Update azure-functions-timer-trigger.bal
Jul 14, 2023
7f7917d
Update azure-functions-http-trigger-with-queue.bal
Jul 14, 2023
a91653f
Update azure-functions-cosmosdb-trigger.bal
Jul 14, 2023
c400052
Update azure-functions-cosmosdb-trigger.md
Jul 14, 2023
6483b57
Remove the current FaaS BBEs
Jul 17, 2023
af7f713
Remove index.json commit
Jul 17, 2023
80695f9
Add new line at the end of index.json
Jul 17, 2023
4956cf3
Merge pull request #4721 from praneesha/revamp-faas-bbes-local
Jul 17, 2023
c559e88
Address FaaS BBEs review comments
Aug 3, 2023
1f386c5
Fix the AZ helloworld BBE deploy output
Aug 3, 2023
07c199b
Merge pull request #4768 from praneesha/revamp-faas-bbes-local
Aug 3, 2023
fe3ea12
Update examples/aws-lambda-dynamodb-trigger/aws-lambda-dynamodb-trigg…
Aug 4, 2023
954ea46
Add the DynamoDB link in BBE
Aug 4, 2023
7081c08
Merge pull request #4769 from praneesha/revamp-faas-bbes-local
Aug 4, 2023
3613ba9
Add underscore in build command output of FaaS BBEs
Aug 4, 2023
9949bda
Verify Azure Functions BBEs output
Aug 4, 2023
01237a9
Add the bal new command outputs
Aug 4, 2023
7170237
Merge pull request #4770 from praneesha/revamp-faas-bbes-local
Aug 4, 2023
89da92b
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Aug 8, 2023
c220070
Update examples/kubernetes-hello-world/kubernetes-hello-world.md
Aug 8, 2023
e0afab1
Update examples/docker-hello-world/docker-hello-world.md
Aug 8, 2023
53aed2d
Update examples/azure-functions-http-trigger-with-queue/azure-functio…
Aug 8, 2023
4e8e004
Update examples/azure-functions-hello-world/azure-functions-hello-wor…
Aug 8, 2023
414816c
Merge branch 'revamp-faas-bbes' of https://github.com/ballerina-platf…
Aug 8, 2023
51e7462
Add new lines in missing FaaS BBE files
Aug 8, 2023
b10e46d
Add the hyphens in titles
Aug 8, 2023
596aaba
Fix more issues
Aug 8, 2023
d9c6de1
Address more feedback
Aug 8, 2023
9c5cbd1
Merge pull request #4772 from praneesha/revamp-faas-bbes-local
Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions examples/aws-lambda-deployment/aws_deploy.out

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ballerina/io;
import ballerinax/aws.lambda;

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

This example creates a function, which will be executed for each entry added to a database in the [DynamoDB](https://aws.amazon.com/dynamodb/).

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

## Set up the prerequisites

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

## Write the function

Follow the steps below to write the function.

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

::: out bal_new.out :::

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

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

## Build the function

Execute the command below to generate the AWS Lambda artifacts.

::: out bal_build.out :::

## Deploy the function

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

::: out aws_deploy.out :::

## Invoke the function

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

1. In the IAM Console, click the corresponding role in the list, and click **Add permissions**.
2. Select **attach policies** from the drop-down menu, and add the **AWSLambdaDynamoDBExecutionRole** to the role.
3. Go to [DynamoDB](https://console.aws.amazon.com/dynamodbv2), and from the drop-down menu at the top RHS of the screen, select the **AWS region** in which you created the user and role.
4. Click **Create Table**, enter a table name and a partition key, and create the table (if you already have a table created, you can skip this step).
5. Click on the DynamoDB table you created, and then click the **Exports and streams** tab.
6. Click **Turn on** under **DynamoDB stream details**, select **Key attributes only** for the event type, and click **Turn on stream**.
8. Under the **Trigger** section, click **Create trigger**, select the `dynamoDBTrigger` from the drop-down, and click **Create trigger**.
9. Click **Explore table items**, and click **Create items** under the **Items returned** section.
10. Enter a value under the **Attributes** section to add an entry to the DynamoDB table to invoke the Lambda function, and click **Create item**.
11. Click the **Monitor** tab of the Lambda function in the AWS Management Console, and click **View CloudWatch logs** to check the logs via CloudWatch.
11. Under **Log streams** in CloudWatch, click on the topmost stream in the list and verify the object name in the logs.
12. Go to the AWS Lambda function and check the logs via CloudWatch to see the object identifier in the logs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description: This example creates a function, which will be executed for each entry added to a database in the DynamoDB.
keywords: ballerina, ballerina by example, aws lambda, dynamodb, serverless, cloud, function as a service
1 change: 1 addition & 0 deletions examples/aws-lambda-dynamodb-trigger/aws_deploy.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ aws lambda create-function --function-name dynamoDBTrigger --zip-file fileb://aws-ballerina-lambda-functions.zip --handler aws-lambda-dynamodb-trigger.dynamoDBTrigger --runtime provided --role arn:aws:iam::908363916111:role/lambda-role--layers arn:aws:lambda:us-west-1:134633749276:layer:ballerina-jre11:6 --memory-size 512 --timeout 10
12 changes: 12 additions & 0 deletions examples/aws-lambda-dynamodb-trigger/bal_build.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ bal build
Compiling source
wso2/aws_lambda_dynamodb_trigger:0.1.0

Generating executable
@awslambda:Function: dynamoDBTrigger

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

Run the following command to re-deploy an updated Ballerina AWS Lambda function:
aws lambda update-function-code --function-name $FUNCTION_NAME --zip-file fileb://aws-ballerina-lambda-functions.zip
2 changes: 2 additions & 0 deletions examples/aws-lambda-dynamodb-trigger/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ bal new aws_lambda_dynamodb_trigger
Created new package 'aws_lambda_dynamodb_trigger' at /Users/wso2/aws_lambda_dynamodb_trigger.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ballerinax/aws.lambda;

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

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

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

## Set up the prerequisites

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

## Write the function

Follow the steps below to write the function.

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

::: out bal_new.out :::

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

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

## Build the function

Execute the command below to generate the AWS Lambda artifacts.

::: out bal_build.out :::

## Deploy the function

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

::: out aws_deploy.out :::

## Invoke the function

Execute the commands below to invoke the function.

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

Generating executable
@awslambda:Function: ctxinfo

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

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

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

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

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

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

## Set up the prerequisites

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

## Write the function

Follow the steps below to write the function.

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

::: out bal_new.out :::

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

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

## Build the function

Execute the command below to generate the AWS Lambda artifacts.

::: out bal_build.out :::

## Deploy the function

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

::: out aws_deploy.out :::

## Invoke the function

Execute the commands below to invoke the function.

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

Generating executable
@awslambda:Function: echo

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

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

@lambda:Function
public function s3Trigger(lambda:Context ctx,
lambda:S3Event event) returns json {
io:println(event.Records[0].s3.'object.key);
return event.Records[0].s3.'object.key;
}
50 changes: 50 additions & 0 deletions examples/aws-lambda-s3-trigger/aws-lambda-s3-trigger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# AWS Lambda - S3 trigger

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

## Set up the prerequisites

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

## Write the function

Follow the steps below to write the function.

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

::: out bal_new.out :::

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

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

## Build the function

Execute the command below to generate the AWS Lambda artifacts.

::: out bal_build.out :::

## Deploy the function

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

::: out aws_deploy.out :::

## Invoke the function

Follow the instructions below to create an S3 bucket in AWS for invoking this function.

1. Go to the [AWS S3](https://s3.console.aws.amazon.com/s3/) portal and create a bucket.
>**Note:** Make sure to select the same **AWS region** in which you created the AWS user and role when creating the S3 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. Under the **Destination** section, select the AWS Lambda function (i.e., `s3Trigger` in this example) from the dropdown.
5. Select the created bucket under the **Buckets** list, click **Upload**, and upload an object to the S3 bucket.
6. Under the **Functions** list of the AWS Management Console, click the AWS Lambda function, and click the **Monitor** tab.
7. If you get a **Missing permissions** notice at the top, click the **Open the IAM Console** in it.
8. In the IAM Console, click the corresponding role in the list, and click **Add permissions**.
9. Select **attach policies** from the drop-down menu, and add the **AWSLambdaBasicExecutionRole** to the role.
10. Click the **Monitor** tab of the Lambda function in the AWS Management Console, and click **View CloudWatch logs** to check the logs via CloudWatch.
11. Under **Log streams** in CloudWatch, click on the topmost stream in the list and verify the object name in the logs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description: This example creates a function, which will be executed for each object creation in AWS S3.
keywords: ballerina, ballerina by example, aws lambda, s3, trigger, serverless, cloud, function as a service
1 change: 1 addition & 0 deletions examples/aws-lambda-s3-trigger/aws_deploy.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ 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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$ bal build
Compiling source
wso2/aws_lambda_deployment:0.1.0
wso2/aws_lambda_s3_trigger:0.1.0

Generating executable
@awslambda:Function: echo, ctxinfo, 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://<project-dir>/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://<project-dir>/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
2 changes: 2 additions & 0 deletions examples/aws-lambda-s3-trigger/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ bal new aws_lambda_s3_trigger
Created new package 'aws_lambda_s3_trigger' at /Users/wso2/aws_lambda_s3_trigger.
Loading