1
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?

Windows 上で AWS をローカル開発できる環境を構築する(4)

1
Last updated at Posted at 2026-04-15

Windows 上で AWS をローカル開発できる環境を構築する(4)

LocalStack の無料版では HTTP API(API Gateway v2)が未実装のため、ここでは REST API(v1)を使って hello Lambda を呼び出します。

1. API Gatewayを追加

ファイル修正
docker-compose.yaml

    environment:
      - SERVICES=lambda,s3,ssm,secretsmanager,apigateway
      - DEBUG=1

Docker を再起動して反映してください。

※ LocalStack(無料版)は永続化されないため、Docker を再起動すると
それまでに作成した Lambda や API Gateway の設定はリセットされます。

2. REST API のIDを作成

REST API の ID を環境変数 API_ID に保存します。

$ API_ID=$(awslocal apigateway create-rest-api \
  --name hello-api \
  --query 'id' \
  --output text)

3. ルートリソース(/)の IDを取得

ルート(/)に相当するリソース ID を ROOT_ID に保存します。

$ ROOT_ID=$(awslocal apigateway get-resources \
  --rest-api-id $API_ID \
  --query 'items[0].id' \
  --output text)

4. 子リソース /hello のIDを作成

作成した /hello リソースの ID を環境変数 HELLO_ID に保存します。

$ HELLO_ID=$(awslocal apigateway create-resource \
  --rest-api-id $API_ID \
  --parent-id $ROOT_ID \
  --path-part hello \
  --query 'id' \
  --output text)

5. GET メソッドを作成

保存した /hello リソース ID(HELLO_ID)に対して GET メソッドを設定します。

$ awslocal apigateway put-method \
  --rest-api-id $API_ID \
  --resource-id $HELLO_ID \
  --http-method GET \
  --authorization-type "NONE"

6. Lambda と統合(Lambda Proxy Integration)

GET メソッドのバックエンドとして hello Lambda を統合します。

$ awslocal apigateway put-integration \
  --rest-api-id $API_ID \
  --resource-id $HELLO_ID \
  --http-method GET \
  --type AWS_PROXY \
  --integration-http-method POST \
  --uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:000000000000:function:hello/invocations

7. Lambda に API Gateway からの呼び出し権限を付与

API Gateway が hello Lambda を実行できるように権限を設定します。

$ awslocal lambda add-permission \
  --function-name hello \
  --statement-id apigw \
  --action lambda:InvokeFunction \
  --principal apigateway.amazonaws.com

8. デプロイを実行

API を dev ステージとしてデプロイします。

$ awslocal apigateway create-deployment \
  --rest-api-id $API_ID \
  --stage-name dev

9. 呼び出し URL を確認

作成した REST API の呼び出し URL を確認します。

$ echo "http://localhost:4566/restapis/$API_ID/dev/_user_request_/hello"

10. 実際に呼び出す

curl で API Gateway 経由の Lambda 実行結果を確認します。

$ curl http://localhost:4566/restapis/$API_ID/dev/_user_request_/hello

出力例

{"message":"Hello from LocalStack Lambda!"}

以上です。

1
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
1
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?