Multi-Cloud Serverless Application with Authentication

Introduction

This project demonstrates how to deploy a Multi-Cloud Serverless Application using AWS Lambda, Azure Functions, and Google Cloud Functions, each secured with an authentication mechanism. By using serverless services across multiple providers, we can:


  • Scale effortlessly: Each provider automatically scales based on incoming requests.
  • Save costs: We operate within the free tiers, paying nothing as long as usage stays within those limits.
  • Enhance flexibility: Leveraging different clouds can help meet diverse compliance or latency needs.
  • Learn cross-platform skills: Mastering multiple cloud providers can open opportunities in various environments.


Why is it useful? Because a multi-cloud approach provides redundancy and portability, ensuring you are not locked to a single provider. Additionally, implementing a centralized authentication layer (e.g., Amazon Cognito, Azure AD B2C, or Google Identity) offers secure access control for users on all clouds.

Prerequisites

Required Tools & Accounts

AWS Account (Free Tier)
Services needed: AWS Lambda, Amazon Cognito (if you choose Cognito as your auth provider).
Make sure you have the necessary permissions (Owner or Editor) on your AWS account.


Azure Account (Free Tier)
Services needed: Azure Functions, Azure AD B2C (if you choose Azure AD B2C).
Sufficient permissions to create Functions, B2C tenants, etc.


Google Cloud Account (Free Tier)
Services needed: Google Cloud Functions, Google Identity Platform (if you choose Google Identity).
Owner or Editor role on the Google Cloud project.


Installed CLI Tools
AWS CLI
Azure CLI
+ Azure Functions Core Tools
Google Cloud SDK
(which includes the gcloud CLI)


Enabled APIs
AWS: Lambda, Cognito (if using Cognito)
Azure: Azure Functions, Azure AD B2C (if using B2C)
Google Cloud: Cloud Functions, Identity Platform (if using Google Identity)


Tip: Be sure you stay within free-tier usage on each cloud to avoid incurring charges.

Step-by-Step Implementation

Below are the steps to deploy a simple “Hello World” serverless function on each cloud with optional authentication. We provide both Console (GUI) steps and Command-Line Interface (CLI) commands—together so that you can perform and automate each step. For every CLI command, we also explain its function.


You can choose any single identity provider for authentication or integrate multiple. For brevity, we assume we will use Amazon Cognito in these steps as an example. The process is similar for Azure AD B2C or Google Identity.


AWS Lambda

Manual (AWS Management Console)

Go to the AWS Lambda Console
Navigate to AWS Lambda Console.


Create a new function
Click “Create function.”
Select Author from scratch, give it a name (e.g., multi-cloud-aws-function), choose runtime (e.g., Python 3.x or Node.js).
Click “Create function.”


Configure the function code
In the inline code editor, add a simple “Hello World” response.
Click “Deploy.”


Test the function
Create a test event and invoke the function.

CLI (AWS CLI)

Below is an example using Python. Adjust accordingly if using another language.

Create a deployment package :zip function.zip lambda_function.py

Explanation: This command zips your Python file (lambda_function.py) into a package named function.zip for deployment.

Create the Lambda function : aws lambda create-function \ --function-name multi-cloud-aws-function \ --zip-file fileb://function.zip \ --handler lambda_function.lambda_handler \ --runtime python3.9 \ --role arn:aws:iam::123456789012:role/lambda-execution-role

Explanation : --function-name: The name of the new Lambda function. --zip-file: Points to your zipped code. --handler: The entry point in your code (lambda_function.lambda_handler). --runtime: The runtime environment, e.g., python3.9. --role: The IAM role with permissions for Lambda. This must be a valid ARN from your account.

Invoke the function aws lambda invoke \ --function-name multi-cloud-aws-function \ --payload '{}' \ output.json

Explanation: Invokes the function with an empty JSON payload. The result is saved into output.json.

Azure Functions :

Manual (Azure Portal)
Navigate to Azure Portal.
Search for “Function App.”


Create a new Function App :
Click “Create.”
Fill in the details: subscription, resource group, function app name (e.g., multi-cloud-azure-function), runtime stack, region.
Click “Create” to provision.


Add a new function :
Once deployment finishes, open your Function App and add a function (e.g., HTTP trigger).

Code editing :
Use the in-portal editor or deploy from VS Code / local. Provide a “Hello World” response in the HTTP trigger.

Test the function :
Use the “Test/Run” option in the Azure Portal.

CLI (Azure CLI + Azure Functions Core Tools) :

Create a new Azure Function project :func init multi-cloud-azure-function --python

Explanation: This initializes a new Azure Functions project named multi-cloud-azure-function using Python.

Create an HTTP trigger function : cd multi-cloud-azure-function func new --name MyHttpTrigger --template "HTTP trigger"

