このプロジェクトは AWS CDK を使用して、Amazon API Gateway と AWS Lambda による REST API を構築します。Lambda 関数は Python で実装されています。
.
├── README.md # このファイル
├── app.py # CDK アプリケーションのエントリーポイント
├── api_gateway_lambda/ # CDK スタック定義
│ ├── __init__.py
│ └── api_gateway_lambda_stack.py
├── lambda/ # Lambda 関数のコード
│ └── api_handler.py
├── tests/ # テストコード
│ └── unit/
│ ├── test_api_gateway_lambda_stack.py
│ └── test_lambda_handler.py
├── requirements.txt # Python 依存関係
└── setup.py # セットアップスクリプト
- API Gateway を通じて
/apiエンドポイントを公開 - GET リクエスト: 現在の時刻とメッセージを返す
- POST リクエスト: 送信されたデータを受け取り、確認メッセージを返す
- AWS CLI がインストールされ、設定済み
- Python 3.6 以上
- AWS CDK v2 がインストール済み
- 依存関係のインストール:
pip install -r requirements.txt- CDK の初期化 (初回のみ):
cdk bootstrap- デプロイ:
cdk deployデプロイが完了すると、API Gateway の URL が出力されます。
単体テストを実行するには:
pytestcurl https://your-api-id.execute-api.region.amazonaws.com/prod/apicurl -X POST \
https://your-api-id.execute-api.region.amazonaws.com/prod/api \
-H 'Content-Type: application/json' \
-d '{"name": "Test User", "message": "Hello API"}'リソースを削除するには:
cdk destroy