Search
๐Ÿ’ท

Serverless Framework

Serverless Framework??

์‚ฌ์ „ ์กฐ๊ฑด

โ€ข
Node.js v12+

์„ค์น˜

npm install -g serverless
Bash
๋ณต์‚ฌ

AWS Credentials ์„ค์ •ํ•˜๊ธฐ

IAM User, Access Key ์ƒ์„ฑ

์„œ๋ฒ„๋ฆฌ์Šค ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด ์ •์ฑ…(Policy)์€ AdministratorAccess ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์‹ค ์šด์˜ ํ™˜๊ฒฝ์—์„œ๋Š” ์ •์ฑ…(Policy)์„ ์ œํ•œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ฐธ๊ณ : ์ •์ฑ…

AWS Access Keys ์‚ฌ์šฉ

ํ™˜๊ฒฝ ๋ณ€์ˆ˜

# Mac / Linux $ export AWS_ACCESS_KEY_ID=<your-key-here> $ export AWS_SECRET_ACCESS_KEY=<your-secret-key-here> # Windows $ set AWS_ACCESS_KEY_ID=<your-key-here> $ set AWS_SECRET_ACCESS_KEY=<your-secret-key-here>
Bash
๋ณต์‚ฌ

serverless config credential ๋ช…๋ น์–ด

$ serverless config credentials \ --provider aws \ --key <your-key-here>\ --secret <your-secret-key-here>
Bash
๋ณต์‚ฌ

AWS CLI

$ aws configure AWS Access Key ID [None]: <your-key-here> AWS Secret Access Key [None]: <your-secret-key-here> Default region name [None]: us-west-2 Default output format [None]: ENTER
Bash
๋ณต์‚ฌ

Hello World

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

$ sls create --template aws-nodejs --path helloworld โœ” Project successfully created in "helloworld" from "aws-nodejs" template (4s)
Bash
๋ณต์‚ฌ

ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ

helloworld โ”œโ”€โ”€ handler.js โ””โ”€โ”€ serverless.yml
Bash
๋ณต์‚ฌ

serverless.yml

service: helloworld frameworkVersion: '3' provider: name: aws runtime: nodejs12.x functions: hello: handler: handler.hello
Bash
๋ณต์‚ฌ

handler.js

'use strict'; module.exports.hello = async (event) => { return { statusCode: 200, body: JSON.stringify( { message: 'Go Serverless v1.0! Your function executed successfully!', input: event, }, null, 2 ), }; };
Bash
๋ณต์‚ฌ

๋ฐฐํฌ(Deploy)

$ sls deploy Deploying helloworld to stage dev (us-east-1) โœ” Service deployed to stack helloworld-dev (109s) functions: hello: helloworld-dev-hello (392 B) Need a better logging experience than CloudWatch? Try our Dev Mode in console: run "serverless --console"
Bash
๋ณต์‚ฌ
โ€ข
Lambda > Functions

Lambda ํ•จ์ˆ˜ ํ˜ธ์ถœ

$ sls invoke -f hello { "statusCode": 200, "body": "{\n \"message\": \"Go Serverless v1.0! Your function executed successfully!\",\n \"input\": {}\n}" }
Bash
๋ณต์‚ฌ

์‚ญ์ œ(Remove)

$ sls remove Removing helloworld from stage dev (us-east-1) โœ” Service helloworld has been successfully removed (23s)
Bash
๋ณต์‚ฌ