Trial on deploying simple Google Cloud Functions Python application with CDKTF on GCP.
- Python 3.8
- GCP Functions Framework
- CDKTF
- gcloud CLI
Install CDKTF
and gcloud CLI
from links above.
Ensure Cloud Build API is enabled in Google project
git clone https://github.com/taiyeoguns/cdktf-gcp-cloud-functions-trial.git
and then change to directory
cd cdktf-gcp-cloud-functions-trial
python -m venv venv
source venv/bin/activate
If gcloud not already set up, open a command prompt, enter:
gcloud init
and follow the instructions.
pip install -r requirements.txt
cd infrastructure
cdktf get
cd application
functions-framework --target=hello_http
Server should be started at http://localhost:8080
To spin up resources, enter:
cd infrastructure
cdktf deploy
to auto approve, use:
cd infrastructure
cdktf deploy --auto-approve
If successful, deployed application url should be available from the function_url
output in the console, e.g. https://us-east1-positive-cacao-243516.cloudfunctions.net/cf-d1d0b561
Endpoint can be tested with https://us-east1-positive-cacao-243516.cloudfunctions.net/cf-d1d0b561
To tear down resources, use:
cd infrastructure
cdktf destroy
to auto-approve, use:
cd infrastructure
cdktf destroy --auto-approve
This project structure combines a CDKTF application and a GCP Functions application. These correspond to the infrastructure
and application
directories respectively. To run any CDKTF commands, ensure you're in the infrastructure
directory, and to run any gcloud Functions framework commands ensure you're in the application
directory.