Skip to content

Commit

Permalink
Scaffolded basic Lambda API using Fastify, added CI/CD w/ GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisischris committed Apr 7, 2024
1 parent d9623b5 commit ff9d4fd
Show file tree
Hide file tree
Showing 8 changed files with 656 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Deploy
on:
push:
branches:
- main
- staging
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Deploy to Lambda
run: |
npm install
npx esbuild ./*.ts --bundle --platform=node --outdir=dist --external:@aws-sdk
cd dist
zip -r lambda.zip * > /dev/null
aws lambda update-function-code --function-name equalify-api${{ github.ref != 'refs/heads/main' && '-staging' || '' }} --zip-file fileb://lambda.zip > /dev/null
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Equalify API
API to interact with the Equalify DB.

This is a Node.js Lambda API built on top of Fastify which interacts with the Equalify DB.

Production environment: https://api.equalify.dev
Staging environment: https://api-staging.equalify.dev
Local environment: TBD
8 changes: 8 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Fastify from "fastify";

export const app = Fastify();

app.get("/", async (request, reply) => {
console.log(request, reply);
return { message: "Equalify everything!" };
});
Binary file removed db_2024-04-06.sql.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import awsLambdaFastify from "@fastify/aws-lambda";
import { app } from "./app";

const proxy = awsLambdaFastify(app);

export async function handler(event: any, context: any) {
return await proxy(event, context);
}
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "equalify-api",
"version": "1.0.0",
"main": "index.js",
"repository": "[email protected]:EqualifyEverything/equalify-api.git",
"author": "Christopher Aitken <[email protected]>",
"license": "AGPL-3.0-only",
"imports": {
"#src/*": "./*"
},
"scripts": {
"build:prod": "esbuild ./*.ts --bundle --platform=node --outdir=dist --external:@aws-sdk && cd dist && zip -r lambda.zip * > /dev/null && aws --profile equalify lambda update-function-code --function-name equalify-api --zip-file \"fileb://lambda.zip\" > /dev/null && rm -rf lambda.zip",
"build:staging": "esbuild ./*.ts --bundle --platform=node --outdir=dist --external:@aws-sdk && cd dist && zip -r lambda.zip * > /dev/null && aws --profile equalify lambda update-function-code --function-name equalify-api-staging --zip-file \"fileb://lambda.zip\" > /dev/null && rm -rf lambda.zip",
"build": "yarn build:staging && yarn build:prod"
},
"type": "module",
"dependencies": {},
"devDependencies": {
"@fastify/aws-lambda": "^4.0.0",
"@types/node": "^20.11.27",
"esbuild": "^0.20.1",
"fastify": "^4.26.2"
}
}
583 changes: 583 additions & 0 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit ff9d4fd

Please sign in to comment.