LoginSignup
0
0

More than 1 year has passed since last update.

SAM CLIでテンプレートを別名指定した時のmodule入りLambdaの注意点

Posted at

はじめに

  • SAMでLambdaを作成する時、コードのディレクトリにrequirements.txtを配置すると自動的にmoduleを拾ってきてくれる
  • SAMでTemplate名を標準外のもので作成することもでき、その時は-t [template path] / --template-file [template path]で指定できる
    • コードは一緒で環境毎に内容を分けたいときとか
  • このときに普通に以下のようなコマンドで実行するとmoduleがいないLambdaが上がってしまう
sam build -t template.dev-env.yaml
sam package --profile dev -t template.dev-env.yaml --s3-bucket artifact-no-bucket --output-template-file packaged.yaml
sam deploy -t packaged.yaml ~~~~~

解決方法

  • sam buildを実行すると.aws-sam/build/配下にmoduleが入った各種Lambdaがtemplateで指定したものごとにディレクトリを分けて出力される
  • .aws-sam/build/template.yamlにはその出力されたディレクトリをCodeUriに指定した形のtemplateが出力されている
    • つまりsam packageのときに.aws-sam/build/template.yamlをtemplateに指定してあげればよかった
sam build -t template.dev-env.yaml
sam package --profile dev -t .aws-sam/build/template.yaml --s3-bucket artifact-no-bucket --output-template-file packaged.yaml
                              ^^^このあたりのパスを変えた^^^
sam deploy -t packaged.yaml ~~~~~
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