Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read registry & config from env variables in AWS Lambda feature server #1870

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions sdk/python/feast/infra/feature_servers/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
import base64
import os
import tempfile
from pathlib import Path

import yaml
from mangum import Mangum

import feast
from feast import FeatureStore
from feast.feature_server import get_app

# TODO: replace this with an actual feature repo config deserialized from the env variables
config = feast.RepoConfig()
# Load RepoConfig
config_base64 = os.environ["FEAST_CONFIG_BASE64"]
config_bytes = base64.b64decode(config_base64)

store = feast.FeatureStore(config=config)
# Override the registry path
config_yaml = yaml.safe_load(config_bytes)
config_yaml["registry"] = "registry.db"
config_bytes = yaml.safe_dump(config_yaml).encode()

app = get_app(store)
# Load Registry
registry_base64 = os.environ["FEAST_REGISTRY_BASE64"]
registry_bytes = base64.b64decode(registry_base64)

# Create a new unique directory for writing feature_store.yaml and registry.db files
repo_path = Path(tempfile.mkdtemp())

with open(repo_path / "feature_store.yaml", "wb") as f:
f.write(config_bytes)

with open(repo_path / "registry.db", "wb") as f:
f.write(registry_bytes)

# Initialize the feature store
store = FeatureStore(repo_path=str(repo_path.resolve()))

# Create the FastAPI app and AWS Lambda handler
app = get_app(store)
handler = Mangum(app)