Giter VIP home page Giter VIP logo

go-lambda's Introduction

go-lambda

AWS has deprecated go1.x runtime.

This repository contains example lambda handler integration with API gateway. Terraform is used to deploy infrastructure including DNS, SSL Certificates.

Requirements

  • go 1.20
  • zip
  • docker
  • terraform
  • aws cli

Setup (optional)

Docker

Although not require specifically to run go in lambdas, can be useful to avoid compatibility issues when using cgo bindings or third party libraries using cgo such as sqlite3.

  • build docker container for building lambda function binary fully compatible with aws lambda runtime
  • docker build -t lambda-build .

Build

AWS provided.al2 requires executables to be named bootstrap.

  • GOARCH=amd64 GOOS=linux go build -tags lambda.norpc -o ./infrastructure/bootstrap main.go

    • provided.al2 provide a single process architecture and allow running without RPC dependency using -tags lambda.norpc
    • Build without RPC using GOARCH=amd64 GOOS=linux go build -tags lambda.norpc -o ./infrastructure/bootstrap main.go
  • go build -o ./bin/main.local ./cmd/handler/main.go for locally running lambda handler as a cli application.

    • requires manually providing event data from file or hard coded into the main.go file
    • it can be very easy to write a cli interface to read event from path or stdin or wrap in a http server

Deploy

Create a terraform.tfvars file inside infrastructure folder and fill out required variables.

  • Manually deploy function code changes with cli aws lambda update-function-code --function-name go-lambda --zip-file fileb://bootstrap.zip
  • Use terraform to deploy infrastructure changes and function changes terraform apply --auto-approve
    • main.aws_lambda_function.go_lambda.source_code_hash = filebase64sha256("bootstrap.zip") will ensure new builds to redeploy with infrastructure changes.

Optional

Currently, the lambda handler takes in any request method and path. For full utilization of api gateway proxy functionality you can make use of https://github.com/awslabs/aws-lambda-go-api-proxy to run a standard Go http server and adapt api gateway requests to Go requests and vice versa Go responses to api gateway responses

  • Be aware to write lambda aware handlers using the adapters.
  • Optimize for fast startups

Future work

  • add GitHub action to build and deploy changes on main branch merge

go-lambda's People

Contributors

jayjamieson avatar

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.