bookmark_borderMeasuring Sentry Impact on AWS Lambda Cold Start and Time to Handler

At Local Logic, we rely heavily on lambda functions. We currently monitor our environment with Sentry via their sdk and know that we could use, as an alternative, the sentry layer. As a good developer, I wondered what were the pros and cons. Obviously, one of them is: which option is the fastest? So, I compared them and will share the results in this post. Without further introduction, let’s dig into the experiment.

Continue reading “Measuring Sentry Impact on AWS Lambda Cold Start and Time to Handler”

bookmark_borderIt’s a Trap! Postgis Geometry with SRID 4326 is not a Geography

Long story short, you create a table with a geometry column that stores points with srid 4326 (read geographic lat/lng, or should I write lng/lat, coordinates). That should be interpreted as geography right? Not at all!

Continue reading “It’s a Trap! Postgis Geometry with SRID 4326 is not a Geography”

bookmark_borderHybrid Pydantic/FastAPI Model

Short story, I have an API that doesn’t run on FastAPI, but I still use FastAPI to generate documentation in OpenAPI format.

So I have models for endpoints and I want them to work with and without FastAPI, because in their pure version FastAPI is not deployed. (To make a long story short, installing FastAPI makes the package a bit heavier to deploy, but especially the cold starts of the AWS lambdas because of the Sentry initialization delay. Sentry detects that FastAPI is present in the environment and automatically adds monitoring, which takes a good 500ms longer than when it’s missing. Measured in December 2023).

Anyway, drawing heavily on a StackOverflow answer, I produced this.

from typing import Annotated, Any, cast

from pydantic import BaseModel, Field
from pydantic.fields import FieldInfo

    from fastapi import Query  # type:ignore[import-not-found]

    def FieldQuery(*args: Any, **kwargs: Any) -> FieldInfo:  # noqa:N802
        return cast(FieldInfo, Field(Query(*args, **kwargs)))

except ImportError:

    def FieldQuery(*args: Any, **kwargs: Any) -> FieldInfo:  # noqa:N802
        return cast(FieldInfo, Field(*args, **kwargs))  # type: ignore[pydantic-field]

class QueryParams(BaseModel):
    limit: Annotated[
            description="The limit of values to fetch. -1 means no limit.",

And for the routes:

from fastapi import FastAPI

from models import QueryParams

app = FastAPI()

def get_things(
    params: Annotated[QueryParams, Depends()],
) -> dict:

Is it perfect? With the “type: ignore”, “noqa”, “import try/except”, not at all. It looks like a big hack.

Does it work? Oh yeah!

Note: The “noqa” and “type: ignore” tags are respectively linked to ruff and mypy linters.

bookmark_borderFastAPI Stripe Webhook Template

A FastAPI equivalent for verify-events-came-from-stripe.

import os

from http import HTTPStatus
from typing import Annotated

import stripe
from fastapi import Depends, FastAPI, Header, HTTPException, Request

app = FastAPI()

async def get_body(request: Request) -> bytes:
    return await request.body()"/webhook", status_code=HTTPStatus.NO_CONTENT)
def post_report(
    stripe_signature: Annotated[str, Header(alias="stripe-signature")],
    body: bytes = Depends(get_body),
) -> None:
    endpoint_secret = os.environ["ENDPOINT_SECRET"]

        # signature validation
        event = stripe.Webhook.construct_event(body, stripe_signature, endpoint_secret)
    except ValueError as e:
        # Invalid payload
        raise HTTPException(status_code=HTTPStatus.BAD_REQUEST) from e
    except stripe.error.SignatureVerificationError as e:
        # Invalid signature
        raise HTTPException(status_code=HTTPStatus.UNPROCESSABLE_ENTITY) from e



A possible catch, one that I ran into, is that I had FastAPI convert the request.body to a dictionary in the function parameters (so body: dict). Then I serialized it to a string for the validation step… and it failed because it was no longer identical to what came in.

bookmark_borderMinimizing the size of lambdas by avoiding having boto3 and its stubs in the deployment package

If you are having problems with AWS lambdas exceeding the 250MB limit, here is a tip that might help.

Continue reading “Minimizing the size of lambdas by avoiding having boto3 and its stubs in the deployment package”

bookmark_borderUsing Selenium to Roll Out Changes to Gihub Settings

Your company is rolling out a new policy and need you to change settings across many repositories? That sounds like a very repetitive task that can be easily automated. I just did it with Selenium. Here is the recipe.

Continue reading “Using Selenium to Roll Out Changes to Gihub Settings”

bookmark_borderA chrome extension to navigate Github files differently

Last week, I was somewhat complaining that Github’s file navigator was not to my taste. When moving across files and directory, you have to go back and forth a lot. If you quickly want to switch between 2 files not in the same directory, it’s painful. Of course, one could open another tab, but tabbing doesn’t cut it. I wanted something more like a files navigator that we can find in any OS.

Then I though, hey, surely I can simply manipulate the HTML to make it work the way I want. I started coding… 45 minutes later, I had a working prototype of JavaScript code that I could simply paste in the browser console and bang; a nice file tree navigator-like experience right in Github.

Continue reading “A chrome extension to navigate Github files differently”

bookmark_borderStarCluster 0.95

English version will follow.

La version 0.95 de StarCluster, à laquelle j’ai contribué à travers mon emploi chez Datacratic et mon implication sur le canal IRC, est sortie hier. Consultez la liste des changements pour plus d’informations.

StarCluster version 0.95, which I contributed to through my work at Datacratic and my implication via the IRC channel, was released yesterday. See the list of changes for more information.

bookmark_borderStarCluster 0.94

La version 0.94 de StarCluster est sortie tout récemment. Le 22 juillet dernier pour être exact.

Pour ceux qui voudraient être un peu plus «bleeding edge», je viens de compléter le merge de la plus récente version de la branche develop à l’intérieur de notre branche vanilla_improvements. À la fin du readme, vous trouverez les ajouts que j’ai faits à la version originale.

StarCluster version 0.94 was recently released. July 22nd to be exact.

For those who would like to use the bleeding edge version, I just completed merging the latest commit on branch develop into our vanilla_improvements branch. At the end of the readme, you will find the additions I made to the original version.