
$ npm install -g serverless
설치 후 버전 확인
$ sls -version
$ sls login
위 명령어를 통해 로그인 할 수 있다
Serverless 플랫폼에 로그인을 하고 나중에 배포를 하게 된다면, 그동안 배포한 함수와 함수들을 위한 문서들도 확인가능
$ serverless config credentials --provider aws --key 액세스키ID --secret 비밀액세스키
Serverless: Setting up AWS...
Serverless: Saving your AWS profile in "~/.aws/credentials"...
Serverless: Success! Your AWS access keys were stored under the "default" profile.
$ sls create -t
Serverless: Generating boilerplate...
Serverless Error ---------------------------------------
Template "true" is not supported. Supported templates are: "aws-nodejs", "aws-nodejs-typescript", "aws-nodejs-ecma-script", "aws-python", "aws-python3", "aws-groovy-gradle", "aws-java-maven", "aws-java-gradle", "aws-kotlin-jvm-maven", "aws-kotlin-jvm-gradle", "aws-kotlin-nodejs-gradle", "aws-scala-sbt", "aws-csharp", "aws-fsharp", "aws-go", "aws-go-dep", "azure-nodejs", "google-nodejs", "kubeless-python", "kubeless-nodejs", "openwhisk-nodejs", "openwhisk-php", "openwhisk-python", "openwhisk-swift", "spotinst-nodejs", "spotinst-python", "spotinst-ruby", "spotinst-java8", "webtasks-nodejs", "plugin" and "hello-world".
$ sls create -t aws-nodejs -p 프로젝트명이름
Serverless: Generating boilerplate...
Serverless: Generating boilerplate in "/Users/example/test"
_______ __
| _ .-----.----.--.--.-----.----| .-----.-----.-----.
| |___| -__| _| | | -__| _| | -__|__ --|__ --|
|____ |_____|__| \___/|_____|__| |__|_____|_____|_____|
| | | The Serverless Application Framework
| | serverless.com, v1.26.0
-------'
Serverless: Successfully generated boilerplate for template: "aws-nodejs"
$ serverless invoke local --function hello
{
"statusCode": 200,
"body": "{\"message\":\"Go Serverless v1.0! Your function executed successfully!\",\"input\":\"\"}"
}
region과 stage를 설정한다. region의 경우엔 AWS에서 배포할 지역을 설정한다. 기본적으로는 미국으로 설정되니, 이 값을 ap-northeast-2 로 입력하여 한국으로 변경한다. stage 는 현재 애플리케이션의 배포 상태를 의미하고 prod 로 하거나, dev로 설정할 수 있다.
service: hello-serverless
provider:
name: aws
runtime: nodejs6.10
stage: dev
region: ap-northeast-2
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
함수 배포시에는 sls deploy 명령어를 입력
$ sls deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (409 B)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..........
Serverless: Stack update finished...
Service Information
service: hello-serverless
stage: dev
region: ap-northeast-2
stack: hello-serverless-dev
api keys:
None
endpoints:
GET - https://4mmtbsr9eg.execute-api.ap-northeast-2.amazonaws.com/dev/hello
functions:
hello: hello-serverless-dev-hello
Serverless: Publish service to Serverless Platform...
Service successfully published! Your service details are available at:
https://platform.serverless.com/services/velopert/hello-serverless
AWS Lambda → 애플리케이션 에서 배포 상태를 확인가능