How-to guides
The user can enter the required information for Cloud Functions through the Samsung Cloud Platform Console, select detailed options, and create the service.
Cloud Functions Create
Click the All Services > Compute > Cloud Functions menu. Navigate to the Service Home page of Cloud Functions.
Click the Create Cloud Functions button on the Service Home page. It navigates to the Create Cloud Functions page.
Create Cloud Functions page, enter the information required to create the service.
| Category | Required | Detailed description |
|---|
| Funtion name | Required | Enter the Funtion name to create- Start with a lowercase English letter and use lowercase English letters, numbers, and special characters (
-) to input within 3 ~ 64 characters
|
| Runtime | Required | Select Runtime creation method- Create new: Create a new Runtime
- Start with Blueprint: Create using the Runtime source code provided by the service
|
| Runtime & Vesion | Required | Select Runtime and Version- Create New을 선택한 경우
- For Java runtime, UI code editing is not supported, but you can run by fetching a Jar file from Object Storage
- Start with Blueprint를 선택한 경우
- You can view source code examples by clicking the View Source Code button for the selected Runtime & Version
|
Table. Cloud Functions Service Information Input Items
Summary Check the detailed information and estimated billing amount generated in the panel, and click the Complete button.
- When creation is complete, check the created resource on the Cloud Functions list page.
Cloud Functions Details page consists of Detail Information, Monitoring, Log, Code, Configuration, Trigger, Tag, Job History tabs.
To view detailed information about the Cloud Functions service, follow these steps.
- All Services > Compute > Cloud Functions Click the menu. Go to the Service Home page of Cloud Functions.
- Click the Function menu on the Service Home page. Move to the Function List page.
- Click the resource to view detailed information on the Function list page. Go to the Function detail page.
- Function Details The page displays status information and additional feature information, and consists of the Details, Monitoring, Log, Code, Configuration, Trigger, Tag, Task History tabs.
| Category | Detailed description |
|---|
| Cloud Functions status | Cloud Functions status information- Ready: green icon, state where normal function calls are possible
- Not Ready: gray icon, state where normal function calls are not possible
- Deploying: yellow icon, state where function is being created or changed, triggered by the following actions
- function creation and modification
- modify code with editor in the Code tab
- inspect jar file in the Code tab
- add and modify in the Trigger tab
- modify in the Configuration tab
- Running: blue icon, state where normal function calls are possible and cold start prevention policy is applied
|
| Service cancellation | Button to cancel the service |
Table. Cloud Functions status information and additional features
Function list page, you can view detailed information of the selected resource and, if necessary, edit the information.
| Category | Detailed description |
|---|
| service | service name |
| Resource Type | Resource Type |
| SRN | Unique resource ID in Samsung Cloud Platform |
| Resource Name | Resource Name- In the Cloud Functions service, it refers to the Function name
|
| Resource ID | Unique resource ID of the service |
| Creator | User who created the service |
| Creation time | Date/time the service was created |
| Editor | User who modified the service |
| Modification Date and Time | Date and time the service was modified |
| Function name | Name of Cloud Function |
| Runtime | Runtime types and versions |
| LLM Endpoint | Click User Guide to view LLM Endpoint information and usage instructions |
Table. Cloud Functions Details - Detailed Information Tab Items
Reference
For detailed information on how to use LLM by integrating AIOS, please refer to
Integrate AIOS.
Monitoring
You can view the Cloud Functions usage information of the selected resource on the Function List page.
| Category | Detailed description |
|---|
| Number of calls | Average number of times the function was called during the unit time (instances) |
| Execution Time | Average execution time (seconds) of the function during the unit time |
| Memory usage | Average memory usage (kb) used during the execution of the function per unit time |
| Current task count | If the function is called multiple times simultaneously, the average number of tasks generated per unit time for concurrent processing (count) |
| Successful call count | Average number of times (cases) the runtime code operated normally and delivered a response code per unit time when the function is called |
| Failed call count | Average number of calls with errors per unit time when the function is invoked- Including runtime due to response timeouts and logic errors
|
Table. Cloud Functions Details - Monitoring Tab Items
Log
You can view the Cloud Functions logs of the selected resource on the Function list page.
| Category | Detailed description |
|---|
| Unit period | Select the period to view Cloud Functions log information- Select in time units (1 hour, 3 hours, 12 hours) or set manually
|
| Log Message | Displayed in order from the most recent occurring function. |
Table. Cloud Functions Details - Log Tab Items
Reference
Log messages can be viewed up to the previous 1,000 messages based on the most recent occurrence.
Code
Function list page allows you to view and edit the Cloud Functions code of the selected resource.
Reference
The way to view and edit source code changes depending on the runtime used.
- Inline Editor: Node.js, Python, PHP, Go
- Run compressed file (.jar/.zip): Java
| Category | Detailed description |
|---|
| Source Code | Inline Editor Mode |
| Code Information | Display code information |
| Edit | Edit After clicking the button, you can edit the code in the inline editor |
Table. Cloud Functions Details - Inline Editor Items in Code Tab
| Category | Detailed description |
|---|
| Source code | Compressed file (.jar/.zip) execution method |
| Code Information | Compressed File Information Display- Java Runtime: Java Runtime version information
- Handler Information: Execution Class and Method information
- Compressed file name (.jar/.zip): Name of the currently set compressed file
- File upload date and time: Upload date and time of the currently set compressed file
- Transmission status: Compressed file transmission history
- Transmission success: When the compressed file setting is successful
- Reason for failure when compressed file transmission fails
|
| Edit | Jar file can be changed- Can be changed by clicking the Get from Object Storage button on the Function code edit page
- Enter the Private URL of the file in the Object Storage bucket to be fetched
- For details on changing compressed files, refer to [Java Runtime code change](#java-runtime code change)
|
Table. Cloud Functions Details - Execution Items of Compressed Files (.jar/.zip) in Code Tab
Reference
- In the case of Java Runtime, it does not provide UI code editing functionality, and you must select a compressed file (.jar/.zip) from the bucket of the Object Storage service.
- In case of users whose Object Storage service authentication key has not been generated, Import from Object Storage cannot be executed, so you must generate the authentication key in advance.
- Cloud Functions service’s Object Storage bucket’s access control must be changed to allow state.
Composition
Function list page allows you to view the Cloud Functions configuration of the selected resource.
| Category | Detailed description |
|---|
| General Configuration | Cloud Function memory and timeout settings- Memory: Maximum memory limit per function
- Timeout: Maximum waiting time for a function call per function. After the timeout, the function goes into a Scale-to-zero state and terminates
- Function execution: Minimum and maximum number of tasks
- Click the Edit button to change the General Configuration settings
|
| Environment Variable | Set runtime environment variables- When using environment variables, you can adjust the function’s behavior without updating the code
- Edit button to environment variable can be added or edited
|
| Function URL | Issue an HTTPS URL address that can access the function- Click the Edit button to set activation status, authentication type, and allowed IP
- When calling the function authenticated with IAM type, the header must include “
x-scf-access-key”, “x-scf-secret-key”. In this case, policy and authentication key IP access control are not applied
|
| Private connection configuration | Can be used in conjunction with PrivateLink Service |
Table. Cloud Functions Details - Configuration Tab Items
Caution
If you disable Access Control, the registered access information will be deleted, making function access control impossible, so it may be exposed to security attacks such as external scanning and hacking.
Reference
- General Configuration’s memory allocation proportionally determines the number of CPU cores that are automatically assigned.
- General configuration’s minimum execution count of 1 or more prevents Cold Start, but costs are incurred continuously.
Trigger
Function List page allows you to view and configure trigger information of the selected resource. If you set a trigger, the Function can be automatically executed when an event occurs.
| Category | Detailed description |
|---|
| Cronjob | Use Cronjob as a trigger- Automatically invoke the function according to time or a scheduled interval
- Click the Edit button to change the frequency and time zone
|
| API Gateway | Use API Gateway as a trigger- You can view the API Gateway name and detailed information.
|
Table. Cloud Functions Details - Trigger Tab Items
Caution
If you call the Cronjob trigger before the function timeout, the function will run nestedly, increasing the execution count and duration. Consequently, continuous additional costs can accrue, leading to high expenses, so be careful.
Reference
- Deploying If in this state, cannot be edited.
- About trigger settings, please refer to Trigger Setup.
Tag
In the Tag tab, you can view the resource’s tag information, and add, modify, or delete it.
| Category | Detailed description |
|---|
| Tag List | Tag List- Tag’s Key, Value information can be checked
- Up to 50 tags can be added per resource
- When entering tags, search and select from the existing list of created Keys and Values
|
Table. Cloud Functions Details - Tag Tab Items
Work History
You can check the work history of resources on the Work History page.
| Category | Detailed description |
|---|
| Work History List | Resource Change History- Work details, work date and time, resource type, resource name, work result, worker information can be checked
- When you click the corresponding resource in the Work History List, the Work History Details popup opens
|
Table. Cloud Functions Details - Job History Tab Items
Java Runtime Code Change
If you are using Java Runtime, you cannot modify the code directly, so you need to select and change the compressed file (.jar/.zip) in the bucket of the Object Storage service.
Follow the steps below to change the compressed file.
To cancel the Cloud Functions service, follow the steps below.
- Click the All Services > Compute > Cloud Functions menu. Go to the Service Home page of Cloud Functions.
- Service Home on the page click the Function menu. Navigate to the Function list page.
- Click the resource to change the compressed file within the code on the Function List page. Navigate to the Function Details page.
- Click the Edit button on the Code tab of the Function Details page. It moves to the Function Code Edit page.
- Import from Object Storage Click the button. Import from Object Storage popup opens.
| Category | Detailed description |
|---|
| Java Runtime | Java Runtime information |
| Handler Information | Handler Information- Execution Class: Automatically entered when setting compressed file (.jar/.zip)
- Execution Method: Automatically entered when setting compressed file (.jar/.zip)
|
| Compressed file (.jar/.zip) | Set the compressed file to modify- Compressed file name (.jar/.zip): Displays the name of the compressed file. After setting Get from Object Storage, it is entered automatically
- Get from Object Storage: Set the Object Storage to retrieve the compressed file (.jar/.zip)
|
Table. Cloud Functions Details - Function Code Modification Items
- Object Storage URL After entering the URL information of the Object Storage from which to retrieve the compressed file, click the Confirm button. A notification popup will open.
- The URL information can be found in the Folder List tab of the detailed page of the Object Storage to be retrieved, under the File Information > Private URL item.
- Click the Confirm button. The name of the imported archive file is displayed in the Function code edit page’s Archive file name (.jar/.zip).
- Click the Save button.
Caution
- In case of a user whose authentication key has not been generated, Import from Object Storage cannot be executed.
- If the URL does not exist or the compressed file corresponds to the following, it cannot be changed.
- When using an unsupported extension
- If there is a harmful file in the compressed file
- If it exceeds the supported size
Cloud Functions Cancel
To cancel the Cloud Functions service, follow the steps below.
- All Services > Compute > Cloud Functions Click the menu. Navigate to the Service Home page of Cloud Functions.
- Click the Function menu on the Service Home page. Go to the Function List page.
- Function list page, click the resource to be terminated and click the Cancel Service button.
- When the termination is completed, check whether the resource has been terminated on the Function List page.
1 - Set Trigger
Set up trigger
Reference
- By default, all triggers can be added in Cloud Functions.
- If triggered from a specific product, it must be passed to Cloud Functions.
Cronjob Trigger Setup
To set up a Cronjob trigger, follow these steps.
- All Services > Compute > Cloud Functions Click the menu. Navigate to the Service Home page of Cloud Functions.
- Click the Function menu on the Service Home page. It moves to the Function List page.
- Function List 페이지에서 트리거를 설정할 자원을 클릭하세요. Function Details 페이지로 이동합니다.
- After clicking the Trigger tab, click the Add Trigger button. Set it. The Add Trigger popup opens.
- Add Trigger In the popup window, select Trigger Type Cronjob. The required information input area appears at the bottom.
| Category | Detailed description |
|---|
| Cronjob Settings | Set the trigger’s repeat frequency- Can be set in minutes, hours, days, months, and weekdays
|
| Timezone setting | Set the trigger’s reference time zone |
Table. Cronjob Trigger Required Information Items
- After entering the required information, click the Confirm button.
- When the pop-up window notifying addition opens, click the Confirm button.
API Gateway Trigger Setup
To set up an API Gateway trigger, follow these steps.
- All Services > Compute > Cloud Functions Click the menu. Go to the Service Home page of Cloud Functions.
- Click the Function menu on the Service Home page. Go to the Function List page.
- Function List on the page, click the resource to set the trigger. Function Details go to the page.
- After clicking the Trigger tab, click the Add Trigger button. Set it. The Add Trigger popup window opens.
- Add Trigger In the popup window, select Trigger Type API Gateway. A required information input area appears at the bottom.
| Category | Detailed description |
|---|
| API name | API selection- You can select an existing API or create a new one
|
| Stage | Select deployment target- You can select an existing stage or create a new one
|
Table. API Gateway Trigger Required Information Items
- After entering the required information, click the Confirm button.
- When the popup notifying addition opens, click the Confirm button.
Setting up Multi Trigger
You can connect multiple triggers to a single function and use them.
Edit Trigger
To modify the added trigger, follow the steps below.
- All Services > Compute > Cloud Functions Click the menu. Go to the Service Home page of Cloud Functions.
- Click the Function menu on the Service Home page. Navigate to the Function List page.
- On the Function List page, click the resource to edit the trigger. It moves to the Function Details page.
- After clicking the Trigger tab, click the Edit button of the trigger whose settings you want to modify in the trigger list. The Edit Trigger popup window opens.
- Trigger Edit After modifying the setting values in the popup window, click the Confirm button.
- When the popup notifying the edit opens, click Confirm.
Delete Trigger
To delete the trigger, follow the steps below.
Caution
Triggers linked to a specific product only manage the product delivered at the time of linking in that product, and when Functions are terminated, a deletion status must be delivered to that product.
- All Services > Compute > Cloud Functions Click the menu. Navigate to the Service Home page of Cloud Functions.
- Click the Function menu on the Service Home page. Navigate to the Function List page.
- Function List page, click the resource to set the trigger. Function Details page will be navigated.
- In the Trigger tab’s trigger list, after selecting the trigger to delete, click the Delete button.
- Click the Confirm button when the popup notifying trigger deletion opens.
3 - Blueprint Detailed Guide
Blueprint Overview
When creating Cloud Functions, you can set the Blueprint to utilize the Runtime source code provided by Cloud Functions.
Refer to the following for Blueprint items provided by Cloud Functions.
| Category | Detailed Description | Remarks |
|---|
| Hello World | When the function is called, it responds with Hello Serverless World! | |
| Execution after timeout | Outputs code that should be executed after the function call time has exceeded, but does not execute. | PHP, Python not supported |
| HTTP request body | Parses the request body. | PHP not supported |
| Send HTTP requests | Send HTTP requests from Cloud functions. | PHP not supported |
| Print logs | Outputs the user’s Samsung Cloud Platform Console Request to the log. | PHP not supported |
| Throw a custom error | Enter the error logic directly to handle the error. | |
| Using Environment Variable | Configure environment variables within the Cloud function and execute. | |
Table. Blueprint Items
Hello World
Hello World explains how to set up receiving responses and an example of function call (using function URL).
Hello World Setting
To set Hello World, follow the steps below.
All Services > Compute > Cloud Functions Click the menu. Navigate to the Service Home page of Cloud Functions.
Click the Function menu on the Service Home page. Go to the Function list page.
Function list page, click the resource to be called via URL. Navigate to the Function detail page.
Click the Configuration tab, then click the Edit button of the Function URL item. The Edit Function URL popup opens.
Edit Function URL in the popup window, after setting Activation Status to Enabled, click the Confirm button.
| Category | Detailed description |
|---|
| Activation status | Set whether to use function URL |
| Authentication Type | Select whether to use IAM authentication when requesting the function URL |
| Access Control | Can manage by adding accessible IPs- After setting to Use, public access IP can be entered and added
|
Table. Required input fields when adding a trigger
After moving to the Code tab, click the Edit button. You will be taken to the Function Code Edit page.
After adding the processing logic for success and failure cases, click the Save button.
- Node.js source code
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
const response = {
statusCode: 200,
body: JSON.stringify('Hello Serverless World!'),
};"
return response;
};
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
const response = {
statusCode: 200,
body: JSON.stringify('Hello Serverless World!'),
};"
return response;
};
Hello World - Node.js source code - Python source code
import json
def handle_request(params):
# User writing area (Function details)
return {
'statusCode': 200,
'body': json.dumps('Hello Serverless World!')
}
import json
def handle_request(params):
# User writing area (Function details)
return {
'statusCode': 200,
'body': json.dumps('Hello Serverless World!')
}
Hello World - Python source code - PHP source code
<?php
function handle_request() {
# User writing area (Function details)
$res = array(
'statusCode' => 200,
'body' => 'Hello Serverless World!',
);
return $res;
}
?>
<?php
function handle_request() {
# User writing area (Function details)
$res = array(
'statusCode' => 200,
'body' => 'Hello Serverless World!',
);
return $res;
}
?>
Hello World - PHP source code
Check function call
After calling the function URL in the Configuration tab of the Function Details page, verify the response.
Hello Serverless World!
# Execution after timeout
Explain the setting for execution after timeout and an example of function call (using function URL).
## Execution after timeout Setting
To set Execution after timeout, follow the steps below.
1. **All Services > Compute > Cloud Functions** Click the menu. Go to the **Service Home** page of Cloud Functions.
2. Click the **Function** menu on the **Service Home** page. Navigate to the **Function List** page.
3. **Function List** page, click the resource to set the trigger. **Function Details** page will be opened.
4. After clicking the **Trigger** tab, click the **Add Trigger** button. The **Add Trigger** popup opens.
5. **Add Trigger** In the popup window, after selecting the **Trigger Type** item, enter the required information displayed at the bottom and click the **Confirm** button.
* Required information varies depending on the trigger type.
| Trigger Type |
Input Item |
| API Gateway |
- API name: You can select an existing API or create a new one
- Stage: You can select an existing stage or create a new one
|
| Cronjob |
- Refer to the example and enter the trigger’s repeat frequency (minute, hour, day, month, day of week)
- Timezone setting: select the reference time zone to apply
|
Table. Required input items when adding a trigger
6. **Code** after moving to the tab, click the **Edit** button. You will be taken to the **Function Code Edit** page.
7. After adding the processing logic for success and failure cases, click the **Save** button.
* Node.js source code
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
console.log("Hello world 3");
await delay(3000);
const response = {
statusCode: 200,
body: JSON.stringify('Hello Serverless World!'),
};;
return response;
};
const delay = (ms) => {
return new Promise(resolve=>{
setTimeout(resolve,ms)
})
}
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
console.log("Hello world 3");
await delay(3000);
const response = {
statusCode: 200,
body: JSON.stringify('Hello Serverless World!'),
};;
return response;
};
const delay = (ms) => {
return new Promise(resolve=>{
setTimeout(resolve,ms)
})
}
Execution after timeout - Node.js source code ## Check function call
**Function Details** page's **configuration** tab call the **function URL** and after a certain amount of time, check the response.
Hello Serverless World!
# HTTP request body
Explains the Request Body parsing settings and function call example (using function URL).
## Setting HTTP request body
To set the HTTP request body, follow these steps.
1. Click the **All Services > Compute > Cloud Functions** menu. Go to the **Service Home** page of Cloud Functions.
2. Click the **Function** menu on the **Service Home** page. Navigate to the **Function** list page.
3. **Function List** page, click the resource to set the trigger. **Function Details** page will be opened.
4. After clicking the **Trigger** tab, click the **Add Trigger** button. The **Add Trigger** popup opens.
5. **Add Trigger** in the popup window, after selecting the **Trigger Type** item, enter the required information displayed at the bottom and click the **Confirm** button.
* Required information varies depending on the trigger type.
| Trigger Type |
Input Item |
| API Gateway |
- API name: You can select an existing API or create a new one
- Stage: You can select an existing stage or create a new one
|
| Cronjob |
- Refer to the example and enter the trigger’s repeat frequency (minute, hour, day, month, day of week)
- Timezone setting: select the time zone to apply
|
Table. Required input items when adding a trigger
6. After moving to the **Code** tab, click the **Edit** button. You will be taken to the **Function Code Edit** page.
7. After adding processing logic for success and failure cases, click the **Save** button.
* Node.js source code
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
const response = {
statusCode: 200,
body: JSON.stringify(params.body),
};;
return response;
};
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
const response = {
statusCode: 200,
body: JSON.stringify(params.body),
};;
return response;
};
Execution after timeout - Node.js source code * Python source codeimport json
def handle_request(params):
# User writing area (Function details)
return {
'statusCode': 200,
'body': json.dumps(params.json)
}
import json
def handle_request(params):
# User writing area (Function details)
return {
'statusCode': 200,
'body': json.dumps(params.json)
}
Execution after timeout - Python source code ## Check function call
**Function Details** page's **Configuration** tab after calling the **function URL**, check the Body data, request Body value, and response Body value.
* request Body value{
"testKey" :"cloud-001",
"testNames": ["
{
"name": "Son"
},
{
"name": "Kim"
}
],
"testCode":"test"
}
{
"testKey" :"cloud-001",
"testNames": ["
{
"name": "Son"
},
{
"name": "Kim"
}
],
"testCode":"test"
}
Request Body Value * Response Body value{
"testKey" :"cloud-001",
"testNames": [
{
"name": "Son"
},
{
"name": "Kim"
}
],
"testCode":"test"
}
{
"testKey" :"cloud-001",
"testNames": [
{
"name": "Son"
},
{
"name": "Kim"
}
],
"testCode":"test"
}
Response Body Value # Send HTTP requests
Explains the HTTP request settings and function call example (using function URL).
## Send HTTP requests Setup
To configure Send HTTP requests, follow the steps below.
1. **All Services > Compute > Cloud Functions** Click the menu. Go to the **Service Home** page of Cloud Functions.
2. Click the **Function** menu on the **Service Home** page. Go to the **Function List** page.
3. Click the resource to set the trigger on the **Function List** page. It navigates to the **Function Details** page.
4. After clicking the **Trigger** tab, click the **Add Trigger** button. The **Add Trigger** popup opens.
5. **Add Trigger** In the popup window, after selecting the **Trigger Type** item, enter the required information displayed at the bottom and click the **Confirm** button.
* Required information varies depending on the type of trigger.| Trigger Type | Input Item |
|---|
| API Gateway | - API name: You can select an existing API or create a new one
- Stage: You can select an existing stage or create a new one
|
| Cronjob | - Refer to the example and enter the trigger’s repeat frequency (minute, hour, day, month, day of week)
- Timezone setting: select the reference time zone to apply
|
| |
| Table. Required input items when adding a trigger | |
| |
6. After moving to the **Code** tab, click the **Edit** button. You will be taken to the **Function Code Edit** page.
7. After adding the processing logic for success and failure cases, click the **Save** button.
* Node.js source codeconst request = require('request');
/**
* @description User writing area (Function details)
*/
exports.handleRequest = async function (params) {
return await sendRequest(params);
};
async function sendRequest(req) {
return new Promise((resolve, reject) => {
// Port 80 and Port 443 are available
url = "https://example.com"; // Destination URL
const options = {
uri: url,
method:'GET',
json: true,
strictSSL: false,
rejectUnauthorized: false
}
request(options, (error, response, body) => {
if (error) {
reject(error);
} else {
resolve({
statusCode: response.statusCode,
body: JSON.stringify(body)
});
}
});
});
}
const request = require('request');
/**
* @description User writing area (Function details)
*/
exports.handleRequest = async function (params) {
return await sendRequest(params);
};
async function sendRequest(req) {
return new Promise((resolve, reject) => {
// Port 80 and Port 443 are available
url = "https://example.com"; // Destination URL
const options = {
uri: url,
method:'GET',
json: true,
strictSSL: false,
rejectUnauthorized: false
}
request(options, (error, response, body) => {
if (error) {
reject(error);
} else {
resolve({
statusCode: response.statusCode,
body: JSON.stringify(body)
});
}
});
});
}
Send HTTP requests - Node.js source code * Python source codeimport json
import requests
def handle_request(params):
# User writing area (Function details)
# Port 80 and Port 443 are available
url = "https://example.com" # Destination URL
try:
response = requests.get(url, verify=True)
return {
'statusCode': response.status_code,
'body': json.dumps(response.text)
}
except requests.exceptions.RequestException as e:
return str(e)
import json
import requests
def handle_request(params):
# User writing area (Function details)
# Port 80 and Port 443 are available
url = "https://example.com" # Destination URL
try:
response = requests.get(url, verify=True)
return {
'statusCode': response.status_code,
'body': json.dumps(response.text)
}
except requests.exceptions.RequestException as e:
return str(e)
Send HTTP requests - Python source code ## Check function call
**Function Details** page's **Configuration** tab, after calling the **function URL**, check the response.<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
Check function call response # Print logs
Explains the log output settings and function call example (using function URL).
## Print logs Setup
Print logs To set up receiving responses, follow the steps below.
1. Click the **All Services > Compute > Cloud Functions** menu. Navigate to the **Service Home** page of Cloud Functions.
2. Click the **Function** menu on the **Service Home** page. Move to the **Function List** page.
3. **Function List** page, click the resource to set the trigger. **Function Details** page will be opened.
4. Click the **Trigger** tab, then click the **Add Trigger** button. The **Add Trigger** popup opens.
5. **Add Trigger** In the popup window, after selecting the **Trigger Type** item, enter the required information displayed at the bottom and click the **Confirm** button.
* Required information varies depending on the trigger type.| Trigger Type | Input Item |
|---|
| API Gateway | - API name: You can select an existing API or create a new one
- Stage: You can select an existing stage or create a new one
|
| Cronjob | - Refer to the example and enter the trigger’s repeat frequency (minute, hour, day, month, day of week)
- Timezone setting: select the reference time zone to apply
|
| |
| Table. Required input items when adding a trigger | |
| |
6. After moving to the **Code** tab, click the **Edit** button. You will be taken to the **Function Code Edit** page.
7. After adding the processing logic for success and failure cases, click the **Save** button.
* Node.js source codeconst winston = require('winston');
// Log module setting
const logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(info => info.timestamp + ' ' + info.level + ': ' + info.message)
),
transports: [
new winston.transports.Console()
]
});
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
const response = {
statusCode: 200,
body: JSON.stringify(params.body),
};"
logger.info(JSON.stringify(response, null, 2));
return response;
};
const winston = require('winston');
// Log module setting
const logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(info => info.timestamp + ' ' + info.level + ': ' + info.message)
),
transports: [
new winston.transports.Console()
]
});
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
const response = {
statusCode: 200,
body: JSON.stringify(params.body),
};"
logger.info(JSON.stringify(response, null, 2));
return response;
};
Print logs - Node.js source code * Python source codeimport json
import logging
# Log module setting
logging.basicConfig(level=logging.INFO)
def handle_request(params):
# User writing area (Function details)
response = {
'statusCode': 200,
'body': json.dumps(params.json)
}
logging.info(response)
return response
import json
import logging
# Log module setting
logging.basicConfig(level=logging.INFO)
def handle_request(params):
# User writing area (Function details)
response = {
'statusCode': 200,
'body': json.dumps(params.json)
}
logging.info(response)
return response
Print logs - Python source code ## Check function call
**Function Details** page's **Configuration** tab after calling the **function URL**, check the log in the **Log** tab.[2023-09-07] 12:06:23] "host": "scf-xxxxxxxxxxxxxxxxxxxxx",
[2023-09-07] 12:06:23] "ce-id": "xxxxxxxxxxxxxxxxxxxxx",
[2023-09-07] 12:06:23] "ce-source": "xxxxxxxxxxxxxxxxxxxxx",
[2023-09-07] 12:06:23] "host": "scf-xxxxxxxxxxxxxxxxxxxxx",
[2023-09-07] 12:06:23] "ce-id": "xxxxxxxxxxxxxxxxxxxxx",
[2023-09-07] 12:06:23] "ce-source": "xxxxxxxxxxxxxxxxxxxxx",
Check function call response # Throw a custom error
Custom error occurrence (Throw a custom error) setting and function call example (function URL usage) is explained.
## Throw a custom error Setting
To set Throw a custom error, follow the steps below.
1. **All Services > Compute > Cloud Functions** Click the menu. Go to the **Service Home** page of Cloud Functions.
2. Click the **Function** menu on the **Service Home** page. Move to the **Function List** page.
3. **Function List** page, click the resource to set the trigger. **Function Details** page will be navigated.
4. **Trigger** tab after clicking, click the **Add Trigger** button. The **Add Trigger** popup window opens.
5. **Add Trigger** In the popup window, after selecting the **Trigger Type** item, enter the required information displayed at the bottom and click the **Confirm** button.
* Required information varies depending on the trigger type.| Trigger Type | Input Item |
|---|
| API Gateway | - API name: You can select an existing API or create a new one
- Stage: You can select an existing stage or create a new one
|
| Cronjob | - Refer to the example and enter the trigger’s repeat frequency (minute, hour, day, month, day of week)
- Timezone setting: select the time zone to apply
|
Table. Required input items when adding a trigger
6. After moving to the **Code** tab, click the **Edit** button. You will be taken to the **Function Code Edit** page.
7. After adding the processing logic for success and failure cases, click the **Save** button.
* Node.js source codeclass CustomError extends Error {
constructor(message) {
super(message);
this.name = 'CustomError';
}
}
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
throw new CustomError('This is a custom error!');
};
class CustomError extends Error {
constructor(message) {
super(message);
this.name = 'CustomError';
}
}
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
throw new CustomError('This is a custom error!');
};
Throw a custom error - Node.js source code * Python source codeclass CustomError(Exception):
def __init__(self, message):
self.message = message
def handle_request(parmas):
raise CustomError('This is a custom error!')
class CustomError(Exception):
def __init__(self, message):
self.message = message
def handle_request(parmas):
raise CustomError('This is a custom error!')
Throw a custom error - Python source code * PHP source code<?php
class CustomError extends Exception {
public function __construct($message) {
parent::__construct($message);
$this->message = $message;
}
}
function handle_request() {
throw new CustomError('This is a custom error!');
}
?>
<?php
class CustomError extends Exception {
public function __construct($message) {
parent::__construct($message);
$this->message = $message;
}
}
function handle_request() {
throw new CustomError('This is a custom error!');
}
?>
Throw a custom error - PHP source code ## Check function call
**Function Details** page's **Configuration** tab after calling the **function URL**, check for errors in the **Log** tab.
# Using Environment Variable
Using Environment Variable (Using Environment Variable) configuration and function call example (using function URL) is explained.
## Using Environment Variable Setup
To set Using Environment Variable, follow the steps below.
1. **All Services > Compute > Cloud Functions** Click the menu. Go to the **Service Home** page of Cloud Functions.
2. Click the **Function** menu on the **Service Home** page. Navigate to the **Function List** page.
3. **Function List** Click the resource to set the trigger on the page. **Function Details** Navigate to the page.
4. After clicking the **Trigger** tab, click the **Add Trigger** button. The **Add Trigger** popup opens.
5. **Add Trigger** In the popup window, after selecting the **Trigger Type** item, enter the required information displayed at the bottom and click the **Confirm** button.
* Required information varies depending on the type of trigger.| Trigger Type | Input Item |
|---|
| API Gateway | - API name: You can select an existing API or create a new one
- Stage: You can select an existing stage or create a new one
|
| Cronjob | - Refer to the example and enter the trigger’s repeat frequency (minute, hour, day, month, day of week)
- Timezone setting: select the reference time zone to apply
|
Table. Required input items when adding a trigger
6. After moving to the **Code** tab, click the **Edit** button. You will be taken to the **Function Code Edit** page.
7. After adding the processing logic for success and failure cases, click the **Save** button.
* Node.js source codeexports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
return process.env.test;
};
exports.handleRequest = async function (params) {
/**
* @description User writing area (Function details)
*/
return process.env.test;
};
Using Environment Variable - Node.js source code * Python source codeimport json
import os
def handle_request(params):
# User writing area (Function details)
return os.environ.get("test")
import json
import os
def handle_request(params):
# User writing area (Function details)
return os.environ.get("test")
Using Environment Variable - Python source code * PHP source codeimport json
def handle_request(params):
# User writing area (Function details)
return os.environ.get("test")
import json
def handle_request(params):
# User writing area (Function details)
return os.environ.get("test")
Using Environment Variable - PHP source code 9. After moving to the **Configuration** tab, click the **Edit** button in the **Environment Variable** area. The **Edit Environment Variable** popup window opens.
10. After entering the environment variable information, click the **Confirm** button.| Category | Detailed description |
|---|
| Name | Enter Key value |
| value | ValueEnter value |
Table. Environment Variable Input Items
## Check function call
**Function Details** page's **Configuration** tab, after calling the **Function URL**, check the environment variable values in the **Log** tab.
4 - PrivateLink Service Integration
By linking Cloud Functions and PrivateLink services, you can connect VPCs within the Samsung Cloud Platform and VPCs to services without external internet.
The data uses only the internal network, which enhances security, and does not require a public IP, NAT, VPN, internet gateway, etc.
PrivateLink Service Integration
You can expose the function via PrivateLink Service so that it can be accessed privately from another VPC.
To integrate the PrivateLink service, follow the steps below.
- All Services > Compute > Cloud Functions Click the menu. Navigate to the Service Home page of Cloud Functions.
- Click the Cloud Functions menu on the Service Home page. You will be taken to the Function list page.
- Click the resource to associate PrivateLink on the Function List page. It moves to the Function Details page.
- Click the Configuration tab on the Function Details page.
- Click the Edit button of PrivateLink Service in Private connection configuration. Edit PrivateLink Service popup window opens.
- PrivateLink Service Edit in the popup window, after checking the Use item of Activation Status, click the Confirm button. In the Configuration tab’s Private Connection Configuration, the PrivateLink Service information is displayed.
| Category | Detailed description |
|---|
| Private URL | PrivateLink Service URL information |
| PrivateLink Service ID | PrivateLink Service ID information |
| Request Endpoint Management | List of PrivateLink Endpoints that requested connection to PrivateLink Service- Endpoint ID and approval status
- Approval Management Click the button to change status
- Requesting: Endpoint that is requesting connection. Click Approve or Reject button to select approval
- Active: Endpoint with completed connection. Click Block button to disconnect
- Disconnected: Endpoint whose connection has been terminated. Click Reconnect button to connect
- Reject: Endpoint whose connection request was denied
|
Table. PrivateLink Service Detailed Information Items
PrivateLink Endpoint Create
Create an entry point to access the user’s VPC PrivateLink Service.
Caution
Additional costs may be incurred when creating an endpoint.
To create a PrivateLink Endpoint, follow these steps.
- All Services > Compute > Cloud Functions Click the menu. Go to the Service Home page of Cloud Functions.
- On the Service Home page, click the Cloud Functions menu. It navigates to the Function list page.
- Click the resource to associate with PrivateLink on the Function List page. You will be taken to the Function Details page.
- Click the Configuration tab on the Function Details page.
- Click the Add button of PrivateLink Endpoint in Configure Private Connection. Add PrivateLink Endpoint popup opens.
- PrivateLink Service Add in the popup window, after entering PrivateLink Service ID and Alias information, click the Confirm button.
- When the popup notifying creation opens, click the Confirm button. In the Configuration tab’s Private connection configuration, the PrivateLink Endpoint information is displayed.
| Category | Detailed description |
|---|
| PrivateLink Endpoint ID | PrivateLink Endpoint ID information |
| PrivateLink Service ID | PrivateLink Service ID information |
| Alias | Alias information |
| Status | Approval status of PrivateLink Endpoint- Requesting: Pending approval
- Active: Approved and connected
- Disconnected: Disconnected
- Reject: Approval denied. Click the Re-request button to request again
- Delete: Delete the endpoint
|
Table. PrivateLink Endpoint detailed information items