This project builds a cloud backend stack in AWS using Golang CDK for handling requests containing Firebase JWT tokens. A part of or entire codebase of the project can be used as a reference for building serverless authentication system in AWS that uses Firebase Authentication in Go programming language.
The stack provisions following AWS resources:
- API Gateway recieves requests, also it terminates TLS and guards its backend with custom throttling. It forwards the request to authorizer function and responds back to API caller.
- Lambda authorizer function validates authenitcation token in request's header. And
- Lambda function processes the valid requests and writes content of token into DynamoDB, and sends notification email to owner of the token.
For developing and deploying resources in the project, you will need following prerequisites:
-
Go, v1.20 or newer
Follow instructions on its official website https://go.dev/doc/install. -
aws-cdk CLI tool
CDK npm package needs to be installed. Assuming nodejs is already installed, run below:
npm install -g cdk
-
Docker
Docker image AL2003, Amazon Linux Image for Go, is used for building lambda functions with Go toolchain. Read more about Building lambda function in Go
For docker installation, follow offical guide at https://docs.docker.com/engine/install
go mod download
go get
This CDK stack is deployed to AWS environment which is setup in local AWS configuration. For more details about environment configuration, refer to AWS official guide on Environments for the AWS CDK
cdk bootstrap
bootstrap stack, only run once at first timecdk deploy
deploy this stack to AWS, run whenever code changes
cdk diff
compare deployed stack with current statecdk destroy
clean up provisioned AWS resourcescdk synth
emits the synthesized CloudFormation templatego test
run unit tests
# Deploy the stack in hot-swap for live updates in case of code changes
cdk watch
# Send a request and monitor its live logs from watch command's output
curl -X POST https://9h3r3yi8mh.execute-api.eu-west-1.amazonaws.com/ --header "Authorization: Bearer abcdefgh"