lambdacompat

package module
v0.0.0-...-c83890d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

README

Lambda compatibility tools for Cloud Run

The Lambda compatibility tools for Cloud Run consist of two programs to facilitate running of unmodified Lambda serverless function on Google Cloud's Cloud Run: lambda-build and lambda-compat

  • lambda-build: reads the template.yaml format of Serverless Application Model and outputs Dockerfiles for serverless functions and associated Terraform scripts to deploy them.
  • lambda-compat: emulates the Lambda Runtime API and relays the results via standard HTTP protocol responses. It also supports automatically calling AssumeRoleWithWebIdentity using OIDC token retrieved from the GCP metadata endpoint and passing the resulting session token to the Lambda function.

Building

Build requires at least Go 1.16. To install the tools, run:

# go install github.com/GoogleCloudPlatform/professional-services/tools/lambda-compat/cmd/lambda-compat
# go install github.com/GoogleCloudPlatform/professional-services/tools/lambda-compat/cmd/lambda-build

The binaries should now be in $GOPATH/bin.

Usage

You can deploy a sample function

# git clone https://github.com/serverless-projects/aws-sam-examples.git
# cd aws-sam-examples/samples_1/hello-world/python/
# export PROJECT_ID=<YOUR-GCP-PROJECT>
# gcloud services enable artifactregistry.googleapis.com
# gcloud artifacts repositories create lambdafunctions --repository-format=docker --location=europe
Create request issued for: [lambdafunctions]
Created repository [lambdafunctions].
# 
# lambda-build -registry europe-docker.pkg.dev/$PROJECT_ID/lambdafunctions -tag v1 template.yaml
10:27AM INF Lambda compatibility tool for Cloud Run
10:27AM INF Processing SAM template file file=template.yaml
10:27AM INF Creating Dockerfile file file=HelloWorldFunction/Dockerfile template=python.tpl
10:27AM INF To build container, run:
10:27AM INF   docker build -t europe-docker.pkg.dev/<YOUR-GCP-PROJECT>/lambdafunctions/v1:HelloWorldFunction -f HelloWorldFunction/Dockerfile .
10:27AM INF Creating Terraform file file=HelloWorldFunction/main.tf template=terraform_main.tf.tpl
10:27AM INF Creating Terraform file file=HelloWorldFunction/outputs.tf template=terraform_outputs.tf.tpl
10:27AM INF Creating Terraform file file=HelloWorldFunction/variables.tf template=terraform_variables.tf.tpl
10:27AM INF Creating Terraform file file=HelloWorldFunction/versions.tf template=terraform_versions.tf.tpl# cd HelloWorldFunction/
# docker build -t europe-docker.pkg.dev/<YOUR-GCP-PROJECT>/lambdafunctions/v1:HelloWorldFunction -f HelloWorldFunction/Dockerfile .
Sending build context to Docker daemon  160.8MB
# 
# echo "project_id=\"$PROJECT_ID\"" > terraform.tfvars
# terraform init
# terraform apply

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LambdaCompat

type LambdaCompat interface {
	Start() error
}

type LambdaCompatCommand

type LambdaCompatCommand struct {
	Context     context.Context
	Command     string
	Args        []string
	Environment []string
}

func (LambdaCompatCommand) Run

type LambdaCompatHandler

type LambdaCompatHandler struct {
	// contains filtered or unexported fields
}

func (LambdaCompatHandler) ServeHTTP

func (h LambdaCompatHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LambdaCompatServer

type LambdaCompatServer struct {
	Command []string

	Region        string
	ProjectNumber string
	Service       string
	Audience      string
	RoleArn       string

	Processing sync.Mutex
	// contains filtered or unexported fields
}

func NewLambdaCompatServer

func NewLambdaCompatServer(command []string, port int, region string, projectNum string, service string, audience string, roleArn string) *LambdaCompatServer

func (LambdaCompatServer) Start

func (s LambdaCompatServer) Start() error

type LambdaErrorHandler

type LambdaErrorHandler struct {
	// contains filtered or unexported fields
}

func (LambdaErrorHandler) ServeHTTP

func (h LambdaErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LambdaRequest

type LambdaRequest struct {
	RequestId string
	Body      []byte
	Result    chan LambdaResponse
}

type LambdaResponse

type LambdaResponse struct {
	Result []byte
	Error  error
}

type LambdaRestartError

type LambdaRestartError struct{}

func (*LambdaRestartError) Error

func (m *LambdaRestartError) Error() string

type LambdaRunHandler

type LambdaRunHandler struct {
	// contains filtered or unexported fields
}

func (LambdaRunHandler) ServeHTTP

func (h LambdaRunHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL