This post explains how to create 2nd gen HTTPS triggered Cloud Function in GCP.
In August, 2022 Google Cloud announced the general availability of the 2nd generation of Cloud Functions. With this announcement now Cloud Functions offers two product versions Cloud Functions (1st gen), the original version, and Cloud Functions (2nd gen), a new version built on Cloud Run and Eventarc to provide an enhanced feature set. With the general availability of the 2nd generation of Cloud Functions you can start using 2nd gen Cloud Functions for new workloads, while continuing to use your existing 1st gen Cloud Functions.
See Also: 1st vs 2nd gen Cloud Functions
See Also: How to create 1st gen Cloud functions
1. Navigate to Google Cloud Console https://console.cloud.google.com/.
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. In the Runtime select Python 3.9, write below code in hello_http entry point and click on DEPLOY.
import functions_framework @functions_framework.http def hello_http(request): request_json = request.get_json(silent=True) request_args = request.args if request_json and 'name' in request_json: name = request_json['name'] elif request_args and 'name' in request_args: name = request_args['name'] else: name = '2nd gen Cloud Function Test' return name
10. Once the function deployment is complete, you should see function URL on the console.
11. Click on the function URL and you should see below response in the browser.