Skip to content

scrambledeggs/kata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kata - Repository of templates

This repository contains the application templates.

This repo currently only contains a template for AWS SAM in golang.

How to use

  1. Execute from root projects folder
$ sam init
  1. Choose "Custom Template Location"
  2. Enter https://github.com/scrambledeggs/kata
  3. Answer questions (has defaults)
  4. If choose 'n' on with_own_db, db_migration is irrelevant

Post installation

There are some not so straight forward steps to follow after installation:

  1. Update/create a .secrets.json
  2. Create and fill a AWS Secrets Manager for staging and production, staging/production-{{ cookiecutter.project_name }} respectively
  • For some key values like AuthorizerFunctionArn, CertificateArnUs, and CertificateArnAp, you can get in AWS services or check other existing repo
  1. Deploy using github actions
  • we need to deploy first to get DistributionId used by AWS Cloudfront for caching (see TODO for reason)
  • in step Deploy, you can check Cloudformation Outputs for the CloudFrontDistributionId
  1. Update ENV / AWS Secret Manager DistributionId from CloudFrontDistributionId and redeploy

Register staging endpoints in core

  1. Go to https://staging-{{ cookiecutter.project_name }}.booky.ph/endpoints to validate your endpoints exist
  2. Go to core/microservices 2.1. Create new microservice using https://staging-{{ cookiecutter.project_name }}.booky.ph/endpoints
  3. Go to core/permissions 3.1. Create new permission name and description first 3.2. Edit newly created permission 3.3. Look for the list in Allowed Policies of the name you added in step 2.1
  4. Go to core/api-keys 4.1. Create new api key for new permission (even temporary) 4.2. Edit newly created api key 4.3 Search for permission name you created in step 3.1

Add api-key Add x-api-key in Header with value of api-key created in 4.1

Features

API Gateway

Template has an API Gateway included that points to (test-/staging-)[project_name] upon deployment

docs/api_contract

Template has a basic setup of OpenAPI documentation

Makefile

Template has a basic Makefile setup that I've tried executing while making the template

Execute this makefile command for local development

$ make dev

Execute this makefile command to deploy project

$ make deploy ENV=test

github actions

Template has a ready github actions that can deploy already, just adjust depending on your projects needs.

air

Template implements air for live-reloading, this works in the background

Execute this makefile command for local development with air live-reloading

$ make dev-watch

goose/dbmate

Template has options for migration handlers - goose or dbmate

Just install which is preferred to use.

sqlc

Template also has an option for sqlc, and has a basic setup for it. Reads db/migrations but can change file sqlc.yaml for other configurations.

HelloWorldV1 - the sample endpoint

Template has a sample of basic handler HelloWorld under /functions/HelloWorldV1 accessible under /v1/hello-world

AllEndpoints - the /endpoints endpoint

Template already has a ready endpoint for our Booky auth under AllEndpoints handler

CachedWorldV1

Template has a sample of a cached endpoint that goes hand-in-hand with InvalidatedCachedWorldV1 under /functions/CachedWorldV1 accessible under /v1/cached-world

InvalidatedCachedWorldV1

Use this sample endpoint to invalidate the cache of CachedWorldV1 under functions/InvalidatedCachedWorldV1 accessible under /v1/invalidate-cached-world

scripts/generate-endpoints

Creates an endpoint (BOOKY endpoint list) for /endpoints endpoint to read. Uses docs/api_contract.yaml to generate list of endpoints

scripts/generate-secret

Reads from (env-)[project_name](by default) in AWS Secrets Manager and creates a file .secrets.json

scripts/generate-parameter-overrides

Reads .secrets.json (by default) and creates a parameter-override string for sam deploy or sam local start-api`

Single repo reason

Since SAM can't have multiple template yet in one repo as of this writing, I opted to put this under root so it can work this way for now aws/aws-sam-cli#3555.

Contributing

We welcome issue reports and pull requests to help improve these application templates.

Road ahead (TODO):

  1. Find a way to add !Ref CloudFrontDistribution to get the ID created with CloudFrontDistribution and use it in Functions that would use to invalidate CloudFront caches in DISTRIBUTION_ID environment variable.
  • Find a way to add it without circular dependency <- that's the error we get right now

About

Templates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •