LoginSignup
0
0

More than 1 year has passed since last update.

samでlambdaのデプロイ

Last updated at Posted at 2021-08-23

目次

・samの導入
・sam init
・sam build
・samconfig.tomlの作成
・sam deploy

samの導入

brewによるインストール

$ brew tap aws/tap
$ brew install aws-sam-cli

もしくはpipによるインストール

$ pip install aws-sam-cli

sam init

対話形式でプロジェクトを作成します。

$ sam init
Which template source would you like to use?
        1 - AWS Quick Start Templates
        2 - Custom Template Location
Choice: 1
What package type would you like to use?
        1 - Zip (artifact is a zip uploaded to S3)
        2 - Image (artifact is an image uploaded to an ECR image repository)
Package type: 1

Which runtime would you like to use?
        1 - nodejs14.x
        2 - python3.8
        3 - ruby2.7
        4 - go1.x
        5 - java11
        6 - dotnetcore3.1
        7 - nodejs12.x
        8 - nodejs10.x
        9 - python3.7
        10 - python3.6
        11 - python2.7
        12 - ruby2.5
        13 - java8.al2
        14 - java8
        15 - dotnetcore2.1
Runtime: 1

Project name [sam-app]: Test

Cloning from https://github.com/aws/aws-sam-cli-app-templates

AWS quick start application templates:
        1 - Hello World Example
        2 - Step Functions Sample App (Stock Trader)
        3 - Quick Start: From Scratch
        4 - Quick Start: Scheduled Events
        5 - Quick Start: S3
        6 - Quick Start: SNS
        7 - Quick Start: SQS
        8 - Quick Start: Web Backend
Template selection: 1

    -----------------------
    Generating application:
    -----------------------
    Name: Test
    Runtime: nodejs14.x
    Dependency Manager: npm
    Application Template: hello-world
    Output Directory: .

    Next steps can be found in the README file at ./Test/README.md

sam local invoke

簡易的なプロジェクトが立ち上がったので、さっそく動かしてみます。

$ sam local invoke
{"statusCode":200,"body":"{\"message\":\"hello world\"}"}

dockerが立ち上がってローカル環境による検証をすることができます。

$ sam local invoke -e path/event.json

-eを指定するとlambdaが実行される時のイベント情報を指定して実行させることができます。

samconfig.tomlの作成

$ sam deploy --guided

対話形式でデプロイ設定ファイルsamconfig.tomlを作成します。

sam deploy

$ cd .aws-sam/build
$ sam deploy

これでデプロイが成功すればOKです。

CloudFormationの管理コンソールからデプロイの確認ができます。
また、Lambdaでは関数の実行をテストすることもできます。

いろいろ試すことができるので、情報がまとまり次第更新していきます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0