Giter VIP home page Giter VIP logo

lambda-eks-integration's Introduction

lambda-eks-integration

Purpose

A simple Lambda that takes its event and send it into a Service in EKS cluster.

The Lambda authenticates to the EKS using IAM role and a ClusterRole defining it permissions. The Service type is ClusterIP, so the Lambda uses the Kubernetes Service proxy API which enables to send HTTP requests without exposing any endpoint.

With such a solution, connecting Kubernetes applications environment into cloud resources cannot be easier. The service is available only within the cluster but still can handle incoming events. The service also doesn't have an Authentication & Authorization layer because it is being taken care of by the cluster.

Note: The Lambda create a proxy channel between the event source and a Kubernetes Service. But it can do any other Kubernetes action as long as it has the right permissions.

Setup

  1. Create a simple HTTP service in your Kubernetes cluster:
kubectl apply -f ./simple-service/simple-service.yml 
  1. Create an IAM role for your Lambda
  2. Add IAM role authentication to the EKS
  3. Add IAM role user cluster permissions
kubectl apply -f ./eks-Lambda/lambda-cluster-role.yml
  1. Create a new Lambda with the IAM role and your code - Using zip or ECR image.
  2. Configure the new Lambda with the following environment variables:
CLUSTER_NAME=YOUR EKS CLUSTER NAME
CLUSTER_REGION=YOUR EKS CLUSTER REGION
SERVICE_NAMESPACE= YOUR K8S SERVICE NAMESPACE
SERVICE_NAME= YOUR K8S SERVICE NAME
SERVICE_PORT= YOUR K8S SERVICE PORT
SERVICE_REQUEST_TIMEOUT= TIMEOUT
SERVICE_REQUEST_METHOD=THE SERVICE EXPOSED METHOD
SERVICE_REQUEST_PATH=THE SERVICE URI

Usage

Test your Lambda with such as event:

{
  "name": "John",
  "age": 24
}

The response should look like:

{
  "lambda_request_id": "12341234-1234-1234-1234-123412341234",
  "lambda_arn": "arn:aws:lambda:YOUR_REGION:YOUR_ACCOUNT:function:YOUR_FUNCTION",
  "status_code": 200,
  "event": {
    "name": "John",
    "age": 24
  },
  "response": {
    "status": 200,
    "data": "{'message':'Hello world from John','event':{'name':'John','age':24}}"
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.