【Serverless】Serverless Framework ~ 入門編 ~

■ はじめに

https://dk521123.hatenablog.com/entry/2023/11/02/000200

の続き。

今回は、サービス作成~サービス削除まで、
Hello worldしてみる

目次

【1】AWSアカウントの設定
【2】サービス作成
【3】サービスのデプロイ
【4】Lambdaの実行
【5】サービスの削除

【1】AWSアカウントの設定

serverless config credentials \
    --provider aws \
    --key <ACCESS_KEY> \
    --secret <SEACRET_KEY> \
    --profile <APP_NAME>

# --provider: プロバイダーを指定。AWSならaws
# --key: アクセスキーを指定
# --secret: シークレットキーを指定
# --profile: アプリ名を指定(任意)
# --overwrite: 上書き指定(任意)

https://www.serverless.com/framework/docs/providers/aws/cli-reference/config-credentials
参考文献
https://blog.aimless.jp/archives/2016-12-21-the-trouble-of-serverless-framework-credentials/
https://forestbook-freelance.com/2021/03/12/serverless-framework-aws/

【2】サービス作成

# serverless create --template <TEMPLATE> --name <SERVICE_NAME>
serverless create --template aws-python3 --name hello-world

https://www.serverless.com/framework/docs/providers/aws/cli-reference/create

【3】サービスのデプロイ

serverless deploy -v

https://www.serverless.com/framework/docs/providers/fn/cli-reference/deploy
serverless.yml
https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml

service: hello-world

frameworkVersion: '3'

provider:
  name: aws
  # https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/lambda-runtimes.html
  runtime: python3.11
  stage: dev
  # AWS Region
  region: us-west-2
  tags:
    foo: bar
    baz: qux
functions:
  hello:
    handler: handler.hello

【4】Lambdaの実行

serverless invoke -f hello -d '{"test":"test"}'

【5】サービスの削除

# -v: --verbose
sls remove -v

https://www.serverless.com/framework/docs/providers/aws/cli-reference/remove

参考文献

https://qiita.com/t_okkan/items/6843afba84d684068341
https://dev.classmethod.jp/articles/serverless-deploy-aws-whats-going-on/
https://gkuga.hatenablog.com/entry/2022/06/10/080000

関連記事

Serverless Framework ~ 環境設定編 ~
https://dk521123.hatenablog.com/entry/2023/11/02/000200
Serverless Framework ~ offline ~
https://dk521123.hatenablog.com/entry/2023/11/09/004458
Lambda ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2017/04/05/235618
Lambda ~ Python / 入門編 ~
https://dk521123.hatenablog.com/entry/2021/10/07/103317