0

As we know we have some major Fass providers like AWS Lambda, Google Cloud Functions, and Microsoft Azure Functions. each has its own SDK to develop the FaaS functions. is there any way(or SDK) to write a function in plain JAVA and run it on any of the FaaS Providers?

I am aware of how to write the functions in AWS Lambda, Google Cloud Functions, and Microsoft Azure Functions individually but I need to write a common function that can run in any of the FaaS providers.

1 Answers1

1

You can write the Java Azure Function where you have to modify the Cloud Services Connectivity and Code accordingly. Then you can upload this code to the GitHub Repository. And then Use the Terraform script with the required cloud provider for deploying the Function as a Service with the code from the Git Repo.

Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs

terraform {
required_providers {
azurerm =  {
source = "hashicorp/azurerm"
version = "3.48.0"
        }
    }
}
  

provider  "azurerm" {
tenant_id =  "<Your_Azure_Tenant_Id>"
subscription_id =  "<Your_Azure_Subscription_Id>"
client_id =  "<Your_Azure_Client_Id"
client_secret =  "<Secret Value from App Registration>"
features {
}
}

resource  "azurerm_resource_group"  "example" {
name =  "HariTestRG"
location =  "East US"
}

resource  "azurerm_storage_account"  "example" {
name =  "haritestrg9f8c"
resource_group_name =  azurerm_resource_group.example.name
location =  azurerm_resource_group.example.location
account_tier =  "Standard"
account_replication_type =  "LRS"
account_kind =  "StorageV2"

tags =  {
environment = "staging"
}
}

resource  "azurerm_windows_function_app"  "example" {
name =  "KrishFunApp05"
resource_group_name =  azurerm_resource_group.example.name
location =  azurerm_resource_group.example.location
  
storage_account_name =  azurerm_storage_account.example.name
storage_account_access_key =  azurerm_storage_account.example.primary_access_key
service_plan_id =  azurerm_service_plan.example.id

site_config {}
}

resource  "azurerm_app_service_source_control"  "example" {
app_id =  azurerm_windows_function_app.example.id
repo_url =  "https://github.com/Azure-Samples/python-docs-hello-world"
branch =  "master"
}

resource  "azurerm_source_control_token"  "example" {

type =  "GitHub"
token =  "<Your_Personal_Access_Token>"
}

resource  "azurerm_service_plan"  "example" {
name =  "ASP-HariTestRG-bb64"
location =  azurerm_resource_group.example.location
resource_group_name =  azurerm_resource_group.example.name
os_type =  "Windows"
sku_name =  "Y1"
}

enter image description here

You can use the Cloud Providers script provided by hasicorp in the terraform for provisioning and deploying the infrastructure for our applications like Web Apps, APIs, Functions, etc and deploying using the code repositories such as GitHub, etc.

  • This answer appears to deal only with Azure. How does it address the question asker's concerns regarding being able to deploy the same code to all existing FaaS providers (or all existing and all future providers, depending on how we interpret the question)? – Matt Welke May 30 '23 at 17:25
  • You can change the azurerm modules to other cloud providers modules which has function app feature such as lambda in aws. –  Jun 02 '23 at 11:57