用途
awsclaw-apigateway 是 awsclaw VS Code 扩展提供的 APIGatewayTool 语言工具,用于在 VS Code 中管理、检查和测试 AWS API Gateway 的 REST API。它面向需要查看或操作 API Gateway 各类资源的开发者与运维人员。
主要能力
工具共提供 68 个命令,可分为以下几类:
- 查询与检查:列出或获取 REST API、资源、方法、集成、集成响应、方法响应、阶段、部署、阶段变量、授权方、使用计划、API 密钥、配额、自定义域名、基础路径映射、VPC 链接、模型、请求验证器、文档部件与版本、网关响应、客户端证书、标签、账户设置等。
- 测试调用:TestInvokeMethod 可在不部署的情况下测试调用某个方法;TestInvokeAuthorizer 可测试授权方行为。
- 创建与更新:创建 REST API、资源、方法、部署、阶段、授权方、API 密钥、使用计划、自定义域名;从 Swagger/OAS 导入 REST API;更新 REST API 与阶段。
- 删除:删除 REST API、资源、方法、阶段、授权方、API 密钥、使用计划、自定义域名。
- 导出与 SDK:GetExport 可将 API 导出为 Swagger/OAS 文件;GetSdk、GetSdkType、GetSdkTypes 用于获取 SDK 产物与类型。
- 标签:TagResource 与 UntagResource 用于为 API Gateway 资源添加或移除标签。
使用方式
工具通过如下输入结构调用:
{
"command": "<CommandName>",
"params": { ... }
}
常用参数包括 restApiId、resourceId、httpMethod、stageName、authorizerId、usagePlanId、keyId、domainName、statusCode、limit、position、name、headers、multiValueHeaders、pathWithQueryString、body、stageVariables、additionalContext、includeCredentials 等。其中 restApiId 被大多数针对特定 API 的 Get 命令所要求;resourceId 与 httpMethod 被 GetIntegration、GetIntegrationResponse、GetMethod、GetMethodResponse、GetResource、TestInvokeMethod 等命令要求;stageName 被 GetStage 要求;authorizerId 被 GetAuthorizer、TestInvokeAuthorizer 要求;usagePlanId 被 GetUsagePlan、GetUsagePlanKey、GetUsagePlanKeys 要求;keyId 被 GetUsagePlanKey 要求;domainName 被 GetDomainName、GetBasePathMapping、GetBasePathMappings 要求;statusCode 被 GetMethodResponse 要求;limit 与 position 用于列表类命令的分页;name 用于 GetApiKeys、GetRestApis 的名称过滤;headers、multiValueHeaders、pathWithQueryString、body、stageVariables 用于测试调用;additionalContext 用于授权方测试;includeCredentials 用于 GetExport。
示例:
列出所有 REST API:
{ "command": "GetRestApis", "params": { "limit": 25 } }
获取特定 API 详情:
{ "command": "GetRestApi", "params": { "restApiId": "abc123def" } }
列出某 API 的资源:
{ "command": "GetResources", "params": { "restApiId": "abc123def", "limit": 100 } }
获取特定方法:
{ "command": "GetMethod", "params": { "restApiId": "abc123def", "resourceId": "xyz789", "httpMethod": "GET" } }
获取集成详情:
{ "command": "GetIntegration", "params": { "restApiId": "abc123def", "resourceId": "xyz789", "httpMethod": "POST" } }
列出阶段:
{ "command": "GetStages", "params": { "restApiId": "abc123def" } }
获取特定阶段:
{ "command": "GetStage", "params": { "restApiId": "abc123def", "stageName": "prod" } }
列出部署:
{ "command": "GetDeployments", "params": { "restApiId": "abc123def", "limit": 10 } }
测试调用方法:
{ "command": "TestInvokeMethod", "params": { "restApiId": "abc123def", "resourceId": "xyz789", "httpMethod": "GET", "pathWithQueryString": "/items?category=books" } }
带请求体测试调用方法:
{ "command": "TestInvokeMethod", "params": { "restApiId": "abc123def", "resourceId": "xyz789", "httpMethod": "POST", "pathWithQueryString": "/items", "body": "{\"name\": \"test\", \"price\": 9.99}", "headers": { "Content-Type": "application/json" } } }
测试调用授权方:
{ "command": "TestInvokeAuthorizer", "params": { "restApiId": "abc123def", "authorizerId": "auth001", "headers": { "Authorization": "Bearer eyJ..." } } }
列出授权方:
{ "command": "GetAuthorizers", "params": { "restApiId": "abc123def" } }
列出使用计划:
{ "command": "GetUsagePlans", "params": { "limit": 10 } }
列出 API 密钥:
{ "command": "GetApiKeys", "params": { "limit": 20 } }
获取自定义域名:
{ "command": "GetDomainNames", "params": { "limit": 10 } }
获取 VPC 链接:
{ "command": "GetVpcLinks", "params": { "limit": 10 } }
适用场景
- 在 VS Code 中快速浏览和排查 API Gateway 的 REST API 结构。
- 查看方法如何与后端集成(GetMethod 配合 GetIntegration)。
- 在不部署或创建阶段的情况下调试方法(TestInvokeMethod)。
- 验证授权方行为而不发起真实 API 调用(TestInvokeAuthorizer)。
- 审计 API 密钥的限流与配额(GetUsagePlans 配合 GetUsagePlanKeys)。
- 查看各阶段的部署历史与阶段变量(GetStages)。
- 导出 API 为 Swagger/OAS 或获取 SDK 产物。
与其他 AWS 服务的关系
API Gateway 可与多个 AWS 服务集成,资料中列出的关联工具包括:LambdaTool(Lambda 代理/自定义集成)、CloudWatchLogTool(CloudWatch 执行日志)、IAMTool(IAM 授权方与执行角色)、CloudFormationTool(通过 CloudFormation 部署)、StepFuncTool(由 Step Functions 编排)、EC2Tool(EC2/VPC 链接目标后端)、DynamoDBTool(DynamoDB 直接集成)、SNSTool(SNS 直接集成)、SQSTool(SQS 直接集成)。
API Gateway 执行日志使用如下日志组命名模式:
API-Gateway-Execution-Logs_<restApiId>/<stageName>
访问日志按阶段配置,可写入自定义日志组。可使用 CloudWatchLogTool 的 DescribeLogGroups 命令,配合 logGroupNamePrefix: "API-Gateway-Execution-Logs_" 查找这些日志组。
使用提示
- 先用 GetRestApis 发现 API,再用 GetResources 查看资源树。
- 用 GetMethod → GetIntegration 查看方法如何连接到后端。
- TestInvokeMethod 无需部署或阶段即可测试 API 方法,适合调试。
- TestInvokeAuthorizer 可在不发起真实 API 调用的情况下验证授权方行为。
- GetStages 可显示每个阶段的部署历史与阶段变量。
- 用 GetUsagePlans 配合 GetUsagePlanKeys 审计 API 密钥的限流与配额。
限制
资料未提供该工具的安装方式、收费模式、平台限制或性能约束等信息,暂未提供。