This post explains how to create HTTPS triggered 1st gen and 2nd gen GCP Cloud Functions from Cloud Storage Bucket.
See Also: 1st vs 2nd gen Cloud Functions
To follow this tutorials you need a Cloud Storage Bucket, refer Steps to create bucket in GCP for creating a new Cloud storage bucket.
1. Create a file with name main.py and write below code in it.
def my_function(req):
return f"hello from gcptutorials.com"
2. Zip the main.py and upload the zipped file to Cloud Storage bucket.
3. In the search bar type Cloud Functions and select Cloud Functions from the results.
4. Click on CREATE FUNCTION.
5. Enabled the required APIs.
6. Select the Environment, provide Function Name, select Region. From the Trigger select HTTP and note down the function URL.
7. In Authentication select Allow unauthenticated invocations and click on SAVE
8. Keep the default in Runtime, build, connection and security settings and click on NEXT.
8. Select following options and click on DEPLOY.
9. Once the deployment is complete, got to TRIGGER, click on Trigger URL and you should see function output on the screen.
1. Create a file with name main.py and write below code in it.
def my_function(req):
return f"hello from gcptutorials.com"
2. Zip the main.py and upload the zipped file to Cloud Storage bucket.
2. In the search bar type Cloud Functions and select Cloud Functions from the results.
3. Click on CREATE FUNCTION.
4. Enabled the required APIs.
5. Select the 2nd gen from the Environment dropdown, provide Function Name, select Region.
6. In the HTTPS trigger select Allow unauthenticated invocations.
7. Keep the default settings in Runtime, build, connection and security settings and click on NEXT.
8. Enable the required Artifact Registry API.
9. Select following options and click on DEPLOY.
10. Once the deployment is complete, got to TRIGGER, click on Trigger URL to run the function.
Category: GCP