The Stack
Serverless processing: Google Cloud Run Serverless data: Upstash Web framework: ExpressProject Setup
Create a directory for your project:The Code
Create index.js and update as below:node index.js
Check http://localhost:3000/foo in different
browsers to validate it keeps the session.
Add the start script to your package.json
:
Build
Create a Docker file (Dockerfile) in the project folder as below:gcloud container images list
Run the container locally:
Deploy
Run:Cloud Run vs Cloud Functions
I have developed two small prototypes with both. Here my impression:- Simplicity: Cloud functions are simpler to deploy as it does not require any container building step.
- Portability: Cloud Run leverages your container, so anytime you can move your application to any containerized system. This is a plus for Cloud Run.
- Cloud Run looks more powerful as it runs your own container with more configuration options. It also allows running longer tasks (can be extended to 60 minutes)
- Cloud Run looks more testable as you can run the container locally. Cloud Functions require a simulated environment.