AWS Lambda Python
SST uses uv to manage your Python runtime, make sure you have it installed.
Any uv workspace package can be built and deployed as a Lambda function using SST. Drop-in mode is currently not supported.
In this example we deploy a handler from the functions/ directory. It depends
on shared code from another uv workspace in the core/ directory.
├── sst.config.ts├── pyproject.toml├── core│ ├── pyproject.toml│ └── src│ └── core│ └── __init__.py└── functions ├── pyproject.toml └── src └── functions ├── __init__.py └── api.pyThe handler is the path to the handler file and the name of the handler function
in it.
new sst.aws.Function("PythonFunction", { handler: "functions/src/functions/api.handler", runtime: "python3.11", link: [linkableValue], url: true,});SST will traverse up from the handler path and look for the nearest
pyproject.toml. And will throw an error if it can’t find one.
To access linked resources, you can use the SST SDK.
from sst import Resource
def handler(event, context): print(Resource.MyLinkableValue.foo)Where the sst-sdk package can be added to your pyproject.toml.
[project]dependencies = ["sst-sdk"]
[tool.uv.sources]sst-sdk = { git = "https://github.com/sst-community/sst.git", subdirectory = "sdk/python", branch = "main" }You also want to set the Python version in your pyproject.toml to the same
version as the one in Lambda.
requires-python = "==3.11.*"This makes sure that your functions work the same in sst dev as sst deploy.
const linkableValue = new sst.Linkable("MyLinkableValue", { properties: { foo: "Hello World", },});
new sst.aws.Function("PythonFunction", { handler: "functions/src/functions/api.handler", runtime: "python3.11", link: [linkableValue], url: true,});View the full example.