Skip to content

Commit 83f9efb

Browse files
committed
add script to update lambda env vars, fix imports
1 parent e88fb71 commit 83f9efb

5 files changed

Lines changed: 50 additions & 7 deletions

File tree

config_lambdas.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import json
2+
import subprocess
3+
4+
5+
def get_lambdas():
6+
functions = {}
7+
res = subprocess.Popen(
8+
["aws", "lambda", "list-functions"],
9+
stdout=subprocess.PIPE,
10+
)
11+
output = res.communicate()[0]
12+
functions.update(json.loads(output))
13+
return functions["Functions"]
14+
15+
16+
# for lambda_function in get_lambdas():
17+
# function_name = lambda_function["FunctionName"]
18+
19+
with open(".env", "r") as f:
20+
env_vars = [
21+
line for line in f.read().splitlines() if line.startswith("SOLESEARCH_")
22+
]
23+
env = ",".join(env_vars)
24+
subprocess.run(
25+
[
26+
"aws",
27+
"lambda",
28+
"update-function-configuration",
29+
"--region",
30+
"us-east-1",
31+
"--function-name",
32+
"solesearch-api",
33+
"--environment",
34+
f"Variables={{{env}}}",
35+
]
36+
)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ path = "src/api/__about__.py"
3131
allow-direct-references = true
3232

3333
[tool.hatch.envs.default.scripts]
34-
start = "python -m api.server"
34+
start = "python -m src.api.main"
3535

3636
[tool.hatch.envs.dev]
3737
pre-install-commands = ["pip install -e ../core"]
38-
scripts.start = "uvicorn src.api.main:app --reload"
38+
scripts.start = "python -m src.api.main"
3939

4040
[tool.hatch.build.targets.wheel]
4141
packages = ["src/api"]

src/api/data/queries.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from bson import ObjectId
55

66
from api.data.instance import DEFAULT_LIMIT, DEFAULT_OFFSET, db, sneakers
7-
from api.data.models import Audience, SortKey, SortOrder
7+
from api.data.models import SortKey, SortOrder
8+
from core.models.details import Audience
89

910

1011
def find_sneaker_by_id(id: str = ""):

src/api/main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from mangum import Mangum
66
from starlette.middleware.sessions import SessionMiddleware
77

8-
from api.routes import auth, sneakers
8+
if not os.environ.get("AWS_EXECUTION_ENV"):
9+
load_dotenv(os.path.join(os.getcwd(), ".env"))
910

10-
dotenv_path = os.path.join(os.path.dirname(__file__), ".env")
11-
load_dotenv(dotenv_path)
11+
from api.routes import auth, sneakers
1212

1313
app = FastAPI(
1414
redoc_url=None,
@@ -20,3 +20,8 @@
2020
app.include_router(sneakers.router)
2121
app.include_router(auth.router)
2222
handler = Mangum(app)
23+
24+
if __name__ == "__main__":
25+
import uvicorn
26+
27+
uvicorn.run(app, host="localhost", port=8000)

src/api/routes/sneakers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from fastapi import APIRouter, Query
44

55
from api.data.instance import DEFAULT_LIMIT, DEFAULT_OFFSET
6-
from api.data.models import Audience, SortKey, SortOrder
6+
from api.data.models import SortKey, SortOrder
77
from api.data.queries import find_sneaker_by_id, find_sneaker_by_sku, find_sneakers
8+
from core.models.details import Audience
89

910
router = APIRouter(
1011
prefix="/sneakers",

0 commit comments

Comments
 (0)