Boavizta / boaviztapi

🛠 Giving access to BOAVIZTA reference data and methodologies trough a RESTful API
GNU Affero General Public License v3.0
66 stars 23 forks source link

Ease the deployment of API as a serverless application #95

Closed demeringo closed 2 years ago

demeringo commented 2 years ago

Problem

In some enterprise context, querying a public API may not be allowed due to security / confidentiality constraints or internet access limitations.

Solution

User may want to self host the API for internal use.

The cloud-scanner for example can be pointed to a specific (private) instance of the API.

An option is to allow the deployment of the API as a serverless application (lambda on AWS) which is relatively cheap and do not imply upfront costs. As a first step, we could wrap the existing API into a lambda using the serverless framework.

Alternatives

Additional context or elements

demeringo commented 2 years ago

https://dwisulfahnur.medium.com/fastapi-deployment-to-aws-lambda-with-serverless-framework-b637b455142c

da-ekchajzer commented 2 years ago

Should we build a specific package on each release or provide an option in the env variable of the docker package ?

demeringo commented 2 years ago

What i would like to try is to simply add the serverless.yml directly at the root of the repository.

IMHO, we do not need to deploy this serveless app through gh action but only provide the boilerplate serverless config to make it easy to deploy for user wanting to create his own instance (in his own account). This means that user should be able to deploy any version of the API by checking out this git revision and running a serveless deploy command.

We may not even need docker for this, serverless framework should be able to wrap/deploy existing fastapi app to lambda is a transparent way. The only additional dependency seems to be https://mangum.io/ which seems to expose the routes of the API in a aws AP gateway / lambda compatible way.

More info: https://adem.sh/blog/tutorial-fastapi-aws-lambda-serverless

demeringo commented 2 years ago

Some insights on customizing openapi spec generation. This may help to serve openapi spec from non-root AWS API gateway route (like when using stage parameter in serveless deployment).

https://github.com/tiangolo/fastapi/issues/2678

demeringo commented 2 years ago

https://github.com/jordaneremieff/mangum/issues/147

demeringo commented 2 years ago

Closing the issue (fully implemented and serving openapi doc now works fine) : https://github.com/Boavizta/boaviztapi/pull/96