GithubHelp home page GithubHelp logo

matteosilv / go-serverless-demo Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 28 KB

A golang AWS lambda example with API Gateway Custom Authorizer

Makefile 1.25% Go 25.31% HCL 41.78% JavaScript 31.65%

go-serverless-demo's Introduction

Golang serverless demo

A demo of a serverless application backed by an AWS Lambda function written in Go.

The Tasks lambda function consists of two endpoints:

  • GET: list created tasks
  • POST: create new tasks

An example of task record is:

{
    "name": "task",
    "description": "a task"
}

Tasks are stored in a AWS DynamoDB table.

The lambda function is served via AWS API Gateway and the POST endpoint is authorized via the Auth Custom Authorizer written in Go that recognizes only the hardcoded user admin via HTTP Basic Authentication.

Logs are stored in CloudWatch and streamed to an AWS ElasticSearch domain through a Subscription Filter.

The whole infrastructure can be deployed using Terraform.

Prerequisites

Terraform and Go

Install Terraform, Go, and the AWS Command Line Interface.

On macOS you can use Homebrew:

$ brew install go terraform awscli

AWS credentials

Use aws configure command or just create a configuration file ~/.aws/credentials:

[default]
aws_access_key_id = KEY
aws_secret_access_key = KEY

You will need to create the access key id and the secret access key in the AWS console.

Usage

Clean

Clean generated lambda functions go binaries

make clean

Build

Generate lambda functions go binaries

make build

Initialize terraform

Initialize terraform

make init

Review terraform plan

Review terraform changes that will be applied to the infrastructure

make plan

Create the infrastructure

Deploy the infrastructure to your aws account

make apply

Destroy the infrastructure

Destroy the infrastructure

make destroy

Test the api

Use the URL in the tasks_api_url terraform output to test your api

Browse elastic search index

Use the URLs in the elasticsearch_kibana_url and elasticsearch_url to search logs streamed to elasticsearch domain via Kibana or ElasticSearch APIs.

Your public ip should be authorized to access via HTTP ElasticSearch and Kibana thanks to an access policy deployed through Terraform.

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.