概要
前々回と前回はベータ版を試したが、ベータ版が取れていたので試した。(参考: ローカルでのテスト)
環境
- Windows 10
- docker desktop v4.19.0
- aws-cdk 2.83.0
- sam-cli 1.84.0 ※
※ 2023/06/08 sam-cliの最新バージョンは1.86.1だが、 docker の 変更 と sam-cliの変更がコンフリクトしているらしく、Error: request() got an unexpected keyword argument 'chunked'"
のエラーが出て動作しなかった。 Issues。
1.84.0をDLし、ダウングレードしたところ、うまくいった。
実践
まずはsynthでcdk.outにCloudFrontテンプレートを出力する。
cdk -a \"npx ts-node --prefer-ts-exts bin/rest.ts\" synth rinne-circle-RineCircleRESTAPIStack
つぎに、SAMでローカル起動する。
指定するテンプレートはスタック名で作成されている。
sam local start-api -t ./cdk.out/rinne-circle-RineCircleRESTAPIStack.template.json
下記のようにhttp://127.0.0.1:3000
でデフォルトでは実行される。
警告が赤字で出ているが、本番では使わないでくれ、みたいな意味なので問題ない。
RESTを投げて、動作することを確認した。
put http://127.0.0.1:3000/api/scenario
{
"id": "xxxxxxx-xxxx-4dff-be34-xxxxxxx",
"authorId": "test",
"title": "シナリオタイトル",
"imageUrl": "/scenarioTitle.png",
"path": "/scenario.json",
"published": true
}