文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 API Gateway 示例 AWS CLI
以下代码示例向您展示了如何使用 with API Gateway 来执行操作和实现常见场景。 AWS Command Line Interface
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示了如何使用 create-api-key。
- AWS CLI
- 
             
                    创建为现有 API 和阶段启用的 API 密钥 命令: aws apigateway create-api-key --name 'Dev API Key' --description 'Used for development' --enabled --stage-keys restApiId='a1b2c3d4e5',stageName='dev'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateApiKey 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-authorizer。
- AWS CLI
- 
             
                    示例 1:为 API 创建基于令牌的 API Gateway 自定义授权方 以下 create-authorizer示例创建基于令牌的授权方。aws apigateway create-authorizer \ --rest-api-id1234123412\ --name 'First_Token_Custom_Authorizer' \ --typeTOKEN\ --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-seconds300输出: { "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-id1234123412\ --name 'First_Cognito_Custom_Authorizer' \ --typeCOGNITO_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-id1234123412\ --name 'First_Request_Custom_Authorizer' \ --typeREQUEST\ --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-seconds300输出: { "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 的详细信息,请参阅AWS CLI 命令参考CreateAuthorizer 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-base-path-mapping。
- AWS CLI
- 
             
                    创建自定义域名的基础路径映射 命令: aws apigateway create-base-path-mapping --domain-namesubdomain.domain.tld--rest-api-id1234123412--stageprod--base-pathv1- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateBasePathMapping 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-deployment。
- AWS CLI
- 
             
                    将为 API 配置的资源部署到新阶段 命令: aws apigateway create-deployment --rest-api-id1234123412--stage-namedev--stage-description 'Development Stage' --description 'First deployment to the dev stage'将为 API 配置的资源部署到现有阶段 命令: aws apigateway create-deployment --rest-api-id1234123412--stage-namedev--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 的详细信息,请参阅AWS CLI 命令参考CreateDeployment 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-domain-name-access-association。
- AWS CLI
- 
             
                    创建域名访问关联 以下 create-domain-name-access-association示例在私有自定义域名和 VPC 端点之间创建域名访问关联。aws apigateway create-domain-name-access-association \ --domain-name-arnarn:aws:apigateway:us-west-2:111122223333:/domainnames/my.private.domain.tld+abcd1234\ --access-association-sourcevpce-abcd1234efg\ --access-association-source-typeVPCE输出: { "domainNameAccessAssociationArn": "arn:aws:apigateway:us-west-2:012345678910:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg "accessAssociationSource": "vpce-abcd1234efg", "accessAssociationSourceType": "VPCE", "domainNameArn" : "arn:aws:apigateway:us-west-2:111122223333:/domainnames/private.example.com+abcd1234" }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中的私有自定义域名。 - 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateDomainNameAccessAssociation 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-domain-name。
- AWS CLI
- 
             
                    示例 1:创建公共自定义域名 以下 create-domain-name示例创建公共自定义域名。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'输出: { "domainName": "my.domain.tld", "certificateName": "my.domain.tld cert", "certificateArn": "arn:aws:acm:us-east-1:012345678910:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3", "certificateUploadDate": "2024-10-08T11:29:49-07:00", "distributionDomainName": "abcd1234.cloudfront.net", "distributionHostedZoneId": "Z2FDTNDATAQYW2", "endpointConfiguration": { "types": [ "EDGE" ] }, "domainNameStatus": "AVAILABLE", "securityPolicy": "TLS_1_2" }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中公共 REST 的自定义域名。 示例 2:创建私有自定义域名 以下 create-domain-name示例创建私有自定义域名。aws apigateway create-domain-name \ --domain-name 'my.private.domain.tld' \ --certificate-name 'my.domain.tld cert' \ --certificate-arn 'arn:aws:acm:us-east-1:012345678910:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3' \ --endpoint-configuration '{"types": ["PRIVATE"]}' \ --security-policy 'TLS_1_2' \ --policyfile://policy.jsonpolicy.json的内容:{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": "execute-api:Invoke", "Resource": [ "execute-api:/*" ] }, { "Effect": "Deny", "Principal": "*", "Action": "execute-api:Invoke", "Resource": [ "execute-api:/*" ], "Condition" : { "StringNotEquals": { "aws:SourceVpce": "vpce-abcd1234efg" } } } ] }输出: { "domainName": "my.private.domain.tld", "domainNameId": "abcd1234", "domainNameArn": "arn:aws:apigateway:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234", "certificateArn": "arn:aws:acm:us-east-1:012345678910:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3", "certificateUploadDate": "2024-09-10T10:31:20-07:00", "endpointConfiguration": { "types": [ "PRIVATE" ] }, "domainNameStatus": "AVAILABLE", "securityPolicy": "TLS_1_2", "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"execute-api:Invoke\",\"Resource\":\"arn:aws:execute-api:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234\"},{\"Effect\":\"Deny\",\"Principal\":\"*\",\"Action\":\"execute-api:Invoke\",\"Resource\":\"arn:aws:execute-api:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234\",\"Condition\":{\"StringNotEquals\":{\"aws:SourceVpc\":\"vpc-1a2b3c4d\"}}}]}" }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中公共 REST 的自定义域名。 - 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateDomainName 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-model。
- AWS CLI
- 
             
                    为 API 创建模型 命令: aws apigateway create-model --rest-api-id1234123412--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 的详细信息,请参阅AWS CLI 命令参考CreateModel 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-resource。
- AWS CLI
- 
             
                    在 API 中创建资源 命令: aws apigateway create-resource --rest-api-id1234123412--parent-ida1b2c3--path-part 'new-resource'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateResource 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-rest-api。
- AWS 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-from1234123412- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateRestApi 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-stage。
- AWS CLI
- 
             
                    在 API 中创建包含现有部署的阶段 命令: aws apigateway create-stage --rest-api-id1234123412--stage-name 'dev' --description 'Development stage' --deployment-ida1b2c3在 API 中创建包含现有部署和自定义阶段变量的阶段 命令: aws apigateway create-stage --rest-api-id1234123412--stage-name 'dev' --description 'Development stage' --deployment-ida1b2c3--variables key='value',otherKey='otherValue'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateStage 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-usage-plan-key。
- AWS CLI
- 
             
                    将现有 API 密钥与使用计划关联 命令: aws apigateway create-usage-plan-key --usage-plan-ida1b2c3--key-type"API_KEY"--key-id4vq3yryqm5- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateUsagePlanKey 中的。 
 
- 
                    
以下代码示例演示了如何使用 create-usage-plan。
- AWS CLI
- 
             
                    创建具有节流功能和配额限制的使用计划,并在月初重置 命令: aws apigateway create-usage-plan --name"New Usage Plan"--description"A new usage plan"--throttleburstLimit=10,rateLimit=5--quotalimit=500,offset=0,period=MONTH- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考CreateUsagePlan 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-api-key。
- AWS CLI
- 
             
                    删除 API 密钥 命令: aws apigateway delete-api-key --api-key8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteApiKey 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-authorizer。
- AWS CLI
- 
             
                    在 API 中删除自定义授权方 命令: aws apigateway delete-authorizer --rest-api-id1234123412--authorizer-id7gkfbo- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteAuthorizer 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-base-path-mapping。
- AWS CLI
- 
             
                    删除自定义域名的基础路径映射 命令: aws apigateway delete-base-path-mapping --domain-name 'api.domain.tld' --base-path 'dev'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteBasePathMapping 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-client-certificate。
- AWS CLI
- 
             
                    删除客户端证书 命令: aws apigateway delete-client-certificate --client-certificate-ida1b2c3- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteClientCertificate 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-deployment。
- AWS CLI
- 
             
                    在 API 中删除部署 命令: aws apigateway delete-deployment --rest-api-id1234123412--deployment-ida1b2c3- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteDeployment 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-domain-name-access-association。
- AWS CLI
- 
             
                    删除域名访问关联 以下 delete-domain-name-access-association示例删除私有自定义域名和 VPC 端点之间的域名访问关联。aws apigateway delete-domain-name-access-association \ --domain-name-access-association-arnarn:aws:apigateway:us-west-2:012345678910:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg此命令不生成任何输出。 有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中的私有自定义域名。 - 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteDomainNameAccessAssociation 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-domain-name。
- AWS CLI
- 
             
                    删除自定义域名 命令: aws apigateway delete-domain-name --domain-name 'api.domain.tld'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteDomainName 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-integration-response。
- AWS CLI
- 
             
                    删除 API 中给定资源、方法和状态代码的集成响应 命令: aws apigateway delete-integration-response --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--status-code200- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteIntegrationResponse 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-integration。
- AWS CLI
- 
             
                    删除 API 中给定资源和方法的集成 命令: aws apigateway delete-integration --rest-api-id1234123412--resource-ida1b2c3--http-methodGET- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteIntegration 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-method-response。
- AWS CLI
- 
             
                    删除 API 中给定资源、方法和状态代码的方法响应 命令: aws apigateway delete-method-response --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--status-code200- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteMethodResponse 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-method。
- AWS CLI
- 
             
                    删除 API 中给定资源的方法 命令: aws apigateway delete-method --rest-api-id1234123412--resource-ida1b2c3--http-methodGET- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteMethod 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-model。
- AWS CLI
- 
             
                    删除给定 API 中的模型 命令: aws apigateway delete-model --rest-api-id1234123412--model-name 'customModel'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteModel 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-resource。
- AWS CLI
- 
             
                    删除 API 中的资源 命令: aws apigateway delete-resource --rest-api-id1234123412--resource-ida1b2c3- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteResource 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-rest-api。
- AWS CLI
- 
             
                    删除 API 命令: aws apigateway delete-rest-api --rest-api-id1234123412- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteRestApi 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-stage。
- AWS CLI
- 
             
                    删除 API 中的阶段 命令: aws apigateway delete-stage --rest-api-id1234123412--stage-name 'dev'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteStage 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-usage-plan-key。
- AWS CLI
- 
             
                    从使用计划中移除 API 密钥 命令: aws apigateway delete-usage-plan-key --usage-plan-ida1b2c3--key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteUsagePlanKey 中的。 
 
- 
                    
以下代码示例演示了如何使用 delete-usage-plan。
- AWS CLI
- 
             
                    删除使用计划 命令: aws apigateway delete-usage-plan --usage-plan-ida1b2c3- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteUsagePlan 中的。 
 
- 
                    
以下代码示例演示了如何使用 flush-stage-authorizers-cache。
- AWS CLI
- 
             
                    刷新阶段的所有授权方缓存条目 命令: aws apigateway flush-stage-authorizers-cache --rest-api-id1234123412--stage-namedev- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考FlushStageAuthorizersCache 中的。 
 
- 
                    
以下代码示例演示了如何使用 flush-stage-cache。
- AWS CLI
- 
             
                    刷新 API 阶段的缓存 以下 flush-stage-cache示例刷新阶段缓存。aws apigateway flush-stage-cache \ --rest-api-id1234123412\ --stage-namedev此命令不生成任何输出。 有关更多信息,请参阅《Amazon API Gateway 开发人员指南》中的刷新 API Gateway 中的 API 阶段缓存。 - 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考FlushStageCache 中的。 
 
- 
                    
以下代码示例演示了如何使用 generate-client-certificate。
- AWS CLI
- 
             
                    创建客户端侧 SSL 证书 命令: aws apigateway generate-client-certificate --description 'My First Client Certificate'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GenerateClientCertificate 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-account。
- AWS CLI
- 
             
                    获取 API Gateway 账户设置 命令: aws apigateway get-account输出: { "cloudwatchRoleArn": "arn:aws:iam::123412341234:role/APIGatewayToCloudWatchLogsRole", "throttleSettings": { "rateLimit": 500.0, "burstLimit": 1000 } }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetAccount 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-api-key。
- AWS CLI
- 
             
                    获取有关指定 API 密钥的信息 命令: aws apigateway get-api-key --api-key8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk输出: { "description": "My first key", "enabled": true, "stageKeys": [ "a1b2c3d4e5/dev", "e5d4c3b2a1/dev" ], "lastUpdatedDate": 1456184515, "createdDate": 1456184452, "id": "8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk", "name": "My key" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetApiKey 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-api-keys。
- AWS 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 的详细信息,请参阅AWS CLI 命令参考GetApiKeys 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-authorizer。
- AWS CLI
- 
             
                    获取每个 API 授权方设置的 API Gateway 命令: aws apigateway get-authorizer --rest-api-id1234123412--authorizer-idgfi4n3输出: { "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 的详细信息,请参阅AWS CLI 命令参考GetAuthorizer 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-authorizers。
- AWS CLI
- 
             
                    获取 REST API 的授权方列表 命令: aws apigateway get-authorizers --rest-api-id1234123412输出: { "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 的详细信息,请参阅AWS CLI 命令参考GetAuthorizers 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-base-path-mapping。
- AWS CLI
- 
             
                    获取自定义域名的一个基础路径映射 命令: aws apigateway get-base-path-mapping --domain-namesubdomain.domain.tld--base-pathv1输出: { "basePath": "v1", "restApiId": "1234w4321e", "stage": "api" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetBasePathMapping 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-base-path-mappings。
- AWS CLI
- 
             
                    获取自定义域名的多个基础路径映射 命令: aws apigateway get-base-path-mappings --domain-namesubdomain.domain.tld输出: { "items": [ { "basePath": "(none)", "restApiId": "1234w4321e", "stage": "dev" }, { "basePath": "v1", "restApiId": "1234w4321e", "stage": "api" } ] }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetBasePathMappings 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-client-certificate。
- AWS CLI
- 
             
                    获取客户端证书 命令: aws apigateway get-client-certificate --client-certificate-ida1b2c3- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetClientCertificate 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-client-certificates。
- AWS 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 的详细信息,请参阅AWS CLI 命令参考GetClientCertificates 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-deployment。
- AWS CLI
- 
             
                    获取有关部署的信息 命令: aws apigateway get-deployment --rest-api-id1234123412--deployment-idztt4m2输出: { "description": "myDeployment", "id": "ztt4m2", "createdDate": 1455218022 }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetDeployment 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-deployments。
- AWS CLI
- 
             
                    获取 REST API 的部署列表 命令: aws apigateway get-deployments --rest-api-id1234123412输出: { "items": [ { "createdDate": 1453797217, "id": "0a2b4c", "description": "Deployed my API for the first time" } ] }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetDeployments 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-domain-name-access-associations。
- AWS CLI
- 
             
                    示例 1:列出所有域名访问关联 以下 get-domain-name-access-associations示例列出所有域名访问关联。aws apigateway get-domain-name-access-associations输出: { "items": [ { "domainNameAccessAssociationArn": "arn:aws:apigateway:us-west-2:012345678910:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg "accessAssociationSource": "vpce-abcd1234efg", "accessAssociationSourceType": "VPCE", "domainNameArn" : "arn:aws:apigateway:us-west-2:111122223333:/domainnames/private.example.com+abcd1234" } ] }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中的私有自定义域名。 示例 2:列出此 AWS 账户拥有的所有域名访问关联 以下 get-domain-name-access-associations示例列出了当前 AWS 账户拥有的所有域名访问关联。aws apigateway get-domain-name-access-associations \ --resource-ownerSELF输出: { "items": [ { "domainNameAccessAssociationArn": "arn:aws:apigateway:us-west-2:012345678910:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg "accessAssociationSource": "vpce-abcd1234efg", "accessAssociationSourceType": "VPCE", "domainNameArn" : "arn:aws:apigateway:us-west-2:111122223333:/domainnames/private.example.com+abcd1234" } ] }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中的私有自定义域名。 - 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetDomainNameAccessAssociations 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-domain-name。
- AWS CLI
- 
             
                    示例 1:获取有关公共自定义域名的信息 以下 get-domain-name示例获取有关公共自定义域名的信息。aws apigateway get-domain-name \ --domain-nameapi.domain.tld输出: { "domainName": "api.domain.tld", "distributionDomainName": "d1a2f3a4c5o6d.cloudfront.net", "certificateName": "uploadedCertificate", "certificateUploadDate": 1462565487 }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中公共 REST 的自定义域名。 示例 2:获取有关私有自定义域名的信息 以下 get-domain-name示例获取有关私有自定义域名的信息。aws apigateway get-domain-name \ --domain-nameapi.private.domain.tld\ --domain-name-idabcd1234输出: { "domainName": "my.private.domain.tld", "domainNameId": "abcd1234", "domainNameArn": "arn:aws:apigateway:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234", "certificateArn": "arn:aws:acm:us-east-1:012345678910:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3", "certificateUploadDate": "2024-09-10T10:31:20-07:00", "endpointConfiguration": { "types": [ "PRIVATE" ] }, "domainNameStatus": "AVAILABLE", "securityPolicy": "TLS_1_2", "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"execute-api:Invoke\",\"Resource\":\"arn:aws:execute-api:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234\"},{\"Effect\":\"Deny\",\"Principal\":\"*\",\"Action\":\"execute-api:Invoke\",\"Resource\":\"arn:aws:execute-api:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234\",\"Condition\":{\"StringNotEquals\":{\"aws:SourceVpc\":\"vpc-1a2b3c4d\"}}}]}" }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中公共 REST 的自定义域名。 - 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetDomainName 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-domain-names。
- AWS CLI
- 
             
                    示例 1:获取自定义域名列表 以下 get-domain-names命令获取域名列表。aws apigateway get-domain-names输出: { "items": [ { "distributionDomainName": "d9511k3l09bkd.cloudfront.net", "certificateUploadDate": 1452812505, "certificateName": "my_custom_domain-certificate", "domainName": "subdomain.domain.tld" } ] }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中的私有自定义域名。 示例 2:获取此 AWS 账户拥有的自定义域名列表 以下 get-domain-names命令获取该 AWS 账户拥有的域名列表。aws apigateway get-domain-names \ --resource-ownerSELF输出: { "items": [ { "domainName": "my.domain.tld", "domainNameArn": "arn:aws:apigateway:us-east-1::/domainnames/my.private.domain.tld", "certificateUploadDate": "2024-08-15T17:02:55-07:00", "regionalDomainName": "d-abcd1234.execute-api.us-east-1.amazonaws.com", "regionalHostedZoneId": "Z1UJRXOUMOOFQ8", "regionalCertificateArn": "arn:aws:acm:us-east-1:012345678910:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3", "endpointConfiguration": { "types": [ "REGIONAL" ] }, "domainNameStatus": "AVAILABLE", "securityPolicy": "TLS_1_2" }, { "domainName": "my.private.domain.tld", "domainNameId": "abcd1234", "domainNameArn": "arn:aws:apigateway:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234", "certificateArn": "arn:aws:acm:us-east-1:012345678910:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3", "certificateUploadDate": "2024-11-26T11:44:40-08:00", "endpointConfiguration": { "types": [ "PRIVATE" ] }, "domainNameStatus": "AVAILABLE", "securityPolicy": "TLS_1_2" } ] }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中的私有自定义域名。 示例 3:获取其他 AWS 账户拥有的自定义域名列表,您可以与之创建域名访问关联。 以下 get-domain-names命令会获取您有权与之创建域名访问关联的其他 AWS 账户所拥有的域名列表。aws apigateway get-domain-names \ --resource-ownerOTHER_ACCOUNTS输出: { "items": [ { "domainName": "my.private.domain.tld", "domainNameId": "abcd1234", "domainNameArn": "arn:aws:apigateway:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234" } ] }有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中的私有自定义域名。 - 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetDomainNames 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-export。
- AWS CLI
- 
             
                    获取阶段的 JSON Swagger 模板 命令: aws apigateway get-export --rest-api-ida1b2c3d4e5--stage-namedev--export-typeswagger/path/to/filename.json获取阶段的 JSON Swagger 模板 + API Gateway 扩展 命令: aws apigateway get-export --parameters extensions='integrations' --rest-api-ida1b2c3d4e5--stage-namedev--export-typeswagger/path/to/filename.json获取阶段的 JSON Swagger 模板 + Postman 扩展 命令: aws apigateway get-export --parameters extensions='postman' --rest-api-ida1b2c3d4e5--stage-namedev--export-typeswagger/path/to/filename.json- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetExport 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-integration-response。
- AWS CLI
- 
             
                    获取在 REST API 资源下定义的 HTTP 方法的集成响应配置 命令: aws apigateway get-integration-response --rest-api-id1234123412--resource-idy9h6rt--http-methodGET--status-code200输出: { "statusCode": "200", "responseTemplates": { "application/json": null } }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetIntegrationResponse 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-integration。
- AWS CLI
- 
             
                    获取在 REST API 资源下定义的 HTTP 方法的集成配置 命令: aws apigateway get-integration --rest-api-id1234123412--resource-idy9h6rt--http-methodGET输出: { "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 的详细信息,请参阅AWS CLI 命令参考GetIntegration 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-method-response。
- AWS CLI
- 
             
                    获取在 REST API 资源下定义的 HTTP 方法的方法响应资源配置 命令: aws apigateway get-method-response --rest-api-id1234123412--resource-idy9h6rt--http-methodGET--status-code200输出: { "responseModels": { "application/json": "Empty" }, "statusCode": "200" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetMethodResponse 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-method。
- AWS CLI
- 
             
                    获取在 REST API 资源下定义的 HTTP 方法的方法资源配置 命令: aws apigateway get-method --rest-api-id1234123412--resource-idy9h6rt--http-methodGET输出: { "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 的详细信息,请参阅AWS CLI 命令参考GetMethod 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-model-template。
- AWS CLI
- 
             
                    获取在 REST API 下定义的模型的映射模板 命令: aws apigateway get-model-template --rest-api-id1234123412--model-nameEmpty输出: { "value": "#set($inputRoot = $input.path('$'))\n{ }" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetModelTemplate 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-model。
- AWS CLI
- 
             
                    获取在 REST API 下定义的模型的配置 命令: aws apigateway get-model --rest-api-id1234123412--model-nameEmpty输出: { "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 的详细信息,请参阅AWS CLI 命令参考GetModel 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-models。
- AWS CLI
- 
             
                    获取 REST API 的模板列表 命令: aws apigateway get-models --rest-api-id1234123412输出: { "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 的详细信息,请参阅AWS CLI 命令参考GetModels 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-resource。
- AWS CLI
- 
             
                    获取有关资源的信息 命令: aws apigateway get-resource --rest-api-id1234123412--resource-idzwo0y3输出: { "path": "/path", "pathPart": "path", "id": "zwo0y3", "parentId": "uyokt6ij2g" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetResource 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-resources。
- AWS CLI
- 
             
                    获取 REST API 的资源列表 命令: aws apigateway get-resources --rest-api-id1234123412输出: { "items": [ { "path": "/resource/subresource", "resourceMethods": { "POST": {} }, "id": "024ace", "pathPart": "subresource", "parentId": "ai5b02" } ] }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetResources 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-rest-api。
- AWS CLI
- 
             
                    获取有关 API 的信息 命令: aws apigateway get-rest-api --rest-api-id1234123412输出: { "name": "myAPI", "id": "o1y243m4f5", "createdDate": 1453416433 }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetRestApi 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-rest-apis。
- AWS CLI
- 
             
                    要获取 REST 列表 APIs 命令: aws apigateway get-rest-apis输出: { "items": [ { "createdDate": 1438884790, "id": "12s44z21rb", "name": "My First API" } ] }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetRestApis 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-sdk。
- AWS CLI
- 
             
                    获取适用于 REST API 阶段的 Android SDK 命令: aws apigateway get-sdk --rest-api-id1234123412--stage-namedev--sdk-typeandroid--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 SDK 命令: aws apigateway get-sdk --rest-api-id1234123412--stage-namedev--sdk-typeobjectivec--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 SDK 命令: aws apigateway get-sdk --rest-api-id1234123412--stage-namedev--sdk-typejavascript/path/to/javascript_sdk.zip输出: { "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"javascript_2016-02-22_23-52Z.zip\"" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetSdk 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-stage。
- AWS CLI
- 
             
                    获取有关 API 阶段的信息 命令: aws apigateway get-stage --rest-api-id1234123412--stage-namedev输出: { "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 的详细信息,请参阅AWS CLI 命令参考GetStage 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-stages。
- AWS CLI
- 
             
                    获取 REST API 的阶段列表 命令: aws apigateway get-stages --rest-api-id1234123412输出: { "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 的详细信息,请参阅AWS CLI 命令参考GetStages 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-usage-plan-key。
- AWS CLI
- 
             
                    获取与使用计划关联的 API 密钥的详细信息 命令: aws apigateway get-usage-plan-key --usage-plan-ida1b2c3--key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetUsagePlanKey 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-usage-plan-keys。
- AWS CLI
- 
             
                    获取与使用计划关联的 API 密钥列表 命令: aws apigateway get-usage-plan-keys --usage-plan-ida1b2c3- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetUsagePlanKeys 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-usage-plan。
- AWS CLI
- 
             
                    获取使用计划的详细信息 命令: aws apigateway get-usage-plan --usage-plan-ida1b2c3- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetUsagePlan 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-usage-plans。
- AWS CLI
- 
             
                    获取所有使用计划的详细信息 命令: aws apigateway get-usage-plans- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetUsagePlans 中的。 
 
- 
                    
以下代码示例演示了如何使用 get-usage。
- AWS CLI
- 
             
                    获取使用计划的使用详细信息 命令: aws apigateway get-usage --usage-plan-ida1b2c3--start-date"2016-08-16"--end-date"2016-08-17"- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考GetUsage 中的。 
 
- 
                    
以下代码示例演示了如何使用 import-rest-api。
- AWS CLI
- 
             
                    导入 Swagger 模板并创建 API 命令: aws apigateway import-rest-api --body 'file:///path/to/API_Swagger_template.json'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考ImportRestApi 中的。 
 
- 
                    
以下代码示例演示了如何使用 put-integration-response。
- AWS CLI
- 
             
                    使用定义的映射模板创建集成响应作为默认响应 命令: aws apigateway put-integration-response --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--status-code200--selection-pattern "" --response-templates '{"application/json": "{\"json\": \"template\"}"}'使用正则表达式为 400 的静态定义的标头值创建集成响应 命令: aws apigateway put-integration-response --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--status-code400--selection-pattern400--response-parameters '{"method.response.header.custom-header": "'"'"'custom-value'"'"'"}'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考PutIntegrationResponse 中的。 
 
- 
                    
以下代码示例演示了如何使用 put-integration。
- AWS CLI
- 
             
                    创建 MOCK 集成请求 命令: aws apigateway put-integration --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--typeMOCK--request-templates '{ "application/json": "{\"statusCode\": 200}" }'创建 HTTP 集成请求 命令: aws apigateway put-integration --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--typeHTTP--integration-http-methodGET--uri 'https://domain.tld/path'使用 Lambda 函数终端节点创建 AWS 集成请求 命令: aws apigateway put-integration --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--typeAWS--integration-http-methodPOST--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 的详细信息,请参阅AWS CLI 命令参考PutIntegration 中的。 
 
- 
                    
以下代码示例演示了如何使用 put-method-response。
- AWS CLI
- 
             
                    基于指定状态代码,通过自定义方法响应标头创建方法响应 命令: aws apigateway put-method-response --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--status-code400--response-parameters"method.response.header.custom-header=false"- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考PutMethodResponse 中的。 
 
- 
                    
以下代码示例演示了如何使用 put-method。
- AWS CLI
- 
             
                    在没有授权、没有 API 密钥和自定义方法请求标头的情况下为 API 中的资源创建方法 命令: aws apigateway put-method --rest-api-id1234123412--resource-ida1b2c3--http-methodPUT--authorization-type"NONE"--no-api-key-required --request-parameters"method.request.header.custom-header=false"- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考PutMethod 中的。 
 
- 
                    
以下代码示例演示了如何使用 put-rest-api。
- AWS CLI
- 
             
                    使用 Swagger 模板覆盖现有 API 命令: aws apigateway put-rest-api --rest-api-id1234123412--modeoverwrite--body 'fileb:///path/to/API_Swagger_template.json'将 Swagger 模板合并到现有 API 中 命令: aws apigateway put-rest-api --rest-api-id1234123412--modemerge--body 'fileb:///path/to/API_Swagger_template.json'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考PutRestApi 中的。 
 
- 
                    
以下代码示例演示了如何使用 reject-domain-name-access-association。
- AWS CLI
- 
             
                    拒绝域名访问关联 以下 reject-domain-name-access-association示例拒绝私有自定义域名和 VPC 端点之间的域名访问关联。aws apigateway reject-domain-name-access-association \ --domain-name-access-association-arnarn:aws:apigateway:us-west-2:012345678910:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg\ --domain-name-arnarn:aws:apigateway:us-east-1:012345678910:/domainnames/my.private.domain.tld+abcd1234此命令不生成任何输出。 有关更多信息,请参阅 Amazon API Gateway 开发者指南 APIs 中的 API Gateway 中的私有自定义域名。 - 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考RejectDomainNameAccessAssociation 中的。 
 
- 
                    
以下代码示例演示了如何使用 test-invoke-authorizer。
- AWS CLI
- 
             
                    测试包含所需标头和值的自定义授权方的调用请求 命令: aws apigateway test-invoke-authorizer --rest-api-id1234123412--authorizer-id5yid1t--headers Authorization='Value'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考TestInvokeAuthorizer 中的。 
 
- 
                    
以下代码示例演示了如何使用 test-invoke-method。
- AWS CLI
- 
             
                    通过发出 GET 请求,在 API 中测试调用根资源 命令: aws apigateway test-invoke-method --rest-api-id1234123412--resource-idavl5sg8fw8--http-methodGET--path-with-query-string '/'通过发出指定路径参数值的 GET 请求,在 API 中测试调用子资源 命令: aws apigateway test-invoke-method --rest-api-id1234123412--resource-id3gapai--http-methodGET--path-with-query-string '/pets/1'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考TestInvokeMethod 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-account。
- AWS 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 的详细信息,请参阅AWS CLI 命令参考UpdateAccount 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-api-key。
- AWS CLI
- 
             
                    更改 API 密钥的名称 命令: aws apigateway update-api-key --api-keysNvjQDMReA1eEQPNAW8r37XsU2rDD7fc7m2SiMnu--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-keysNvjQDMReA1eEQPNAW8r37XsU2rDD7fc7m2SiMnu--patch-operations op='replace',path='/enabled',value='false'输出: { "description": "currentDescription", "enabled": false, "stageKeys": [ "41t2j324r5/dev" ], "lastUpdatedDate": 1470086052, "createdDate": 1445460347, "id": "sNvjQDMReA1vEQPNzW8r3dXsU2rrD7fcjm2SiMnu", "name": "newName" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateApiKey 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-authorizer。
- AWS CLI
- 
             
                    更改自定义授权方的名称 命令: aws apigateway update-authorizer --rest-api-id1234123412--authorizer-idgfi4n3--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-id1234123412--authorizer-idgfi4n3--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 的详细信息,请参阅AWS CLI 命令参考UpdateAuthorizer 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-base-path-mapping。
- AWS CLI
- 
             
                    更改自定义域名的基础路径 命令: aws apigateway update-base-path-mapping --domain-nameapi.domain.tld--base-pathprod--patch-operations op='replace',path='/basePath',value='v1'输出: { "basePath": "v1", "restApiId": "1234123412", "stage": "api" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateBasePathMapping 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-client-certificate。
- AWS CLI
- 
             
                    更新客户端证书的说明 命令: aws apigateway update-client-certificate --client-certificate-ida1b2c3--patch-operations op='replace',path='/description',value='My new description'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateClientCertificate 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-deployment。
- AWS CLI
- 
             
                    更改部署的说明 命令: aws apigateway update-deployment --rest-api-id1234123412--deployment-idztt4m2--patch-operations op='replace',path='/description',value='newDescription'输出: { "description": "newDescription", "id": "ztt4m2", "createdDate": 1455218022 }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateDeployment 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-domain-name。
- AWS CLI
- 
             
                    更改自定义域名的证书名称 以下 update-domain-name示例更改自定义域的证书名称。aws apigateway update-domain-name \ --domain-nameapi.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 的详细信息,请参阅AWS CLI 命令参考UpdateDomainName 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-integration-response。
- AWS CLI
- 
             
                    将集成响应标头更改为具有“*”的静态映射 命令: aws apigateway update-integration-response --rest-api-id1234123412--resource-id3gapai--http-methodGET--status-code200--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-id1234123412--resource-id3gapai--http-methodGET--status-code200--patch-operations op='remove',path='/responseParameters/method.response.header.Access-Control-Allow-Origin'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateIntegrationResponse 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-integration。
- AWS CLI
- 
             
                    添加配置了输入直通的“Content-Type: application/json”映射模板 命令: aws apigateway update-integration \ --rest-api-ida1b2c3d4e5\ --resource-ida1b2c3\ --http-methodPOST\ --patch-operations"op='add',path='/requestTemplates/application~1json'"更新(替换)使用自定义模板配置的“Content-Type: application/json”映射模板 命令: aws apigateway update-integration \ --rest-api-ida1b2c3d4e5\ --resource-ida1b2c3\ --http-methodPOST\ --patch-operations "op='replace',path='/requestTemplates/application~1json',value='{"example": "json"}'"使用输入直通更新(替换)与“Content-Type: application/json”关联的自定义模板 命令: aws apigateway update-integration \ --rest-api-ida1b2c3d4e5\ --resource-ida1b2c3\ --http-methodPOST\ --patch-operations"op='replace',path='requestTemplates/application~1json'"移除“Content-Type: application/json”映射模板 命令: aws apigateway update-integration \ --rest-api-ida1b2c3d4e5\ --resource-ida1b2c3\ --http-methodPOST\ --patch-operations"op='remove',path='/requestTemplates/application~1json'"- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateIntegration 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-method-response。
- AWS CLI
- 
             
                    为方法中的 200 响应创建新的方法响应标头,并将其定义为非必填(默认值) 命令: aws apigateway update-method-response --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--status-code200--patch-operations op="add",path="/responseParameters/method.response.header.custom-header",value="false"在方法中删除 200 响应的响应模型 命令: aws apigateway update-method-response --rest-api-id1234123412--resource-ida1b2c3--http-methodGET--status-code200--patch-operations op="remove",path="/responseModels/application~1json"- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateMethodResponse 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-method。
- AWS CLI
- 
             
                    示例 1:将方法修改为需要 API 密钥 以下 update-method示例将方法修改为需要 API 密钥。aws apigateway update-method \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --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-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --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-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --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 的详细信息,请参阅AWS CLI 命令参考UpdateMethod 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-model。
- AWS CLI
- 
             
                    在 API 中更改模型的说明 命令: aws apigateway update-model --rest-api-id1234123412--model-name 'Empty' --patch-operations op=replace,path=/description,value='New Description'在 API 中更改模型的架构 命令: aws apigateway update-model --rest-api-id1234123412--model-name 'Empty' --patch-operations op=replace,path=/schema,value='"{ \"$schema\": \"http://json-schema.org/draft-04/schema#\", \"title\" : \"Empty Schema\", \"type\" : \"object\" }"'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateModel 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-resource。
- AWS CLI
- 
             
                    在 API 中移动资源并将其置于不同的父资源下 命令: aws apigateway update-resource --rest-api-id1234123412--resource-id1a2b3c--patch-operations op=replace,path=/parentId,value='3c2b1a'输出: { "path": "/resource", "pathPart": "resource", "id": "1a2b3c", "parentId": "3c2b1a" }在 API 中重命名资源(pathPart) 命令: aws apigateway update-resource --rest-api-id1234123412--resource-id1a2b3c--patch-operationsop=replace,path=/pathPart,value=newresourcename输出: { "path": "/newresourcename", "pathPart": "newresourcename", "id": "1a2b3c", "parentId": "3c2b1a" }- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateResource 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-rest-api。
- AWS CLI
- 
             
                    更改 API 的名称 命令: aws apigateway update-rest-api --rest-api-id1234123412--patch-operations op=replace,path=/name,value='New Name'更改 API 的说明 命令: aws apigateway update-rest-api --rest-api-id1234123412--patch-operations op=replace,path=/description,value='New Description'- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateRestApi 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-stage。
- AWS CLI
- 
             
                    示例 1:覆盖资源和方法的阶段设置 以下 update-stage示例覆盖了阶段设置并关闭了特定资源和方法的完整 request/response 日志记录。aws apigateway update-stage \ --rest-api-id1234123412\ --stage-name 'dev' \ --patch-operationsop=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 阶段的所有资源和方法开启了完整 request/response 日志记录。aws apigateway update-stage \ --rest-api-id1234123412\ --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 的详细信息,请参阅AWS CLI 命令参考UpdateStage 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-usage-plan。
- AWS CLI
- 
             
                    更改使用计划中定义的期限 命令: aws apigateway update-usage-plan --usage-plan-ida1b2c3--patch-operations op="replace",path="/quota/period",value="MONTH"更改使用计划中定义的配额限制 命令: aws apigateway update-usage-plan --usage-plan-ida1b2c3--patch-operations op="replace",path="/quota/limit",value="500"更改使用计划中定义的节流速率限制 命令: aws apigateway update-usage-plan --usage-plan-ida1b2c3--patch-operations op="replace",path="/throttle/rateLimit",value="10"更改使用计划中定义的节流爆发限制 命令: aws apigateway update-usage-plan --usage-plan-ida1b2c3--patch-operations op="replace",path="/throttle/burstLimit",value="20"- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateUsagePlan 中的。 
 
- 
                    
以下代码示例演示了如何使用 update-usage。
- AWS CLI
- 
             
                    临时修改使用计划中定义的当前时间段内 API 密钥的配额 命令: aws apigateway update-usage --usage-plan-ida1b2c3--key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu--patch-operations op="replace",path="/remaining",value="50"- 
                    有关 API 的详细信息,请参阅AWS CLI 命令参考UpdateUsage 中的。 
 
-