Explanation: Adds a new function named MyHttpTrigger using the HTTP trigger template.

Test locally : func start

Explanation: Spins up a local Azure Functions runtime so you can hit the function endpoint from a local browser or tool.

Login to Azure : az login

Explanation: Authenticates your local CLI with Azure.

Create a Function App in Azure :

az functionapp create \

--resource-group MyResourceGroup \

--consumption-plan-location westus \

--name multi-cloud-azure-function \

--runtime python

Explanation: Creates a Function App on a consumption plan (always staying within the free tier for certain usage).


Deploy to Azure :

func azure functionapp publish multi-cloud-azure-function

Explanation: Uploads your local function code to the specified Function App in Azure.

Google Cloud Functions

Go to the Google Cloud Console:Navigate to Google Cloud Console.

Create a new function Click “Navigation Menu” → “Cloud Functions” → “Create function.” Specify a name, region, runtime (e.g., Python 3.x), and trigger (HTTP).

Add code:Paste your “Hello World” code in the inline editor or link to a repository. Click “Create.”

Test the function:Once deployed, click “Trigger” URL to test in a new tab.

CLI (gcloud CLI)

Initialize your GCP project:gcloud init

Explanation: Guides you through selecting or creating a Google Cloud project and authenticating your CLI session.

Deploy the function:gcloud functions deploy multi-cloud-gcf-function \ --entry-point hello_world \ --runtime python39 \ --trigger-http \ --allow-unauthenticated

Explanation:

  • --entry-point: The Python function name to be executed (e.g., hello_world).

  • --runtime: The language runtime, here python39.

  • --trigger-http: Exposes the function via an HTTP endpoint.

  • --allow-unauthenticated: Lets anyone access the URL (or you can restrict this via IAM if you prefer authentication).

Authentication Setup (Example with Amazon Cognito)

If you want to integrate authentication (Cognito for AWS as an example):

Create a Cognito User Pool:
AWS Console → Amazon Cognito → Manage User Pools → “Create a user pool.”
Configure sign-up and security settings.

Integrate Cognito with Lambda:
Under “Triggers” in your user pool, you could link to your Lambda function for pre-sign-up or post-auth actions.
For a simple authentication flow, you can also protect an API Gateway with Cognito Authorizer and link that to your Lambda.

(Repeat a similar setup if you prefer Azure AD B2C or Google Identity. Each has a similar flow: create an identity resource, configure sign-in policies, link to your function’s endpoint or gateway.)

Verifying and Testing the Project

  • Invoke Each Cloud Function AWS Lambda: Test via console or CLI. Confirm status code 200 and “Hello World” text. Azure Functions: Copy the function URL, paste in a browser or use curl. Confirm the output. Google Cloud Functions: Click “Trigger” URL to see “Hello World.”

  • Check Authentication (if configured) Attempt to call a protected endpoint without a valid token (should fail). Acquire a valid token from Cognito / AD B2C / Google Identity, then call again (should succeed).

  • Verify Logs Each provider (CloudWatch for AWS, Monitor for Azure, Cloud Logging for GCP) should show entries for successful invocations.

Common Issues and Troubleshooting

  • Permission Errors
    Symptom
    : CLI commands fail due to insufficient permissions.
    Fix: Ensure your IAM user/role on AWS, Azure, or GCP has the “Owner” or “Editor” role or the specific function creation permissions.
  • Function Deployment Failures
    Symptom
    : Deployment fails with an error about the runtime or missing files.
    Fix: Check that your runtime in the console or CLI matches your code files. Confirm that your entry point is correct.
  • Authentication Problems
    Symptom
    : Calls to your function fail with an unauthorized or token error.
    Fix: Ensure your token is valid and that the function (or attached gateway) is properly configured with the identity provider.
  • Exceeding Free Tier Limits
    Symptom
    : Unexpected charges or deployment blocked.
    Fix: Check usage dashboards on each platform. Stay within free usage quotas (e.g., 1M requests/month).

Conclusion

We have successfully deployed serverless functions across AWS Lambda, Azure Functions, and Google Cloud Functions, each capable of running within the free tier. We also explored how to set up authentication with services like Amazon Cognito (or similarly Azure AD B2C / Google Identity) to protect our application endpoints. By going multi-cloud, we gain flexibility, improved reliability, and broader expertise. We also learned how to test our functions, verify logs, and troubleshoot common issues.


What is Cloud Computing ?

Cloud computing delivers computing resources (servers, storage, databases, networking, and software) over the internet, allowing businesses to scale and pay only for what they use, eliminating the need for physical infrastructure.


  • AWS: The most popular cloud platform, offering scalable compute, storage, AI/ML, and networking services.
  • Azure: A strong enterprise cloud with hybrid capabilities and deep Microsoft product integration.
  • Google Cloud (GCP): Known for data analytics, machine learning, and open-source support.