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
๋ณต์ฌ