Skip to content

A golang AWS lambda example with API Gateway Custom Authorizer

Notifications You must be signed in to change notification settings

matteosilv/go-serverless-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A golang AWS lambda example with API Gateway Custom Authorizer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published