Skip to content

yuta3003/amazon-q-develop-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Gateway と Lambda を使用した API の構築

このプロジェクトは 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 がインストール済み

セットアップ手順

  1. 依存関係のインストール:
pip install -r requirements.txt
  1. CDK の初期化 (初回のみ):
cdk bootstrap
  1. デプロイ:
cdk deploy

デプロイが完了すると、API Gateway の URL が出力されます。

テスト実行方法

単体テストを実行するには:

pytest

API の使用方法

GET リクエスト

curl https://your-api-id.execute-api.region.amazonaws.com/prod/api

POST リクエスト

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors