본문 바로가기
AWS

서버리스 프레임워크 사용법 Serverless Framework

by DOSGamer 2022. 9. 20.
반응형

기초사용법

정의

서버리스 프로그램을 편하게 할 수 있도록 도와주는 Framework (Node.js 기반)

경쟁제품 : Python 기반의 Zappa, AWS 의 SAM 이 있다

Serverless Framework 는 경쟁제품보다 오래 되어 사용처가 많고, 커뮤니티도 활발하다

지원하는 Cloud 밴더로 다양하다

sls create --help

설치

#Step 1. Install serverless globally
npm install serverless -g

#Step 2. Create a serverless function
serverless create --template aws-nodejs --path my-service

cd my-service

#Step 3. Deploy to cloud provider
serverless deploy -v

#Step 4-1. Invoke the Function on cloud provider
serverless invoke -f hello -l

#Step 4-2. Invoke the Function on your local machine
serverless invoke local -f hello -l

#Step 5. Fetch the Function Logs
serverless logs -f hello -t

#Step 6. Remove the Service
serverless remove

Boilerplate

Dynobase/serverless-dynamodb-api-boilerplate
Kickstart your Cloud-native and Serverless project in minutes. This is work in progress This repository is a result of many lessons from launching variety of Serverless powered applications to the production. It was created according to many best practices and aims to provide developers a rapid start while also being production-ready.
https://github.com/Dynobase/serverless-dynamodb-api-boilerplate
anishkny/realworld-dynamodb-lambda
AWS DynamoDB + Lambda codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API. This codebase was created to demonstrate a fully fledged fullstack application built with AWS DynamoDB + Lambda including CRUD operations, authentication, routing, pagination, and more.
https://github.com/anishkny/realworld-dynamodb-lambda

동일한 repository 에서 server 와 client 배포 하는 방법

tree 구조

samplefolder
│  package.json
│  serverless.yml
│
├─client
│  │  babel.config.js
│  │  package.json
│  │  vue.config.js
│  │
│  ├─public
│  └─src
└─server
    │  .eslintrc.js
    │  package.json
    │
    └─src

root 의 package.json

	"devDependencies": {
    "serverless-apig-s3": "^2.0.0"
  },
  "scripts": {
    "package:server": "serverless package --stage production",
    "deploy:server": "serverless deploy --stage production",
    "deploy:client": "cd client && npm run build && cd .. && serverless client deploy --stage production",
    "postinstall": "cd client && npm install && cd .. && cd server && npm install && cd .."
  },

root 의 serverless.yml

package:
  exclude:
    # Exclude everything!
    - "*/**"
  include:
    # Source files
    - "server/src/rest/**"
    - "server/src/utils/**"
    # Dependencies bcryptjs + jsonwebtoken
    - "server/node_modules/bcryptjs/**"
    - "server/node_modules/buffer-equal-constant-time/**"
    - "server/node_modules/ecdsa-sig-formatter/**"
    - "server/node_modules/jsonwebtoken/**"
    - "server/node_modules/jwa/**"
    - "server/node_modules/jws/**"
    - "server/node_modules/lodash*/**"
    - "server/node_modules/ms/**"
    - "server/node_modules/safe-buffer/**"

참조포스트

matusnovak/serverless-aws-node-bootstrap-vue
This is a Serverless example using Node.js as the backend and Bootstrap-vue (Bootstrap 4 + Vue.js 2.4 - without webpack) as the front end. This is a slightly more advanced example showing a simple Post/Comment web app, including user authentication. Additionally, both the front end nad back end are served through the API Gateway, no need to use AWS CloudFront.
https://github.com/matusnovak/serverless-aws-node-bootstrap-vue

Uploaded by N2T

반응형

'AWS' 카테고리의 다른 글

AWS DynamoDB 참고사이트  (0) 2022.08.26
AWS를 도커로 설정하기  (0) 2022.08.26
puppeteer + lambda 조합으로 사용법  (0) 2022.08.26
IAM 정책  (0) 2022.08.24
Underneath DynamoDB  (0) 2022.08.24
CodeCommit  (0) 2022.08.24
DynamoDB  (0) 2022.08.24
API authorizers  (0) 2022.08.24