This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"cloudformation:List*", | |
"cloudformation:Get*", | |
"cloudformation:ValidateTemplate" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE serverless_example; | |
-- Replace 'test-password' with a secure password of your choice | |
CREATE USER srv_serverless WITH PASSWORD 'test-password'; | |
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO srv_serverless; | |
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO srv_serverless; | |
create table authors | |
( | |
id serial not null primary key , | |
first_name text not null, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: build clean deploy | |
build: | |
go get ./... | |
go mod vendor | |
env GOOS=linux go build -ldflags="-s -w" -o bin/hello hello/main.go | |
env GOOS=linux go build -ldflags="-s -w" -o bin/world world/main.go | |
clean: | |
rm -rf ./bin ./vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: serverless-example | |
frameworkVersion: '2' | |
provider: | |
name: aws | |
runtime: go1.x | |
lambdaHashingVersion: 20201221 | |
environment: | |
DB_NAME: ${ssm:/db-name~true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type StorageIFace interface { | |
} | |
type Storage struct { | |
db *pg.DB | |
} | |
var sto StorageIFace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
import "time" | |
type Article struct { | |
ID int `json:"id"` | |
Name string `json:"name"` | |
AuthorID int `json:"author_id"` | |
CreatedAt time.Time `json:"created_at"` | |
UpdatedAt time.Time `json:"updated_at"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type StorageIFace interface { | |
CreateAuthor(author *models.Author) (*models.Author, error) | |
GetAllAuthors() ([]models.Author, error) | |
CreateArticle(article *models.Article) (*models.Article, error) | |
GetAllArticles() ([]models.Article, error) | |
} | |
// Code down here does not change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"github.com/aws/aws-lambda-go/events" | |
"github.com/aws/aws-lambda-go/lambda" | |
"github.com/marioarizaj/serverless-example/api/common" | |
"github.com/marioarizaj/serverless-example/models" | |
) |
OlderNewer