npm i
- Create an AWS account if you don't have one.
- Create an IAM User
- Export
aws_access_key_id
andaws_secret_access_key
env variables. - Run
brew install awscli
in the terminal to install AWS CLI - Run
brew install go
- For Linux - Ubuntu - Run
sudo apt install awscli
, enter your password, entery
to confirm. Check version withaws --version
- For Linux - Ubuntu - Run
- Run
aws configure
to Authorize SST via AWS CLI through Lambda to your local environment - Create a
.env
file in the root directory with the necessary environment variables found in .env.example. - Copy the file
functions/gateway/helpers/cloudflare_locations_template
to =>functions/gateway/helpers/cloudflare_locations.go
creating a new file with the.go
extension - Find the string
in the
const cfLocations = `<replace me>`
cloudflare_locations.go
file and replace the<replace me>
(keep the wrapping backtick characters) with the JSON from speed.cloudflare.com/locations... this file is used to intercept incoming request headers and look at theRequest['Headers']['Cf-Ray']
string, which terminates with a 3 letter code likeEWR
which correlates with aniata
airport code. This is the Cloudflare datacenter serving the request - Run
npm run dev:sst
to run the initial AWS project deployment. NOTE that you will NOT use the same command after the initial deployment of your project - Give the project a an SST
stage
name, it can be anything - Once you see
✔ Deployed:
... look forApexUrl: https://<abcxyz>.execute-api.us-east-1.amazonaws.com
whereabcxyz
is a hash unique to your project - Copy this URL and open it in a browser to test that the project runs
- Use CTRL+C to stop the project
- Restart the project with
npm run dev
– you will use this command for all subsequent attempts to start the project) in order to have the project run the following:- SST Go Lambda server with hot reload / Go rebuild – this proxies real AWS resources pointing back to your local Go server through Lambda, and simplifies / sidesteps the complexity of needing to use proxies to ensure harmonious server behaviors liike same-origin and other typical local dev hurdles.
⚠️ Unlike React / JS frontends, since our Go monolith requires a rebuild whenever a template or Go file changes, check your terminal to get a feel for typical "rebuild time". A common issue is to have the server die often when you make a request while it's rebuilding. To avoid this, you really only need to wait maybe about 2 seconds for the rebuild to happen. Once it's finished, you'll be fine, but if you refresh a page0.25s
after a change initiates a rebuild you might see something likeError: spawn /Users/bfeister/dev/meetnearme-api/.sst/artifacts/c8ae08557883d489e35129f0feb436ead1e1695501/bootstrap ENOENT
and then[serve-static] http-server stopped.
- Local static asset server
- Local node.js based
templ
– our golang templating engine pkg) watch script to rebuild templates as they're modified - Local tailwind watcher – this includes some complexity, because we use a hashing algorithim that updates
layout.templ
with a new hash value whenever the tailwind styles in the template change for cache-busting when new deployments are pushed to prod. The dev experience here is a work-in-progress. I've noticed that sometimes updates tolayout.templ
can require a FULL stop / restart of thenpm run dev
processes to take effect.
- SST Go Lambda server with hot reload / Go rebuild – this proxies real AWS resources pointing back to your local Go server through Lambda, and simplifies / sidesteps the complexity of needing to use proxies to ensure harmonious server behaviors liike same-origin and other typical local dev hurdles.
- Add your
APEX_URL
from your local deployment to the allow lists for both Redirect and Post Logout URls in Zitadel under Redirect Settings in the admin UI following the existing URL path schema for both. If you don't have admin access in Zitadel, ask someone on the team
- Add to your
.zshrc
/.bashrc
export GOPATH=$HOME/go
go install github.com/a-h/templ/cmd/templ@latest
- Run
templ generate
npm run dev
should finish with an AWS endpoint, hitting that endpoint should
show a list of events in that particular stage's dynamoDb table
For auth to work, you must add your AWS local deployment's URL to Zitadel's callback URLs our app-specific redirect settings
- Add your AWS deployment URL to
Redirect URIs
and suffix it likehttps://{instance-id}.execute-api.us-east-1.amazonaws.com/auth/callback
- Add your AWS deployment URL to
Post- Logout URIs
, your deployment URL looks like thishttps://{instance-id}.execute-api.us-east-1.amazonaws.com
- Add a new event -
curl <AWS URL from npm run dev>/api/event
- list table Eventscurl -X POST -H 'Content-Type: application/json' --data-raw $'{"events":[{"eventOwners":["123"],"name":"Espanola Lowriders Good Friday Rally & Bar Crawl","description":"Join us in the low rider capital of the world while we hit up all TWO of our local bars\u0021 You haven\'t seen a real lowrider if you haven\'t visited Espanola\u0021","startTime":"2025-02-15T18:30:00Z","address":"Espanola, NM","lat": 36.015303,"long":-106.066063}]}' <AWS URL from npm run dev>/api/event
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/dynamodb/index.html
If you see an error like
(!) templ version check failed: generator v0.2.513 is older than templ version v0.2.648 found in go.mod file, consider upgrading templ CLI
,
you need to update the templ
go binary
go install github.com/a-h/templ/cmd/templ@latest
For an overview of our current env vars with an explanation of each, look at .env.example
When updating env vars, the changes need to be made in 4 places:
stacks/ApiStack.ts
.github/actions/set_aws_creds_env_vars/action.yml
(inputs
section).github/actions/set_aws_creds_env_vars/action.yml
(run
section where vars areecho
d).env.example
to clarify in version control what our currently-used env vars are
For *.meetnear.me
and *.devnear.me
there is some custom configuration
required at the API Gateway level, DNS nameserver level, and Route53
configuration level
- DNS Level - at the time of writing, the
*.me
TLD can't be registered through Amazon, so it's handled through Namecheap.com. - API Gateway / Route53 Level - To map the DNS to Route53 (covered in the
next step), you must first configure at the API Gateway level
- First, go to API Gateway >
Custom Domain Names
and click
Create
. - Enter the new domain, in our case
devnear.me
- Under
ACM Certificate
if this is a new domain, you might need to click Create a new ACM Certificate - After initiating the certificate creation, you'll be taken to the AWS
cert admin panel
where you need to click
Create Records in Route53
to verify domain ownership for the cert - Go to the
API Gateway
> Custom Domains in the AWS console - Click
Create
- Choose the newly created (and now verified via the Route53 records added above) cert
- Go to
devnear.me
(your newly created Custom Domain Name) > Configure API Mappings - Set
API
value to the Cloudformation resource you want to map todevnear.me
- Go back to Route53 console to confirm the mapped
A
records are set correctly. If they are, theValue
for theA
record will be (slightly confusingly)d-<alpha-numeric>.execute-api.us-east-1.amazonaws.com
. This should be different from theApiEndpoint
seen in Github Actions output for the deployment, which typically looks likeApiEndpoint: https://<alpha-numeric>.execute-api.us-east-1.amazonaws.com
. The alpha-numeric characters will not match, and the correctA
record should be prefixed withd-
- First, go to API Gateway >
Custom Domain Names
and click
$ docker compose build
$ docker compose up