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. |
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 triggerAfter 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 codeColor mode
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 codeColor mode
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 codeColor mode
<?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
- Node.js 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
Color mode
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
Color mode
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 codeColor modeimport 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 valueColor mode{
"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 valueColor mode{
"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 codeColor modeconst 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 codeColor modeimport 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.Color mode<!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 codeColor modeconst 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 codeColor modeimport 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.Color mode[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 trigger6. 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 codeColor modeclass 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 codeColor modeclass 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 codeColor mode<?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 trigger6. 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 codeColor modeexports.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 codeColor modeimport 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 codeColor modeimport 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.