aws-lambdagoogle-cloud-functionsazure-functionsopenfaasfaas

How to create Common Faas function to run on all Faas Providers


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.


Solution

  • 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.