Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.

tutor-pet API

Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.

Macro architecture:
Macro architecture

Code architecture:
Code architecture

Pre-Requisites

  1. Install the Go language.
  2. Install the make utility tool.
  3. Install aws-cli, follow the official guide.
  4. Install aws sam-cli, follow the official guide.

How to Run

Locally:

Run the follow command:

make run-local

On AWS:

  1. Run the follow command:
    make deploy
  2. Get the Cognito user-pool-id and Cognito user-pool clint-id at AWS console: UserPool ID Client ID
  3. Run the following script to add an user to the Cognito UserPool and get a token to call the API (remember to add the right values to the env vars before the command):
    chmod +x scripts/cognito_add_test_user.sh
    USER_POOL_ID= CLIENT_ID= [email protected] TEMPORARY_PASSWORD=T3ST@go NEW_PASSWORD=T3ST@golang NAME="" FAMILY_NAME="" ./scripts/cognito_add_test_user.sh
  4. After the cognito_add_test_user.sh script it's possible to get a new token with the following commands:
    chmod +x scripts/cognito_get_token_test_user.sh
    USER_POOL_ID= CLIENT_ID= [email protected] NEW_PASSWORD=T3ST@golang ./scripts/cognito_get_token_test_user.sh
  5. Get the API URL: API URL

If completed successfully, user a tool like curl or Postman to test the API passing the token in the Authorization header. You can also check the stack status inside AWS' console at CloudFormation service.

Note: To remove all the aws services run the below command, it should remove the stack created by the sam cli

make delete

Call sample

curl --request POST \
  --url https://11xxxxx1x1.execute-api.us-east-1.amazonaws.com/dev/pets \
  --header 'Authorization: Bearer token_here' \
  --header 'Content-Type: application/json' \
  --data '{
	"name": "Joca",
	"age": 4,
	"tutorID": 1234
}'

Folder Structure

resources/

This folder contains all the AWS resources used by the API, the files will be grouped together in the base.yaml file before the sam deploy action (there is a build-template script inside the scripts folder to put all the resources and the base template together, see here).

scripts/

This folder has some useful scripts to help the development process

src/

  • handlers: This Folder contains the sub-folders where is the handler code for each lambda. Each AWS Lambda has its own folder and go file has the same name of the sub-folder.
  • models: It is the folder where is the data model.
  • repositories: Here we put the repositories for each model that we create.
  • services: The services receive requests from the handler layer and get the data inside the repository.
  • types: Here we can put DTOs (data transfer objects) for responses or requests.
  • utils: Some useful code to avoid duplication.

Testing [WIP]

Really good example of writing unit test with mocks and spies.

Unit tests

Run the below command:

make unit-test
Owner
Lucas Ferreira
Computer Engineering. Backend Developer | Node.js + Serverless + Typescript + AWS. Knowledge in: Spring Boot + Java and GoLang.
Lucas Ferreira
Similar Resources

A very simple local client-server calculator project built using Cobra and socket programming, written in Go.

Golculator Introduction A very simple local client-server calculator project built using Cobra and socket programming, written in Go. Setup and run Fi

Apr 3, 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

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

A Go client library enabling programs to perform CRUD operations on the goharbor API.

goharbor-client A Go client library enabling programs to perform CRUD operations on the goharbor API. This client library utilizes types generated by

Jan 10, 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

Pulumi - Modern Infrastructure as Code. Any cloud, any language 🚀

Pulumi - Modern Infrastructure as Code. Any cloud, any language 🚀

Pulumi's Infrastructure as Code SDK is the easiest way to create and deploy cloud software that use containers, serverless functions, hosted services,

Dec 30, 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

A serverless sync server for Santa, built on AWS

Rudolph Rudolph is the control server counterpart of Santa, and is used to rapidly deploy configurations to Santa agents. Rudolph is built in Amazon W

Dec 5, 2022
A Lambda function built with SAM (Serverless Application Module)

AWS SAM Lambda Function © Israel Pereira Tavares da Silva The AWS Serverless Application Model (SAM) is an open-source framework for building serverle

Dec 19, 2021
Golang AWS SAM Lambda example

Golang AWS SAM Lambda example This example project shows how to use AWS SAM with

Nov 18, 2022
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 Serverless framework Go language AWS API Gateway AWS Lamb

Dec 25, 2021
Lol-champions-api - A REST API app for CRUD' ing informations related to League of Legends champions, written with Go

LOL-CHAMPIONS-API Just a REST API app for CRUD' ing informations related to Leag

Mar 17, 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
Api-product - A basic REST-ish API that allows you to perform CRUD operations for Products

Description A basic REST-ish API that allows you to perform CRUD operations for

Jan 3, 2022
Feb 7, 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
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
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