diff --git a/sdk/python/feast/infra/feature_servers/app.py b/sdk/python/feast/infra/feature_servers/app.py index 895dbfde97..d917c7f7b2 100644 --- a/sdk/python/feast/infra/feature_servers/app.py +++ b/sdk/python/feast/infra/feature_servers/app.py @@ -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)