Create a Falcon API in service.py
,
# service.py
class QuoteResource:
def on_get(self, req, resp):
quote = {
'quote': "Blabetiblou",
'author': 'Raphaël JOIE'
}
resp.media = quote
api = falcon.App()
api.add_route('/quote', QuoteResource())
# requirements.txt
falcon
and import the API in a lambda_function.py
file
# lambda_function.py
from service import api
from python_falcon_lambda import lambda_handler
lambda_handler = lambda_handler(api)
Run Python Lambda Builder to package
$ docker run \
--volume $(pwd):/workdir \
--platform linux/amd64 \
raphaeljoie/python-lambda-builder \
".terraform/*"
to generate build/lambda.zip
Prepare the deployment
provider "aws" {
region = "eu-west-1"
}
module "api" {
source = "git:///python-falcon-lambda/terraform"
lambda_bucket_name = "shared-lambda-bucket-name"
lambda_name = "my-lambda"
lambda_version = "v0.1.0"
}
output "api_url" {
value = module.api.api_url
}
and terraform apply
- Docker builder is using python3.8 => should use the same for lambda runner
- adapt payload v2.0 and v1.0 https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html