An implementation of a simple RESTful API in Golang on AWS infrastructure.

go-api

An implementation of a simple RESTful API in Golang on AWS infrastructure.

Tech Stack

Installation

Make sure you've got Golang, aws-cli, node.js and serverless installed.

For instructions regarding aws-cli installation, check this link on AWS docs.

You may also find ways to install node.js on this link. Serverless framework requires node.js to work.

Assuming you've got node.js and it's dependency manager, npm installed; install Serverless framework using the command below. (Open up a Terminal if you use macOS or GNU/Linux, else try WIN + R and type CMD to open a command Prompt and then enter these commands!)

  npm i -g serverless

This will install Serverless globally. Next step is to configure your aws-cli.

Use below command to start the configuration process:

  aws configure

Input the requested values accordingly. These are the private data regarding your AWS account.

Congratulations!

Scripts

I've provided some easy-to-use scripts for build, test, deploy and clean processes; as well as a Makefile for unix-like OS users. (Since GNU/make is not available on Windows)

Assuming you have a Terminal/Command Prompt open and located to the project root path, change directory to scripts where all the scripts are located.

  cd scripts
  • Build

    Windows: .\build

    Unix-like: make build

    Alternative command:

      env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o ../bin/ ../src/handlers/...

    Will build the source code using go build for linux and amd64 architecture.

  • Test

    Windows: .\test

    Unix-like: make test

    Runs unit testing (using *_test.go files) and stores results in tests directory. Will open Go coverage report in the default web browser on Windows.

  • Clean

    Windows: .\clean

    Unix-like: make clean

    Alternative command:

      rm -rf ../bin ../tests/*

    Clears bin directory and test results located at tests directory.

  • Deploy

    Windows: .\deploy

    Unix-like: make deploy

    Alternative command:

      cd .. && serverless deploy --verbose

    Will handle deployment to AWS using Serverless framework.

Test Results

Handlers (Lambda functions):

  • src/addDevice/addDevice.go

    PASSED with 95.1% coverage of statements.

  • src/getDeviceById/getDeviceById.go

    PASSED with 91.5% coverage of statements.

  • Tests do not cover inner AWS functions like lambda.Start() and session.NewSession()

Demo

• Currently serving on dev stage. You may change stage name and region in serverless.yml file.

API Endpoints:

$ curl --location --request POST 'https://vssb3ixb3j.execute-api.us-west-1.amazonaws.com/dev/devices' --header 'Content-Type: application/json' --data-raw '{"id": "/devices/id1","deviceModel": "/devicemodels/id1","name": "Sensor","note": "Testing a sensor.","serial": "A020000102"}'

{"message":"Device successfully added to DynamoDB","statusCode":201}
$ curl --location --request GET 'https://vssb3ixb3j.execute-api.us-west-1.amazonaws.com/dev/devices/id1'

{
	"data": {
		"id": "id1",
		"deviceModel": "/devicemodels/id1",
		"name": "Sensor",
		"note": "Testing a sensor.",
		"serial": "A020000102"
	}
}
Similar Resources

Aws-parameter-bulk - Export AWS SSM Parameter Store values in bulk to .env files

aws-parameter-bulk Utility to read parameters from AWS Systems Manager (SSM) Par

Oct 18, 2022

Aws-cognito-demo-go - Source code for AWS Cognito in Go

AWS Cognito Demo in Go Source code for YouTube series, AWS Cognito in Go - https

Dec 10, 2022

API client/backend for Moody's infrastructure

MoodyAPI API client/back-end for Moody's infrastructure The API back-end currently provides: DDNS Records Maintenance. Surveillance Camera Notificatio

Dec 14, 2022

A simple implementation to upload file to AWS S3

A simple implementation to upload file to AWS S3.

Nov 19, 2021

Simple-Weather-API - Simple weather api app created using golang and Open Weather API key

Simple-Weather-API - Simple weather api app created using golang and Open Weather API key

Simple Weather API Simple weather api app created using golang and Open Weather

Feb 6, 2022

lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin to AWS Lambda and Amazon API Gateway.

aws-lambda-go-api-proxy makes it easy to run Golang APIs written with frameworks such as Gin with AWS Lambda and Amazon API Gateway.

Jan 6, 2023

Quick add or delete ASN/AS-SET to your AS-SET through RIPE RESTful API

RIPE AS-SET updater Quick add or delete ASN/AS-SET to your AS-SET through RIPE RESTful API. Requirenments You need to add "auth:" attribute in mntner

Apr 19, 2022

OpenAPI for Todolist RESTful API

Go API client for swagger OpenAPI for Todolist RESTful API Overview This API cli

Dec 18, 2021

Komikuapitk - Restful API Manga bahasa Indonesia built with Go

Komikku API Restful API Manga bahasa Indonesia built with ❤️ and Go Usage Clone

Sep 2, 2022
Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

May 7, 2022
Go api infra - Infrastructure for making api on golang so easy

Go Infra Api Infrastructre methods and types for make api simple Response abstra

Jun 18, 2022
Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK)

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Nov 4, 2022
Feb 7, 2022
A package for access aws service using AWS SDK for Golang

goaws ?? A package for access aws service using AWS SDK for Golang Advantage with goaws package Example for get user list IAM with AWS SDK for Golang

Nov 25, 2021
Aws-cdk-go-examples - Example projects using the AWS CDK by Golang

aws-cdk-go-examples Example projects using the AWS CDK by Golang Useful commands

Nov 24, 2022
Simple RESTful API for WhatsApp in Golang (using the Whatsmeow multi device library)
Simple RESTful API for WhatsApp in Golang (using the Whatsmeow multi device library)

WUZAPI WuzAPI is an implementation of @tulir/whatsmeow library as a simple RESTful API service with multiple device support and concurrent sessions. W

Dec 30, 2022
Integrate AWS EKS Anywhere cluster with AWS Services
 Integrate AWS EKS Anywhere cluster with AWS Services

This article provides step-by-step instruction on integrating AWS EKS Anywhere with AWS Services so the applications running on customer data center can securely connect with these services.

Mar 6, 2022
Apis para la administracion de notifiaciones, utilizando servicios como AWS SNS y AWS SQS

notificacion_api Servicio para envío de notificaciónes por difusión en AWS SNS Especificaciones Técnicas Tecnologías Implementadas y Versiones Golang

Jan 7, 2022
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

Dec 20, 2022