本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 API Gateway 示例 Amazon CLI
以下代码示例向您展示了如何使用 with API Gateway 来执行操作和实现常见场景。 Amazon Command Line Interface
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。
场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。
每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示如何使用 create-api-key
。
- Amazon CLI
-
创建为现有 API 和舞台启用的 API 密钥
命令:
aws apigateway create-api-key --name 'Dev API Key' --description 'Used for development' --enabled --stage-keys restApiId='a1b2c3d4e5',stageName='dev'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateApiKey
中的。
-
以下代码示例演示如何使用 create-authorizer
。
- Amazon CLI
-
示例 1:为 API 创建基于令牌的 API Gateway 自定义授权器
以下
create-authorizer
示例创建了一个基于令牌的授权者。aws apigateway create-authorizer \ --rest-api-id 1234123412 \ --name 'First_Token_Custom_Authorizer' \ --type TOKEN \ --authorizer-uri 'arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:customAuthFunction/invocations' \ --identity-source 'method.request.header.Authorization' \ --authorizer-result-ttl-in-seconds 300
输出:
{ "authType": "custom", "name": "First_Token_Custom_Authorizer", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:customAuthFunction/invocations", "authorizerResultTtlInSeconds": 300, "identitySource": "method.request.header.Authorization", "type": "TOKEN", "id": "z40xj0" }
示例 2:为该 API 创建基于 Cognito 用户池的 API Gateway 自定义授权器
以下
create-authorizer
示例创建了基于 Cognito 用户池的 API Gateway 自定义授权器。aws apigateway create-authorizer \ --rest-api-id 1234123412 \ --name 'First_Cognito_Custom_Authorizer' \ --type COGNITO_USER_POOLS \ --provider-arns 'arn:aws:cognito-idp:us-east-1:123412341234:userpool/us-east-1_aWcZeQbuD' \ --identity-source 'method.request.header.Authorization'
输出:
{ "authType": "cognito_user_pools", "identitySource": "method.request.header.Authorization", "name": "First_Cognito_Custom_Authorizer", "providerARNs": [ "arn:aws:cognito-idp:us-east-1:342398297714:userpool/us-east-1_qWbZzQhzE" ], "type": "COGNITO_USER_POOLS", "id": "5yid1t" }
示例 3:为 API 创建基于请求的 API Gateway 自定义授权器
以下
create-authorizer
示例创建了一个基于请求的授权者。aws apigateway create-authorizer \ --rest-api-id 1234123412 \ --name 'First_Request_Custom_Authorizer' \ --type REQUEST \ --authorizer-uri 'arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:customAuthFunction/invocations' \ --identity-source 'method.request.header.Authorization,context.accountId' \ --authorizer-result-ttl-in-seconds 300
输出:
{ "id": "z40xj0", "name": "First_Request_Custom_Authorizer", "type": "REQUEST", "authType": "custom", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:customAuthFunction/invocations", "identitySource": "method.request.header.Authorization,context.accountId", "authorizerResultTtlInSeconds": 300 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateAuthorizer
中的。
-
以下代码示例演示如何使用 create-base-path-mapping
。
- Amazon CLI
-
为自定义域名创建基本路径映射
命令:
aws apigateway create-base-path-mapping --domain-name subdomain.domain.tld --rest-api-id 1234123412 --stage prod --base-path v1
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateBasePathMapping
中的。
-
以下代码示例演示如何使用 create-deployment
。
- Amazon CLI
-
将为 API 配置的资源部署到新阶段
命令:
aws apigateway create-deployment --rest-api-id 1234123412 --stage-name dev --stage-description 'Development Stage' --description 'First deployment to the dev stage'
将为 API 配置的资源部署到现有阶段
命令:
aws apigateway create-deployment --rest-api-id 1234123412 --stage-name dev --description 'Second deployment to the dev stage'
通过 Stage 变量将为 API 配置的资源部署到现有阶段
aws apigateway 创建部署 — rest-api-id 1234123412 — stage-name dev — 描述 “第三次部署到开发阶段” — variables key='value ',otherkey='otherValue',otherkey='otherValue'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateDeployment
中的。
-
以下代码示例演示如何使用 create-domain-name
。
- Amazon CLI
-
创建自定义域名
命令:
aws apigateway create-domain-name --domain-name 'my.domain.tld' --certificate-name 'my.domain.tld cert' --certificate-arn 'arn:aws:acm:us-east-1:012345678910:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateDomainName
中的。
-
以下代码示例演示如何使用 create-model
。
- Amazon CLI
-
为 API 创建模型
命令:
aws apigateway create-model --rest-api-id 1234123412 --name 'firstModel' --description 'The First Model' --content-type 'application/json' --schema '{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "firstModel", "type": "object", "properties": { "firstProperty" : { "type": "object", "properties": { "key": { "type": "string" } } } } }'
输出:
{ "contentType": "application/json", "description": "The First Model", "name": "firstModel", "id": "2rzg0l", "schema": "{ \"$schema\": \"http://json-schema.org/draft-04/schema#\", \"title\": \"firstModel\", \"type\": \"object\", \"properties\": { \"firstProperty\" : { \"type\": \"object\", \"properties\": { \"key\": { \"type\": \"string\" } } } } }" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateModel
中的。
-
以下代码示例演示如何使用 create-resource
。
- Amazon CLI
-
在 API 中创建资源
命令:
aws apigateway create-resource --rest-api-id 1234123412 --parent-id a1b2c3 --path-part 'new-resource'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateResource
中的。
-
以下代码示例演示如何使用 create-rest-api
。
- Amazon CLI
-
创建 API
命令:
aws apigateway create-rest-api --name 'My First API' --description 'This is my first API'
使用现有 API 创建重复的 API
命令:
aws apigateway create-rest-api --name 'Copy of My First API' --description 'This is a copy of my first API' --clone-from 1234123412
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateRestApi
中的。
-
以下代码示例演示如何使用 create-stage
。
- Amazon CLI
-
在 API 中创建包含现有部署的阶段
命令:
aws apigateway create-stage --rest-api-id 1234123412 --stage-name 'dev' --description 'Development stage' --deployment-id a1b2c3
在 API 中创建包含现有部署和自定义阶段变量的阶段
命令:
aws apigateway create-stage --rest-api-id 1234123412 --stage-name 'dev' --description 'Development stage' --deployment-id a1b2c3 --variables key='value',otherKey='otherValue'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateStage
中的。
-
以下代码示例演示如何使用 create-usage-plan-key
。
- Amazon CLI
-
将现有 API 密钥与使用计划关联
命令:
aws apigateway create-usage-plan-key --usage-plan-id a1b2c3 --key-type "API_KEY" --key-id 4vq3yryqm5
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateUsagePlanKey
中的。
-
以下代码示例演示如何使用 create-usage-plan
。
- Amazon CLI
-
创建具有限制和配额限制的使用计划,并在月初重置
命令:
aws apigateway create-usage-plan --name "New Usage Plan" --description "A new usage plan" --throttle burstLimit=10,rateLimit=5 --quota limit=500,offset=0,period=MONTH
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateUsagePlan
中的。
-
以下代码示例演示如何使用 delete-api-key
。
- Amazon CLI
-
删除 API 密钥
命令:
aws apigateway delete-api-key --api-key 8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteApiKey
中的。
-
以下代码示例演示如何使用 delete-authorizer
。
- Amazon CLI
-
在 API 中删除自定义授权方
命令:
aws apigateway delete-authorizer --rest-api-id 1234123412 --authorizer-id 7gkfbo
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteAuthorizer
中的。
-
以下代码示例演示如何使用 delete-base-path-mapping
。
- Amazon CLI
-
删除自定义域名的基本路径映射
命令:
aws apigateway delete-base-path-mapping --domain-name 'api.domain.tld' --base-path 'dev'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteBasePathMapping
中的。
-
以下代码示例演示如何使用 delete-client-certificate
。
- Amazon CLI
-
删除客户证书
命令:
aws apigateway delete-client-certificate --client-certificate-id a1b2c3
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteClientCertificate
中的。
-
以下代码示例演示如何使用 delete-deployment
。
- Amazon CLI
-
在 API 中删除部署
命令:
aws apigateway delete-deployment --rest-api-id 1234123412 --deployment-id a1b2c3
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteDeployment
中的。
-
以下代码示例演示如何使用 delete-domain-name
。
- Amazon CLI
-
删除自定义域名
命令:
aws apigateway delete-domain-name --domain-name 'api.domain.tld'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteDomainName
中的。
-
以下代码示例演示如何使用 delete-integration-response
。
- Amazon CLI
-
删除 API 中给定资源、方法和状态代码的集成响应
命令:
aws apigateway delete-integration-response --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --status-code 200
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteIntegrationResponse
中的。
-
以下代码示例演示如何使用 delete-integration
。
- Amazon CLI
-
删除 API 中给定资源和方法的集成
命令:
aws apigateway delete-integration --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteIntegration
中的。
-
以下代码示例演示如何使用 delete-method-response
。
- Amazon CLI
-
删除 API 中给定资源、方法和状态代码的方法响应
命令:
aws apigateway delete-method-response --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --status-code 200
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteMethodResponse
中的。
-
以下代码示例演示如何使用 delete-method
。
- Amazon CLI
-
在 API 中删除给定资源的方法
命令:
aws apigateway delete-method --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteMethod
中的。
-
以下代码示例演示如何使用 delete-model
。
- Amazon CLI
-
在给定 API 中删除模型
命令:
aws apigateway delete-model --rest-api-id 1234123412 --model-name 'customModel'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteModel
中的。
-
以下代码示例演示如何使用 delete-resource
。
- Amazon CLI
-
删除 API 中的资源
命令:
aws apigateway delete-resource --rest-api-id 1234123412 --resource-id a1b2c3
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteResource
中的。
-
以下代码示例演示如何使用 delete-rest-api
。
- Amazon CLI
-
删除 API
命令:
aws apigateway delete-rest-api --rest-api-id 1234123412
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteRestApi
中的。
-
以下代码示例演示如何使用 delete-stage
。
- Amazon CLI
-
在 API 中删除阶段
命令:
aws apigateway delete-stage --rest-api-id 1234123412 --stage-name 'dev'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteStage
中的。
-
以下代码示例演示如何使用 delete-usage-plan-key
。
- Amazon CLI
-
从使用计划中删除 API 密钥
命令:
aws apigateway delete-usage-plan-key --usage-plan-id a1b2c3 --key-id 1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteUsagePlanKey
中的。
-
以下代码示例演示如何使用 delete-usage-plan
。
- Amazon CLI
-
删除使用计划
命令:
aws apigateway delete-usage-plan --usage-plan-id a1b2c3
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteUsagePlan
中的。
-
以下代码示例演示如何使用 flush-stage-authorizers-cache
。
- Amazon CLI
-
刷新舞台上的所有授权者缓存条目
命令:
aws apigateway flush-stage-authorizers-cache --rest-api-id 1234123412 --stage-name dev
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考FlushStageAuthorizersCache
中的。
-
以下代码示例演示如何使用 flush-stage-cache
。
- Amazon CLI
-
刷新 API 阶段的缓存
命令:
aws apigateway flush-stage-cache --rest-api-id 1234123412 --stage-name dev
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考FlushStageCache
中的。
-
以下代码示例演示如何使用 generate-client-certificate
。
- Amazon CLI
-
创建客户端 SSL 证书
命令:
aws apigateway generate-client-certificate --description 'My First Client Certificate'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GenerateClientCertificate
中的。
-
以下代码示例演示如何使用 get-account
。
- Amazon CLI
-
获取 API Gateway 账户设置
命令:
aws apigateway get-account
输出:
{ "cloudwatchRoleArn": "arn:aws:iam::123412341234:role/APIGatewayToCloudWatchLogsRole", "throttleSettings": { "rateLimit": 500.0, "burstLimit": 1000 } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetAccount
中的。
-
以下代码示例演示如何使用 get-api-key
。
- Amazon CLI
-
获取有关特定 API 密钥的信息
命令:
aws apigateway get-api-key --api-key 8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk
输出:
{ "description": "My first key", "enabled": true, "stageKeys": [ "a1b2c3d4e5/dev", "e5d4c3b2a1/dev" ], "lastUpdatedDate": 1456184515, "createdDate": 1456184452, "id": "8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk", "name": "My key" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetApiKey
中的。
-
以下代码示例演示如何使用 get-api-keys
。
- Amazon CLI
-
获取 API 密钥列表
命令:
aws apigateway get-api-keys
输出:
{ "items": [ { "description": "My first key", "enabled": true, "stageKeys": [ "a1b2c3d4e5/dev", "e5d4c3b2a1/dev" ], "lastUpdatedDate": 1456184515, "createdDate": 1456184452, "id": "8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk", "name": "My key" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetApiKeys
中的。
-
以下代码示例演示如何使用 get-authorizer
。
- Amazon CLI
-
获取每个 API 授权方的 API Gateway 设置
命令:
aws apigateway get-authorizer --rest-api-id 1234123412 --authorizer-id gfi4n3
输出:
{ "authorizerResultTtlInSeconds": 300, "name": "MyAuthorizer", "type": "TOKEN", "identitySource": "method.request.header.Authorization", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:authorizer_function/invocations", "id": "gfi4n3" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetAuthorizer
中的。
-
以下代码示例演示如何使用 get-authorizers
。
- Amazon CLI
-
获取 REST API 的授权者列表
命令:
aws apigateway get-authorizers --rest-api-id 1234123412
输出:
{ "items": [ { "name": "MyAuthorizer", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:My_Authorizer_Function/invocations", "authorizerResultTtlInSeconds": 300, "identitySource": "method.request.header.Authorization", "type": "TOKEN", "id": "gfi4n3" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetAuthorizers
中的。
-
以下代码示例演示如何使用 get-base-path-mapping
。
- Amazon CLI
-
获取自定义域名的基础路径映射
命令:
aws apigateway get-base-path-mapping --domain-name subdomain.domain.tld --base-path v1
输出:
{ "basePath": "v1", "restApiId": "1234w4321e", "stage": "api" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetBasePathMapping
中的。
-
以下代码示例演示如何使用 get-base-path-mappings
。
- Amazon CLI
-
获取自定义域名的基本路径映射
命令:
aws apigateway get-base-path-mappings --domain-name subdomain.domain.tld
输出:
{ "items": [ { "basePath": "(none)", "restApiId": "1234w4321e", "stage": "dev" }, { "basePath": "v1", "restApiId": "1234w4321e", "stage": "api" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetBasePathMappings
中的。
-
以下代码示例演示如何使用 get-client-certificate
。
- Amazon CLI
-
获取客户证书
命令:
aws apigateway get-client-certificate --client-certificate-id a1b2c3
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetClientCertificate
中的。
-
以下代码示例演示如何使用 get-client-certificates
。
- Amazon CLI
-
获取客户证书列表
命令:
aws apigateway get-client-certificates
输出:
{ "items": [ { "pemEncodedCertificate": "-----BEGIN CERTIFICATE----- <certificate content> -----END CERTIFICATE-----", "clientCertificateId": "a1b2c3", "expirationDate": 1483556561, "description": "My Client Certificate", "createdDate": 1452020561 } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetClientCertificates
中的。
-
以下代码示例演示如何使用 get-deployment
。
- Amazon CLI
-
获取有关部署的信息
命令:
aws apigateway get-deployment --rest-api-id 1234123412 --deployment-id ztt4m2
输出:
{ "description": "myDeployment", "id": "ztt4m2", "createdDate": 1455218022 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetDeployment
中的。
-
以下代码示例演示如何使用 get-deployments
。
- Amazon CLI
-
获取 REST API 的部署列表
命令:
aws apigateway get-deployments --rest-api-id 1234123412
输出:
{ "items": [ { "createdDate": 1453797217, "id": "0a2b4c", "description": "Deployed my API for the first time" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetDeployments
中的。
-
以下代码示例演示如何使用 get-domain-name
。
- Amazon CLI
-
获取有关自定义域名的信息
命令:
aws apigateway get-domain-name --domain-name api.domain.tld
输出:
{ "domainName": "api.domain.tld", "distributionDomainName": "d1a2f3a4c5o6d.cloudfront.net", "certificateName": "uploadedCertificate", "certificateUploadDate": 1462565487 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetDomainName
中的。
-
以下代码示例演示如何使用 get-domain-names
。
- Amazon CLI
-
获取自定义域名列表
命令:
aws apigateway get-domain-names
输出:
{ "items": [ { "distributionDomainName": "d9511k3l09bkd.cloudfront.net", "certificateUploadDate": 1452812505, "certificateName": "my_custom_domain-certificate", "domainName": "subdomain.domain.tld" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetDomainNames
中的。
-
以下代码示例演示如何使用 get-export
。
- Amazon CLI
-
获取舞台的 JSON Swagger 模板
命令:
aws apigateway get-export --rest-api-id a1b2c3d4e5 --stage-name dev --export-type swagger /path/to/filename.json
获取舞台的 JSON Swagger 模板 + API Gateway 扩展
命令:
aws apigateway get-export --parameters extensions='integrations' --rest-api-id a1b2c3d4e5 --stage-name dev --export-type swagger /path/to/filename.json
要获取 JSON Swagger 模板 + 舞台的 Postman 扩展
命令:
aws apigateway get-export --parameters extensions='postman' --rest-api-id a1b2c3d4e5 --stage-name dev --export-type swagger /path/to/filename.json
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetExport
中的。
-
以下代码示例演示如何使用 get-integration-response
。
- Amazon CLI
-
获取在 REST API 资源下定义的 HTTP 方法的集成响应配置
命令:
aws apigateway get-integration-response --rest-api-id 1234123412 --resource-id y9h6rt --http-method GET --status-code 200
输出:
{ "statusCode": "200", "responseTemplates": { "application/json": null } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetIntegrationResponse
中的。
-
以下代码示例演示如何使用 get-integration
。
- Amazon CLI
-
获取在 REST API 资源下定义的 HTTP 方法的集成配置
命令:
aws apigateway get-integration --rest-api-id 1234123412 --resource-id y9h6rt --http-method GET
输出:
{ "httpMethod": "POST", "integrationResponses": { "200": { "responseTemplates": { "application/json": null }, "statusCode": "200" } }, "cacheKeyParameters": [], "type": "AWS", "uri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:My_Function/invocations", "cacheNamespace": "y9h6rt" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetIntegration
中的。
-
以下代码示例演示如何使用 get-method-response
。
- Amazon CLI
-
获取在 REST API 资源下定义的 HTTP 方法的方法响应资源配置
命令:
aws apigateway get-method-response --rest-api-id 1234123412 --resource-id y9h6rt --http-method GET --status-code 200
输出:
{ "responseModels": { "application/json": "Empty" }, "statusCode": "200" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetMethodResponse
中的。
-
以下代码示例演示如何使用 get-method
。
- Amazon CLI
-
获取在 REST API 资源下定义的 HTTP 方法的方法资源配置
命令:
aws apigateway get-method --rest-api-id 1234123412 --resource-id y9h6rt --http-method GET
输出:
{ "apiKeyRequired": false, "httpMethod": "GET", "methodIntegration": { "integrationResponses": { "200": { "responseTemplates": { "application/json": null }, "statusCode": "200" } }, "cacheKeyParameters": [], "uri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:My_Function/invocations", "httpMethod": "POST", "cacheNamespace": "y9h6rt", "type": "AWS" }, "requestParameters": {}, "methodResponses": { "200": { "responseModels": { "application/json": "Empty" }, "statusCode": "200" } }, "authorizationType": "NONE" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetMethod
中的。
-
以下代码示例演示如何使用 get-model-template
。
- Amazon CLI
-
获取在 REST API 下定义的模型的映射模板
命令:
aws apigateway get-model-template --rest-api-id 1234123412 --model-name Empty
输出:
{ "value": "#set($inputRoot = $input.path('$'))\n{ }" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetModelTemplate
中的。
-
以下代码示例演示如何使用 get-model
。
- Amazon CLI
-
获取在 REST API 下定义的模型的配置
命令:
aws apigateway get-model --rest-api-id 1234123412 --model-name Empty
输出:
{ "contentType": "application/json", "description": "This is a default empty schema model", "name": "Empty", "id": "etd5w5", "schema": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"title\" : \"Empty Schema\",\n \"type\" : \"object\"\n}" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetModel
中的。
-
以下代码示例演示如何使用 get-models
。
- Amazon CLI
-
获取 REST API 的模型列表
命令:
aws apigateway get-models --rest-api-id 1234123412
输出:
{ "items": [ { "description": "This is a default error schema model", "schema": "{\n \"$schema\" : \"http://json-schema.org/draft-04/schema#\",\n \"title\" : \"Error Schema\",\n \"type\" : \"object\",\n \"properties\" : {\n \"message\" : { \"type\" : \"string\" }\n }\n}", "contentType": "application/json", "id": "7tpbze", "name": "Error" }, { "description": "This is a default empty schema model", "schema": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"title\" : \"Empty Schema\",\n \"type\" : \"object\"\n}", "contentType": "application/json", "id": "etd5w5", "name": "Empty" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetModels
中的。
-
以下代码示例演示如何使用 get-resource
。
- Amazon CLI
-
获取有关资源的信息
命令:
aws apigateway get-resource --rest-api-id 1234123412 --resource-id zwo0y3
输出:
{ "path": "/path", "pathPart": "path", "id": "zwo0y3", "parentId": "uyokt6ij2g" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetResource
中的。
-
以下代码示例演示如何使用 get-resources
。
- Amazon CLI
-
获取 REST API 的资源列表
命令:
aws apigateway get-resources --rest-api-id 1234123412
输出:
{ "items": [ { "path": "/resource/subresource", "resourceMethods": { "POST": {} }, "id": "024ace", "pathPart": "subresource", "parentId": "ai5b02" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetResources
中的。
-
以下代码示例演示如何使用 get-rest-api
。
- Amazon CLI
-
获取有关 API 的信息
命令:
aws apigateway get-rest-api --rest-api-id 1234123412
输出:
{ "name": "myAPI", "id": "o1y243m4f5", "createdDate": 1453416433 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetRestApi
中的。
-
以下代码示例演示如何使用 get-rest-apis
。
- Amazon CLI
-
获取 REST API 列表
命令:
aws apigateway get-rest-apis
输出:
{ "items": [ { "createdDate": 1438884790, "id": "12s44z21rb", "name": "My First API" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetRestApis
中的。
-
以下代码示例演示如何使用 get-sdk
。
- Amazon CLI
-
获取适用于 REST API 阶段的安卓 SDK
命令:
aws apigateway get-sdk --rest-api-id 1234123412 --stage-name dev --sdk-type android --parameters groupId='com.mycompany',invokerPackage='com.mycompany.clientsdk',artifactId='Mycompany-client',artifactVersion='1.0.0' /path/to/android_sdk.zip
输出:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"android_2016-02-22_23-52Z.zip\"" }
获取适用于 REST API 阶段的 IOS 开发工具包
命令:
aws apigateway get-sdk --rest-api-id 1234123412 --stage-name dev --sdk-type objectivec --parameters classPrefix='myprefix' /path/to/iOS_sdk.zip
输出:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"objectivec_2016-02-22_23-52Z.zip\"" }
获取适用于 REST API 阶段的 Javascript 开发工具包
命令:
aws apigateway get-sdk --rest-api-id 1234123412 --stage-name dev --sdk-type javascript /path/to/javascript_sdk.zip
输出:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"javascript_2016-02-22_23-52Z.zip\"" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetSdk
中的。
-
以下代码示例演示如何使用 get-stage
。
- Amazon CLI
-
获取有关 API 阶段的信息
命令:
aws apigateway get-stage --rest-api-id 1234123412 --stage-name dev
输出:
{ "stageName": "dev", "cacheClusterSize": "0.5", "cacheClusterEnabled": false, "cacheClusterStatus": "NOT_AVAILABLE", "deploymentId": "rbh1fj", "lastUpdatedDate": 1466802961, "createdDate": 1460682074, "methodSettings": { "*/*": { "cacheTtlInSeconds": 300, "loggingLevel": "INFO", "dataTraceEnabled": false, "metricsEnabled": true, "unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER", "throttlingRateLimit": 500.0, "cacheDataEncrypted": false, "cachingEnabled": false, "throttlingBurstLimit": 1000, "requireAuthorizationForCacheControl": true }, "~1resource/GET": { "cacheTtlInSeconds": 300, "loggingLevel": "INFO", "dataTraceEnabled": false, "metricsEnabled": true, "unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER", "throttlingRateLimit": 500.0, "cacheDataEncrypted": false, "cachingEnabled": false, "throttlingBurstLimit": 1000, "requireAuthorizationForCacheControl": true } } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetStage
中的。
-
以下代码示例演示如何使用 get-stages
。
- Amazon CLI
-
获取 REST API 的阶段列表
命令:
aws apigateway get-stages --rest-api-id 1234123412
输出:
{ "item": [ { "stageName": "dev", "cacheClusterSize": "0.5", "cacheClusterEnabled": true, "cacheClusterStatus": "AVAILABLE", "deploymentId": "123h64", "lastUpdatedDate": 1456185138, "createdDate": 1453589092, "methodSettings": { "~1resource~1subresource/POST": { "cacheTtlInSeconds": 300, "loggingLevel": "INFO", "dataTraceEnabled": true, "metricsEnabled": true, "throttlingRateLimit": 500.0, "cacheDataEncrypted": false, "cachingEnabled": false, "throttlingBurstLimit": 1000 } } } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetStages
中的。
-
以下代码示例演示如何使用 get-usage-plan-key
。
- Amazon CLI
-
获取与使用计划关联的 API 密钥的详细信息
命令:
aws apigateway get-usage-plan-key --usage-plan-id a1b2c3 --key-id 1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetUsagePlanKey
中的。
-
以下代码示例演示如何使用 get-usage-plan-keys
。
- Amazon CLI
-
获取与使用计划关联的 API 密钥列表
命令:
aws apigateway get-usage-plan-keys --usage-plan-id a1b2c3
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetUsagePlanKeys
中的。
-
以下代码示例演示如何使用 get-usage-plan
。
- Amazon CLI
-
获取使用计划的详细信息
命令:
aws apigateway get-usage-plan --usage-plan-id a1b2c3
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetUsagePlan
中的。
-
以下代码示例演示如何使用 get-usage-plans
。
- Amazon CLI
-
要获取所有使用计划的详细信息
命令:
aws apigateway get-usage-plans
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetUsagePlans
中的。
-
以下代码示例演示如何使用 get-usage
。
- Amazon CLI
-
获取使用计划的使用详情
命令:
aws apigateway get-usage --usage-plan-id a1b2c3 --start-date "2016-08-16" --end-date "2016-08-17"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetUsage
中的。
-
以下代码示例演示如何使用 import-rest-api
。
- Amazon CLI
-
导入 Swagger 模板并创建 API
命令:
aws apigateway import-rest-api --body 'file:///path/to/API_Swagger_template.json'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ImportRestApi
中的。
-
以下代码示例演示如何使用 put-integration-response
。
- Amazon CLI
-
使用定义的映射模板创建集成响应作为默认响应
命令:
aws apigateway put-integration-response --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --status-code 200 --selection-pattern "" --response-templates '{"application/json": "{\"json\": \"template\"}"}'
使用正则表达式为 400 的静态定义的标头值创建集成响应
命令:
aws apigateway put-integration-response --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --status-code 400 --selection-pattern 400 --response-parameters '{"method.response.header.custom-header": "'"'"'custom-value'"'"'"}'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考PutIntegrationResponse
中的。
-
以下代码示例演示如何使用 put-integration
。
- Amazon CLI
-
创建 MOCK 集成请求
命令:
aws apigateway put-integration --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --type MOCK --request-templates '{ "application/json": "{\"statusCode\": 200}" }'
创建 HTTP 集成请求
命令:
aws apigateway put-integration --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --type HTTP --integration-http-method GET --uri 'https://domain.tld/path'
使用 Lambda 函数终端节点创建 Amazon 集成请求
命令:
aws apigateway put-integration --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --type AWS --integration-http-method POST --uri 'arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:function_name/invocations'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考PutIntegration
中的。
-
以下代码示例演示如何使用 put-method-response
。
- Amazon CLI
-
基于指定状态代码,通过自定义方法响应标头创建方法响应
命令:
aws apigateway put-method-response --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --status-code 400 --response-parameters "method.response.header.custom-header=false"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考PutMethodResponse
中的。
-
以下代码示例演示如何使用 put-method
。
- Amazon CLI
-
在没有授权、没有 API 密钥和自定义方法请求标头的情况下为 API 中的资源创建方法
命令:
aws apigateway put-method --rest-api-id 1234123412 --resource-id a1b2c3 --http-method PUT --authorization-type "NONE" --no-api-key-required --request-parameters "method.request.header.custom-header=false"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考PutMethod
中的。
-
以下代码示例演示如何使用 put-rest-api
。
- Amazon CLI
-
使用 Swagger 模板覆盖现有 API
命令:
aws apigateway put-rest-api --rest-api-id 1234123412 --mode overwrite --body 'fileb:///path/to/API_Swagger_template.json'
将 Swagger 模板合并到现有 API 中
命令:
aws apigateway put-rest-api --rest-api-id 1234123412 --mode merge --body 'fileb:///path/to/API_Swagger_template.json'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考PutRestApi
中的。
-
以下代码示例演示如何使用 test-invoke-authorizer
。
- Amazon CLI
-
要进行测试,请调用包含所需标头和值的自定义授权器的请求
命令:
aws apigateway test-invoke-authorizer --rest-api-id 1234123412 --authorizer-id 5yid1t --headers Authorization='Value'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考TestInvokeAuthorizer
中的。
-
以下代码示例演示如何使用 test-invoke-method
。
- Amazon CLI
-
通过发出 GET 请求在 API 中测试调用根资源
命令:
aws apigateway test-invoke-method --rest-api-id 1234123412 --resource-id avl5sg8fw8 --http-method GET --path-with-query-string '/'
通过发出指定路径参数值的 GET 请求在 API 中测试调用子资源
命令:
aws apigateway test-invoke-method --rest-api-id 1234123412 --resource-id 3gapai --http-method GET --path-with-query-string '/pets/1'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考TestInvokeMethod
中的。
-
以下代码示例演示如何使用 update-account
。
- Amazon CLI
-
更改用于登录到日志的 IAM 角色 ARN CloudWatch
命令:
aws apigateway update-account --patch-operations op='replace',path='/cloudwatchRoleArn',value='arn:aws:iam::123412341234:role/APIGatewayToCloudWatchLogs'
输出:
{ "cloudwatchRoleArn": "arn:aws:iam::123412341234:role/APIGatewayToCloudWatchLogs", "throttleSettings": { "rateLimit": 1000.0, "burstLimit": 2000 } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateAccount
中的。
-
以下代码示例演示如何使用 update-api-key
。
- Amazon CLI
-
更改 API 密钥的名称
命令:
aws apigateway update-api-key --api-key sNvjQDMReA1eEQPNAW8r37XsU2rDD7fc7m2SiMnu --patch-operations op='replace',path='/name',value='newName'
输出:
{ "description": "currentDescription", "enabled": true, "stageKeys": [ "41t2j324r5/dev" ], "lastUpdatedDate": 1470086052, "createdDate": 1445460347, "id": "sNvjQDMReA1vEQPNzW8r3dXsU2rrD7fcjm2SiMnu", "name": "newName" }
禁用 API 密钥
命令:
aws apigateway update-api-key --api-key sNvjQDMReA1eEQPNAW8r37XsU2rDD7fc7m2SiMnu --patch-operations op='replace',path='/enabled',value='false'
输出:
{ "description": "currentDescription", "enabled": false, "stageKeys": [ "41t2j324r5/dev" ], "lastUpdatedDate": 1470086052, "createdDate": 1445460347, "id": "sNvjQDMReA1vEQPNzW8r3dXsU2rrD7fcjm2SiMnu", "name": "newName" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateApiKey
中的。
-
以下代码示例演示如何使用 update-authorizer
。
- Amazon CLI
-
更改自定义授权者的名称
命令:
aws apigateway update-authorizer --rest-api-id 1234123412 --authorizer-id gfi4n3 --patch-operations op='replace',path='/name',value='testAuthorizer'
输出:
{ "authType": "custom", "name": "testAuthorizer", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:customAuthorizer/invocations", "authorizerResultTtlInSeconds": 300, "identitySource": "method.request.header.Authorization", "type": "TOKEN", "id": "gfi4n3" }
更改由自定义授权方调用的 Lambda 函数
命令:
aws apigateway update-authorizer --rest-api-id 1234123412 --authorizer-id gfi4n3 --patch-operations op='replace',path='/authorizerUri',value='arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:newAuthorizer/invocations'
输出:
{ "authType": "custom", "name": "testAuthorizer", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:newAuthorizer/invocations", "authorizerResultTtlInSeconds": 300, "identitySource": "method.request.header.Authorization", "type": "TOKEN", "id": "gfi4n3" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateAuthorizer
中的。
-
以下代码示例演示如何使用 update-base-path-mapping
。
- Amazon CLI
-
更改自定义域名的基础路径
命令:
aws apigateway update-base-path-mapping --domain-name api.domain.tld --base-path prod --patch-operations op='replace',path='/basePath',value='v1'
输出:
{ "basePath": "v1", "restApiId": "1234123412", "stage": "api" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateBasePathMapping
中的。
-
以下代码示例演示如何使用 update-client-certificate
。
- Amazon CLI
-
更新客户证书的描述
命令:
aws apigateway update-client-certificate --client-certificate-id a1b2c3 --patch-operations op='replace',path='/description',value='My new description'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateClientCertificate
中的。
-
以下代码示例演示如何使用 update-deployment
。
- Amazon CLI
-
更改部署的描述
命令:
aws apigateway update-deployment --rest-api-id 1234123412 --deployment-id ztt4m2 --patch-operations op='replace',path='/description',value='newDescription'
输出:
{ "description": "newDescription", "id": "ztt4m2", "createdDate": 1455218022 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateDeployment
中的。
-
以下代码示例演示如何使用 update-domain-name
。
- Amazon CLI
-
更改自定义域名的证书名称
以下
update-domain-name
示例更改了自定义域的证书名称。aws apigateway update-domain-name \ --domain-name api.domain.tld \ --patch-operations op='replace',path='/certificateArn',value='arn:aws:acm:us-west-2:111122223333:certificate/CERTEXAMPLE123EXAMPLE'
输出:
{ "domainName": "api.domain.tld", "distributionDomainName": "d123456789012.cloudfront.net", "certificateArn": "arn:aws:acm:us-west-2:111122223333:certificate/CERTEXAMPLE123EXAMPLE", "certificateUploadDate": 1462565487 }
有关更多信息,请参阅 Amazon API Gateway 开发者指南中的在 API Gateway 中为 API 设置自定义域名。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateDomainName
中的。
-
以下代码示例演示如何使用 update-integration-response
。
- Amazon CLI
-
将集成响应标头更改为具有 '*' 的静态映射
命令:
aws apigateway update-integration-response --rest-api-id 1234123412 --resource-id 3gapai --http-method GET --status-code 200 --patch-operations op='replace',path='/responseParameters/method.response.header.Access-Control-Allow-Origin',value='"'"'*'"'"'
输出:
{ "statusCode": "200", "responseParameters": { "method.response.header.Access-Control-Allow-Origin": "'*'" } }
移除集成响应标头
命令:
aws apigateway update-integration-response --rest-api-id 1234123412 --resource-id 3gapai --http-method GET --status-code 200 --patch-operations op='remove',path='/responseParameters/method.response.header.Access-Control-Allow-Origin'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateIntegrationResponse
中的。
-
以下代码示例演示如何使用 update-integration
。
- Amazon CLI
-
添加配置了输入直通的 “内容类型:应用程序/json” 映射模板
命令:
aws apigateway update-integration \ --rest-api-id a1b2c3d4e5 \ --resource-id a1b2c3 \ --http-method POST \ --patch-operations "op='add',path='/requestTemplates/application~1json'"
更新(替换)使用自定义模板配置的 “内容类型:应用程序/json” 映射模板
命令:
aws apigateway update-integration \ --rest-api-id a1b2c3d4e5 \ --resource-id a1b2c3 \ --http-method POST \ --patch-operations "op='replace',path='/requestTemplates/application~1json',value='{"example": "json"}'"
使用输入直通更新(替换)与 “内容类型:应用程序/json” 关联的自定义模板
命令:
aws apigateway update-integration \ --rest-api-id a1b2c3d4e5 \ --resource-id a1b2c3 \ --http-method POST \ --patch-operations "op='replace',path='requestTemplates/application~1json'"
移除 “内容类型:应用程序/json” 映射模板
命令:
aws apigateway update-integration \ --rest-api-id a1b2c3d4e5 \ --resource-id a1b2c3 \ --http-method POST \ --patch-operations "op='remove',path='/requestTemplates/application~1json'"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateIntegration
中的。
-
以下代码示例演示如何使用 update-method-response
。
- Amazon CLI
-
为方法中的 200 响应创建新的方法响应标头并将其定义为不需要(默认)
命令:
aws apigateway update-method-response --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --status-code 200 --patch-operations op="add",path="/responseParameters/method.response.header.custom-header",value="false"
在方法中删除 200 响应的响应模型
命令:
aws apigateway update-method-response --rest-api-id 1234123412 --resource-id a1b2c3 --http-method GET --status-code 200 --patch-operations op="remove",path="/responseModels/application~1json"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateMethodResponse
中的。
-
以下代码示例演示如何使用 update-method
。
- Amazon CLI
-
示例 1:将方法修改为需要 API 密钥
以下
update-method
示例将该方法修改为需要 API 密钥。aws apigateway update-method \ --rest-api-id 1234123412 \ --resource-id a1b2c3 \ --http-method GET \ --patch-operations op="replace",path="/apiKeyRequired",value="true"
输出:
{ "httpMethod": "GET", "authorizationType": "NONE", "apiKeyRequired": true, "methodResponses": { "200": { "statusCode": "200", "responseModels": {} } }, "methodIntegration": { "type": "AWS", "httpMethod": "POST", "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789111:function:hello-world/invocations", "passthroughBehavior": "WHEN_NO_MATCH", "contentHandling": "CONVERT_TO_TEXT", "timeoutInMillis": 29000, "cacheNamespace": "h7i8j9", "cacheKeyParameters": [], "integrationResponses": { "200": { "statusCode": "200", "responseTemplates": {} } } } }
示例 2:将方法修改为要求 IAM 授权
以下
update-method
示例将方法修改为需要 IAM 授权。aws apigateway update-method \ --rest-api-id 1234123412 \ --resource-id a1b2c3 \ --http-method GET \ --patch-operations op="replace",path="/authorizationType",value="AWS_IAM"
输出:
{ "httpMethod": "GET", "authorizationType": "AWS_IAM", "apiKeyRequired": false, "methodResponses": { "200": { "statusCode": "200", "responseModels": {} } }, "methodIntegration": { "type": "AWS", "httpMethod": "POST", "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789111:function:hello-world/invocations", "passthroughBehavior": "WHEN_NO_MATCH", "contentHandling": "CONVERT_TO_TEXT", "timeoutInMillis": 29000, "cacheNamespace": "h7i8j9", "cacheKeyParameters": [], "integrationResponses": { "200": { "statusCode": "200", "responseTemplates": {} } } } }
示例 3:将方法修改为需要 Lambda 授权
以下
update-method
示例将该方法修改为所需的 Lambda 授权。aws apigateway update-method --rest-api-id 1234123412 \ --resource-id a1b2c3 \ --http-method GET \ --patch-operations op="replace",path="/authorizationType",value="CUSTOM" op="replace",path="/authorizerId",value="e4f5g6"
输出:
{ "httpMethod": "GET", "authorizationType": "CUSTOM", "authorizerId" : "e4f5g6", "apiKeyRequired": false, "methodResponses": { "200": { "statusCode": "200", "responseModels": {} } }, "methodIntegration": { "type": "AWS", "httpMethod": "POST", "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789111:function:hello-world/invocations", "passthroughBehavior": "WHEN_NO_MATCH", "contentHandling": "CONVERT_TO_TEXT", "timeoutInMillis": 29000, "cacheNamespace": "h7i8j9", "cacheKeyParameters": [], "integrationResponses": { "200": { "statusCode": "200", "responseTemplates": {} } } } }
有关更多信息,请参阅 Amazon API Gateway 开发者指南中的使用 API Gateway CLI 和 REST API 创建、配置和测试使用计划以及在 API Gateway 中控制和管理 REST API 的访问权限。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateMethod
中的。
-
以下代码示例演示如何使用 update-model
。
- Amazon CLI
-
在 API 中更改模型的描述
命令:
aws apigateway update-model --rest-api-id 1234123412 --model-name 'Empty' --patch-operations op=replace,path=/description,value='New Description'
在 API 中更改模型的架构
命令:
aws apigateway update-model --rest-api-id 1234123412 --model-name 'Empty' --patch-operations op=replace,path=/schema,value='"{ \"$schema\": \"http://json-schema.org/draft-04/schema#\", \"title\" : \"Empty Schema\", \"type\" : \"object\" }"'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateModel
中的。
-
以下代码示例演示如何使用 update-resource
。
- Amazon CLI
-
在 API 中移动资源并将其置于不同的父资源下
命令:
aws apigateway update-resource --rest-api-id 1234123412 --resource-id 1a2b3c --patch-operations op=replace,path=/parentId,value='3c2b1a'
输出:
{ "path": "/resource", "pathPart": "resource", "id": "1a2b3c", "parentId": "3c2b1a" }
在 API 中重命名资源 (pathPart)
命令:
aws apigateway update-resource --rest-api-id 1234123412 --resource-id 1a2b3c --patch-operations op=replace,path=/pathPart,value=newresourcename
输出:
{ "path": "/newresourcename", "pathPart": "newresourcename", "id": "1a2b3c", "parentId": "3c2b1a" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateResource
中的。
-
以下代码示例演示如何使用 update-rest-api
。
- Amazon CLI
-
更改 API 的名称
命令:
aws apigateway update-rest-api --rest-api-id 1234123412 --patch-operations op=replace,path=/name,value='New Name'
更改 API 的描述
命令:
aws apigateway update-rest-api --rest-api-id 1234123412 --patch-operations op=replace,path=/description,value='New Description'
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateRestApi
中的。
-
以下代码示例演示如何使用 update-stage
。
- Amazon CLI
-
示例 1:覆盖资源和方法的阶段设置
以下
update-stage
示例覆盖了阶段设置并关闭了特定资源和方法的完整请求/响应日志记录。aws apigateway update-stage \ --rest-api-id 1234123412 \ --stage-name 'dev' \ --patch-operations op=replace,path=/~1resourceName/GET/logging/dataTrace,value=false
输出:
{ "deploymentId": "5ubd17", "stageName": "dev", "cacheClusterEnabled": false, "cacheClusterStatus": "NOT_AVAILABLE", "methodSettings": { "~1resourceName/GET": { "metricsEnabled": false, "dataTraceEnabled": false, "throttlingBurstLimit": 5000, "throttlingRateLimit": 10000.0, "cachingEnabled": false, "cacheTtlInSeconds": 300, "cacheDataEncrypted": false, "requireAuthorizationForCacheControl": true, "unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER" } }, "tracingEnabled": false, "createdDate": "2022-07-18T10:11:18-07:00", "lastUpdatedDate": "2022-07-18T10:19:04-07:00" }
有关更多信息,请参阅 Amazon API Gateway 开发者指南中的为 REST API 设置阶段。
示例 2:更新 API 阶段的所有资源和方法的阶段设置
以下
update-stage
示例为 API 阶段的所有资源和方法开启了完整的请求/响应日志记录。aws apigateway update-stage \ --rest-api-id 1234123412 \ --stage-name 'dev' \ --patch-operations 'op=replace,path=/*/*/logging/dataTrace,value=true'
输出:
{ "deploymentId": "5ubd17", "stageName": "dev", "cacheClusterEnabled": false, "cacheClusterStatus": "NOT_AVAILABLE", "methodSettings": { "*/*": { "metricsEnabled": false, "dataTraceEnabled": true, "throttlingBurstLimit": 5000, "throttlingRateLimit": 10000.0, "cachingEnabled": false, "cacheTtlInSeconds": 300, "cacheDataEncrypted": false, "requireAuthorizationForCacheControl": true, "unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER" } }, "tracingEnabled": false, "createdDate": "2022-07-18T10:11:18-07:00", "lastUpdatedDate": "2022-07-18T10:31:04-07:00" }
有关更多信息,请参阅 Amazon API Gateway 开发者指南中的为 REST API 设置阶段。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateStage
中的。
-
以下代码示例演示如何使用 update-usage-plan
。
- Amazon CLI
-
更改使用计划中定义的期限
命令:
aws apigateway update-usage-plan --usage-plan-id a1b2c3 --patch-operations op="replace",path="/quota/period",value="MONTH"
更改使用计划中定义的配额限制
命令:
aws apigateway update-usage-plan --usage-plan-id a1b2c3 --patch-operations op="replace",path="/quota/limit",value="500"
更改使用计划中定义的油门速率限制
命令:
aws apigateway update-usage-plan --usage-plan-id a1b2c3 --patch-operations op="replace",path="/throttle/rateLimit",value="10"
更改使用计划中定义的油门爆发限制
命令:
aws apigateway update-usage-plan --usage-plan-id a1b2c3 --patch-operations op="replace",path="/throttle/burstLimit",value="20"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateUsagePlan
中的。
-
以下代码示例演示如何使用 update-usage
。
- Amazon CLI
-
临时修改使用计划中定义的当前期间 API 密钥的配额
命令:
aws apigateway update-usage --usage-plan-id a1b2c3 --key-id 1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu --patch-operations op="replace",path="/remaining",value="50"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateUsage
中的。
-