Serverless offline

KyungUp·2022년 10월 9일
0

AWS

목록 보기
1/3

요구 사항

nodejs 14.18.0 이상 필요
https://nodejs.org/dist/

Serverless 설치 (global)

$ npm install -g serverless

npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated superagent@7.1.6: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731)
/usr/local/bin/serverless -> /usr/local/lib/node_modules/serverless/bin/serverless.js
/usr/local/bin/sls -> /usr/local/lib/node_modules/serverless/bin/serverless.js

> es5-ext@0.10.62 postinstall /usr/local/lib/node_modules/serverless/node_modules/es5-ext
>  node -e "try{require('./_postinstall')}catch(e){}" || exit 0


> serverless@3.22.0 postinstall /usr/local/lib/node_modules/serverless
> node ./scripts/postinstall.js

Serverless Framework successfully installed!

To start your first project run “serverless”.

Turn on automatic updates by running “serverless config --autoupdate”.
+ serverless@3.22.0
added 416 packages from 333 contributors in 16.376s

serverless 혹은 sls 실행

$ sls

Creating a new serverless project

? What do you want to make? (Use arrow keys)
? 무엇을 만들고 싶습니까? (화살표 키 사용)

❯ AWS - Node.js - Starter 
  AWS - Node.js - HTTP API 
  AWS - Node.js - Scheduled Task 
  AWS - Node.js - SQS Worker 
  AWS - Node.js - Express API 
  AWS - Node.js - Express API with DynamoDB 
  AWS - Python - Starter 
  AWS - Python - HTTP API 
  AWS - Python - Scheduled Task 
  AWS - Python - SQS Worker 
  AWS - Python - Flask API 
  AWS - Python - Flask API with DynamoDB 
  Other
  
? What do you want to call this project? < your_project_name >
? 이 프로젝트를 무엇이라고 부르시겠습니까? < your_project_name >

✔ Project successfully created in aws-node-project folder
✔ aws-node-project 폴더에 프로젝트가 성공적으로 생성되었습니다.

? Do you want to login/register to Serverless Dashboard? No
? 서버리스 대시보드에 로그인/등록하시겠습니까? No

? Do you want to deploy now? No
? 지금 배포하시겠습니까? No

What next?
다음은?

Run these commands in the project directory:
프로젝트 디렉터리에서 다음 명령을 실행합니다.

serverless deploy    Deploy changes
serverless info      View deployed endpoints and resources
serverless invoke    Invoke deployed functions
serverless --help    Discover more commands

serverless-offline 설치 (plugin)

package.json 필요 (해당 파일 있을 경우 넘어 가주세요)

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (aws-node-http-api-project)
version: (1.0.0)
description:
entry point: (handler.js)
test command:
git repository:
keywords:
author:
license: (ISC)

...

Is this OK? (yes) yes
$ npm install serverless-offline --save-dev

npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated superagent@7.1.6: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect 
patch version (see https://github.com/visionmedia/superagent/issues/1731)

added 567 packages, and audited 568 packages in 32s

112 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
// serverless.yml 가장 하단 부분에 추가 해주세요
plugins:
  - serverless-offline

serverless offline 혹은 sls offline 실행

$ serverless offline start

Starting Offline at stage dev (us-east-1)

Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
           * hello: aws-node-project-dev-hello

   ┌─────────────────────────────────────────────────────────────────────────┐
   │                                                                         │
   │   GET | http://localhost:3000/dev/hello                                 │
   │   POST | http://localhost:3000/2015-03-31/functions/hello/invocations   │
   │                                                                         │
   └─────────────────────────────────────────────────────────────────────────┘

Server ready: http://localhost:3000 🚀

메소드 확인

샘플 코드

https://github.com/wonkyungup/serverless-template/tree/serverless-offline

profile
Last Epoch하고싶다

0개의 댓글