serverless-navercloud
v1.0.4
Published
Provider plugin for the Serverless Framework
Downloads
6
Readme
Serverless Naver Cloud Plugin
This plugin enables Naver CloudFunctions support within the Serverless Framework.
Getting Started
Register account with Naver Cloud
Before you can deploy your service to Naver Cloud, you need to have an account registered.
Set up account credentials
Use the following environment variables to be pass in account credentials.
NCLOUD_ACCESS_KEY
NCLOUD_SECRET_KEY
Create Service From template
TODO
Need to deploy to specific region?
Ensure you set the region
option in the serverless.yaml prior to deployment. Default value for this option is kr.
provider:
name: navercloud
region: jp
Supported regions are
- kr
- jp
- sg
- gov
- fin
Deploy Service
serverless deploy
Test Service
Once you deployed functions with serverless deploy
, you can also invoke the functions with the following CLI.
serverless invoke -f <functionName>
Invoke Options
-f
or--function
- Function to Invoke--timeout
- Set the timeout of http call to invoke function in ms
- With too short timeout, you may see only
activationId
without the result of invoking function - Default value for this option is 60000
--verbose
- With this option, serverless framework shows all the result of invoking function
-d
or--data
- Specify runtime parameters of deployed functions to invoke
- String data in JSON format
-p
or--path
- Specify the path to a JSON file which has input data to be passed to a function
- Support both absolute path and relative path
Example
serverless invoke -f hello
serverless invoke -f hello --timeout 10000
serverless invoke -f hello --verbose
serverless invoke -f hello --verbose --timeout 30000
serverless invoke -f hello -d '{"name":"Naver Cloud"}'
serverless invoke -f hello -p ./data.json
You may also pass input data from stdin to a function. The data should be a string in JSON format.
echo '{"name":"Naver Cloud"}' | serverless invoke -f hello
Writing Functions - Node.js
Here's an index.js
file containing an example handler function.
function main(params) {
const name = params.name || 'World';
return {payload: 'Hello, ' + name + '!'};
};
exports.main = main;
Modules should return the function handler as a custom property on the global exports
object.
functions:
my_function:
handler: index.main
runtime: nodejs:12
Using NPM Modules
NPM modules must be installed locally in the node_modules
directory before deployment. This directory will be packaged up in the deployment artefact. Any dependencies included in node_modules
will be available through require()
in the runtime environment.
const leftPad = require("left-pad")
function pad_lines(args) {
const lines = args.lines || [];
return { padded: lines.map(l => leftPad(l, 30, ".")) }
};
exports.handler = pad_lines;
Writing Functions - Python
Here's an index.py
file containing an example handler function.
def endpoint(params):
name = params.get("name", "stranger")
greeting = "Hello " + name + "!"
print(greeting)
return {"greeting": greeting}
In the serverless.yaml
file, the handler
property is used to denote the source file and module property containing the serverless function.
functions:
my_function:
handler: index.endpoint
runtime: python:3.6
Deleting a Service
serverless remove
Logging
If you want to see invocation logs or function stdout/stderr log of your function, you can also run logs
CLI.
serverless logs -f <functionName>
Logs Options
--pageNo
- Set which page to retrieve
- Default value for this option is 1
--pageSize
- Set the number of logs to fit on a page
- Default value for this option is 20
--start
- Set the starting point of the logs to retrieve
- KST for KR region / SST for SG region
--end
- Set the end point of the logs to retrieve
- KST for KR region / SST for SG region
-t
or--tail
- Defines whether serverless framework keeps waiting for new logs
- If new logs fit to the options generated, serverless framework shows them.
Example
serverless logs -f hello
serverless logs -f hello --pageNo 2 --pageSize 3
serverless logs -f hello --start 2022-12-15T15:00:00 --end 2022-12-15T16:30:00
serverless logs -f hello --tail
serverless logs -f hello --pageNo 2 --end 2022-12-15T14:00:00 -t
Acknowledgement
This Library contains some code from the projects below
- https://github.com/serverless/serverless-azure-functions (MIT license)
- https://github.com/serverless/serverless-openwhisk (MIT license)
License
Copyright 2023-present NAVER Cloud Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.