-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffolded basic Lambda API using Fastify, added CI/CD w/ GitHub Actions
- Loading branch information
1 parent
d9623b5
commit ff9d4fd
Showing
8 changed files
with
656 additions
and
1 deletion.
There are no files selected for viewing
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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
node_modules/ |
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
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 |
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
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 not shown.
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
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); | ||
} |
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
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" | ||
} | ||
} |