0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS CDKで作成したAPIGateway+Lambda(Node18)をローカルで動かしてみたメモ

Last updated at Posted at 2023-06-08

概要

前々回前回はベータ版を試したが、ベータ版が取れていたので試した。(参考: ローカルでのテスト)

ソースコード

環境

  • 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でデフォルトでは実行される。
警告が赤字で出ているが、本番では使わないでくれ、みたいな意味なので問題ない。

image.png

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
} 
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?