Lädt...


🔧 GCP - Create api with Cloud Functions and API Gateway


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Introduction

In this article, we will explore how to create an API using Google Cloud Platform (GCP) Cloud Functions and API Gateway. Cloud Functions allow you to build serverless applications that can scale automatically based on demand. API Gateway is a service that acts as a central point of entry for your API requests, allowing you to handle tasks such as routing, authentication, rate limiting, and more.

By combining these two services, you can create a highly scalable and flexible API that can handle a wide range of use cases.

Prerequisites

Before we get started, make sure you have the following:

  • A GCP working account

Tasks:

There are total3 tasks for this activity
Task 1 - service account creation
Task 2 - cloud function creation
Task 3 - api gateway creation

Task-1: Create 2 Service Account

Let's create two service accounts.

  1. For Cloud function - backend-function
  2. For api-gateway - api-gateway
  • Go to iam -> Service Accounts -> +CREATE SERVICE ACCOUNT

backend-function service account

api-gateway service account

  • copy the email generated for api-gateway service account

Task-2: Create Cloud function

  • Go to - Cloud Functions -> +CREATE FUNCTION

create cloud function

  • choose backend-function service account

backend-function service account

  • Leave all other function details to default -

use default nodejs function

  • Now, Deploy the function
  • After this, a function will be deployed

deployed function

Change the permission for cloud function

  • add principal
    add  principal for cloud function

  • give the permission to api-gateway account for function invocation.

Permission for api gateway

givining the invocation access for cloud function

  • Save it and policy will be updated and it will look like below image

CF policy update

Task-3: Create Api-Gateway

  • Get the address from cloud function from trigger section

Get the address from cloud function

  • make api-spec file and change the address value which is found in above step
swagger: '2.0'
info:
  title: test-name-spec
  description: Sample API on API Gateway with a Google Cloud Functions backend
  version: 1.0.0
schemes:
  - https
produces:
  - application/json
paths:
  /hello:
    get:
      summary: Greet a user
      operationId: hello
      x-google-backend:
        address: https://us-central1-qwiklabs-gcp-03-3b06fe0404f2.cloudfunctions.net/cloud-backend-function
      responses:
        '200':
          description: A successful response
          schema:
            type: string
  • Create the gateway with above file and add the details similar to given screenshot

Create api-gateway screenshot

  • Wait for the API Gateway to be created, it will look like this after completion

After api gateway created

  • Go to newly created api-gateway and get the URL for api gateway from gateways tab

api gateway url

  • add hello after the given url and we will be able to access the api like this

api-gateway api working

...

🔧 Pratical Differences between GCP Cloud Functions and AWS Lambda Functions


📈 43.3 Punkte
🔧 Programmierung

🔧 Diferenças práticas entre GCP Cloud Functions e AWS Lambda Functions


📈 41.68 Punkte
🔧 Programmierung

🔧 Functions of Commercial Bank: Primary Functions and Secondary Functions


📈 32.9 Punkte
🔧 Programmierung

🔧 GCP Cloud Functions Gen 2


📈 31.25 Punkte
🔧 Programmierung

🔧 Serverless on GCP using Cloud Functions


📈 31.25 Punkte
🔧 Programmierung

🔧 Seamless API Management: Optimizing Spring Cloud Gateway with AWS API Gateway


📈 30.51 Punkte
🔧 Programmierung

🔧 Choosing the Right API Gateway: Pricing Models for Amazon API Gateway, Apigee, Kong, and Apache APISIX


📈 28.33 Punkte
🔧 Programmierung

📰 Und Microsoft so: Cloud, Cloud, Cloud, Cloud, Cloud, Cloud, Cloud


📈 26.55 Punkte
📰 IT Security Nachrichten

🔧 GCP for beginners 2024: Build a simple web app with Cloud Run and Cloud Build through terminal


📈 26.23 Punkte
🔧 Programmierung

🔧 GCP Cloud Digital Leader certification versus the AWS Cloud Practitioner, and are they worth it?


📈 26.23 Punkte
🔧 Programmierung

🔧 AWS: Integrating OpenAPI With the Amazon API Gateway and Lambda Functions


📈 25.4 Punkte
🔧 Programmierung

🔧 Serverless Functions with AWS Lambda and Strapi: API Gateway Integration


📈 25.4 Punkte
🔧 Programmierung

📰 How an Attacker Can Achieve Persistence in Google Cloud Platform (GCP) with Cloud Shell


📈 24.62 Punkte
📰 IT Security Nachrichten

📰 How to Connect to GCP Cloud SQL with Cloud SQL Auth Proxy in Docker


📈 24.62 Punkte
🔧 AI Nachrichten

🔧 Multi-Cloud Strategy: Pros and Cons of Using AWS, Azure, and GCP Together


📈 24.05 Punkte
🔧 Programmierung

🔧 Multi-Cloud Strategy: Pros and Cons of Using AWS, Azure, and GCP Together


📈 24.05 Punkte
🔧 Programmierung

🔧 Async Integration with Step Functions from API Gateway via CDK


📈 23.79 Punkte
🔧 Programmierung

🔧 Deploying AWS Lambda Functions with API Gateway to DynamoDB using AWS SAM on LocalStack


📈 23.79 Punkte
🔧 Programmierung

🔧 Durable Functions 2.0 - Serverless Actors, Orchestrations, and Stateful Functions


📈 22.47 Punkte
🔧 Programmierung

🔧 The difference between Arrow functions and Normal functions in JavaScript


📈 22.47 Punkte
🔧 Programmierung

🔧 7 Differences Between Arrow Functions and Traditional Functions


📈 22.47 Punkte
🔧 Programmierung

🔧 First-Class Functions, Higher-Order Functions, and Closures in Python – Explained with Code Examples


📈 22.47 Punkte
🔧 Programmierung

🔧 Why the "this" Keyword Behaves Differently in Regular Functions and Arrow Functions


📈 22.47 Punkte
🔧 Programmierung

🔧 Draft: What are the differences between arrow functions and traditional functions?


📈 22.47 Punkte
🔧 Programmierung

🔧 UNDERSTANDING THE TRANSFER OF ETHER FUNCTIONS :call,send and transfer functions


📈 22.47 Punkte
🔧 Programmierung

🔧 🚀 JavaScript Functions: Arrow Functions, Callbacks, and Closures 📜


📈 22.47 Punkte
🔧 Programmierung

📰 Cloud Data Exfiltration via GCP Storage Buckets and How to Prevent It


📈 22.44 Punkte
📰 IT Security Nachrichten

📰 Cloud forensics – An introduction to investigating security incidents in AWS, Azure and GCP


📈 22.44 Punkte
📰 IT Security Nachrichten

matomo