Skip to content

AWS SAMの Lambda + API Gatwayで 引数をGETメソッドとPOSTメソッドで渡すサンプル。Python 3.9

Notifications You must be signed in to change notification settings

heiwa4126/sam-hello-who

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sam-hello-who

AWS SAMの Lambda + API Gatwayで 引数をGETメソッドとPOSTメソッドで渡すサンプル。

Python 3.9

中身は"Hello {who}\n"を出すだけです。 (whoが引数)

デプロイ

sam build
sam deploy --guided  # --guidedは最初の1回

sam deploy --guided

HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: y

以外はデフォルトでいいです。

デプロイが終わったら

./export1.sh  # 実行にはjqとyqとaws cliが必要

で、APIのURLを .export.sh に書き出してください。

テストの実行

./get_test.sh  # GETメソッドでテスト
./post_test.sh # POSTメソッドでテスト

スタックの削除

sam delete --no-prompts

で消えます。

メモ

post_test.shにかかれていますが、 APIゲートウエイにbody送るのには application/jsonにする必要があります。 で、bodyはJSONで。

JSONでない場合event.bodyが空になります(NilやらNONEやら)。

API Gatewayのコンソールからテストするときも、 POSTの方は「リクエスト本文」のところにJSONを書くこと。

About

AWS SAMの Lambda + API Gatwayで 引数をGETメソッドとPOSTメソッドで渡すサンプル。Python 3.9

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published