yezarela / go-lambda

Go architecture for AWS Lambda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Lambda

Go architecture for AWS Lambda

Requirements

This is the explanation of our file structure:

.
├── domain                           <-- All domains/entities belong here
├── user                             <-- Module directory
│   └── handler                     
│       └── user-get                 <-- Source code for a lambda function
│           ├── main.go              <-- Lambda function code
│           └── main_test.go         <-- Unit tests
│   └── repository 
│       ├── mysql_repository.go      <-- Repository for our db
│       └── mysql_repository_test.go <-- Unit tests
│   └── usecase 
│       ├── user_usecase.go          <-- Business rules
│       └── user_usecase_test.go     <-- Unit tests
│
├── infra                            <-- All external framework/drivers 
├── utils                            <-- Shared utilities
├── Makefile                         <-- Make to automate build
└── template.yaml                    <-- Cloudformation template

Setup process

Installing dependencies

make deps
docker-compose up -d

Building

make build

Local development

Invoking function locally through local API Gateway

make local

If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function http://localhost:3000/hello

Packaging and deployment

The following command will package your lambda functions, create a Cloudformation Stack and deploy your SAM resources:

make deploy

After deployment is complete you can run the following command to retrieve the API Gateway Endpoint URL:

make describe

Testing

We use testing package that is built-in in Golang and you can simply run the following command to run our tests:

go test -v ./handlers/hello-world/

For mocking purpose, we use gomock from Golang to help us to generate mock files quickly.

Inspiration

TODO

  • Resource tagging

About

Go architecture for AWS Lambda

License:MIT License


Languages

Language:Go 93.5%Language:Makefile 6.5%