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.
Install Terraform, Go, and the AWS Command Line Interface.
On macOS you can use Homebrew:
$ brew install go terraform awscli
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.
Clean generated lambda functions go binaries
make clean
Generate lambda functions go binaries
make build
Initialize terraform
make init
Review terraform changes that will be applied to the infrastructure
make plan
Deploy the infrastructure to your aws account
make apply
Destroy the infrastructure
make destroy
Use the URL in the tasks_api_url
terraform output to test your api
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.