Skip to content

Commit

Permalink
Add Python Lambda
Browse files Browse the repository at this point in the history
Fixes #1583.
  • Loading branch information
lpsinger committed Oct 31, 2023
1 parent cc7b97c commit ed1f670
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '18'
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: NPM Install
run: npm ci
- name: Pip Install
run: pip install -r requirements.txt
- name: Build
run: npm run build
- name: Configure aws credentials
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Node.js CI
name: Pull Request
on:
push:
branches:
Expand All @@ -7,5 +7,10 @@ on:
branches:
- main
jobs:
build:
node:
uses: nasa-gcn/.github/.github/workflows/node.yml@main
python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
vendor

# Generated by `npm run dev`, `npm run build`, etc.
/.cache
Expand All @@ -21,5 +22,8 @@ sam.yaml
# Generated by Mac
.DS_Store

# Generated by Python
__pycache__

.env
.eslintcache
5 changes: 5 additions & 0 deletions app.arc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ remix-gcn
method any
src build/server

/labs/api/*
method any
src python

@email-incoming
circulars
src build/email-incoming/circulars
Expand Down Expand Up @@ -111,6 +115,7 @@ region us-east-1
architecture arm64
memory 256
timeout 30
hydrate false

@search
instanceType t3.small.search
Expand Down
1 change: 1 addition & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export default {
if (!files) return []
return `prettier --write ${filteredFiles}`
},
'*.py': 'black',
}
119 changes: 70 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dev:esbuild": "node esbuild.js --dev",
"dev": "run-p \"dev:*\"",
"prepare": "husky install",
"deploy": "arc deploy --no-hydrate --prune --production",
"deploy": "arc deploy --prune --production",
"clean": "rimraf --glob build/static app/css \"build/**/index.*\" \"build/**/metafile.*\" \"build/**/version.txt\" \"app/**/*.css\" \"app/**/*.css.map\" sam.json sam.yaml .cache",
"test": "jest",
"test-coverage": "jest --coverage",
Expand Down Expand Up @@ -135,6 +135,10 @@
"ts-jest": "^29.1.0",
"typescript": "^5.2.2"
},
"overrides": {
"@architect/hydrate": "github:lpsinger/hydrate#hydrate-per-function-config",
"@architect/sandbox": "github:lpsinger/sandbox#x-forwarded-port-string"
},
"engines": {
"node": ">=18"
},
Expand Down
7 changes: 7 additions & 0 deletions python/config.arc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@aws
runtime python3.11
memory 2048
timeout 30

@arc
hydrate true
17 changes: 17 additions & 0 deletions python/lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright © 2023 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.


from fastapi import FastAPI
from mangum import Mangum

app = FastAPI()


@app.get("/")
async def example():
return {"greeting": "Hello, world!"}


handler = Mangum(app, api_gateway_base_path="/labs/api", lifespan="off")
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
astropy
black
fastapi
mangum

0 comments on commit ed1f670

Please sign in to comment.