本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
API 使用 的閘道範例 AWS CLI
下列程式碼範例示範如何透過 AWS Command Line Interface 搭配 API Gateway 使用 來執行動作和實作常見案例。
Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。
每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。
主題
動作
下列程式碼範例示範如何使用 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詳細資訊,請參閱 命令參考 CreateApiKey
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 create-authorizer
。
- AWS CLI
-
範例 1:為 建立以字符為基礎的API閘道自訂授權方 API
下列
create-authorizer
範例會建立以權杖為基礎的授權方。aws apigateway create-authorizer \ --rest-api-id
1234123412
\ --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:為 建立以 Cognito 使用者集區為基礎的API閘道自訂授權方 API
下列
create-authorizer
範例會建立以 Cognito 使用者集區為基礎的API閘道自訂授權器。aws apigateway create-authorizer \ --rest-api-id
1234123412
\ --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
下列
create-authorizer
範例會建立以請求為基礎的授權方。aws apigateway create-authorizer \ --rest-api-id
1234123412
\ --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詳細資訊,請參閱 命令參考 CreateAuthorizer
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 create-base-path-mapping
。
- AWS CLI
-
為自訂網域名稱建立基本路徑映射
命令:
aws apigateway create-base-path-mapping --domain-name
subdomain.domain.tld
--rest-api-id1234123412
--stageprod
--base-pathv1
-
如需API詳細資訊,請參閱 命令參考 CreateBasePathMapping
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 create-deployment
。
- AWS CLI
-
將 的已設定資源部署API至新的階段
命令:
aws apigateway create-deployment --rest-api-id
1234123412
--stage-namedev
--stage-description 'Development Stage
' --description 'First deployment to the dev stage
'將 的已設定資源部署API至現有階段
命令:
aws apigateway create-deployment --rest-api-id
1234123412
--stage-namedev
--description 'Second deployment to the dev stage
'將 的已設定資源部署API到具有階段變數的現有階段
aws apigateway create-deployment --rest-api-id 1234123412 --stage-name dev --description 'Third deployment to the dev stage' --variables key='value',otherKey='otherValue'
-
如需API詳細資訊,請參閱 命令參考 CreateDeployment
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 create-domain-name
。
- AWS 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詳細資訊,請參閱 命令參考 CreateDomainName
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 create-model
。
- AWS 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詳細資訊,請參閱 命令參考 CreateModel
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 create-resource
。
- AWS CLI
-
若要在 中建立資源 API
命令:
aws apigateway create-resource --rest-api-id
1234123412
--parent-ida1b2c3
--path-part 'new-resource
'-
如需API詳細資訊,請參閱 命令參考 CreateResource
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 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詳細資訊,請參閱 命令參考 CreateRestApi
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 create-stage
。
- AWS CLI
-
在 中建立API包含現有部署的階段
命令:
aws apigateway create-stage --rest-api-id
1234123412
--stage-name 'dev
' --description 'Development stage
' --deployment-ida1b2c3
在 中建立階段API,其中包含現有的部署和自訂階段變數
命令:
aws apigateway create-stage --rest-api-id
1234123412
--stage-name 'dev
' --description 'Development stage
' --deployment-ida1b2c3
--variables key='value',otherKey='otherValue'-
如需API詳細資訊,請參閱 命令參考 CreateStage
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 create-usage-plan-key
。
- AWS CLI
-
將現有API金鑰與使用計畫建立關聯
命令:
aws apigateway create-usage-plan-key --usage-plan-id
a1b2c3
--key-type"API_KEY"
--key-id4vq3yryqm5
-
如需API詳細資訊,請參閱 命令參考 CreateUsagePlanKey
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 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詳細資訊,請參閱 命令參考 CreateUsagePlan
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-api-key
。
- AWS CLI
-
若要刪除API金鑰
命令:
aws apigateway delete-api-key --api-key
8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk
-
如需API詳細資訊,請參閱 命令參考 DeleteApiKey
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-authorizer
。
- AWS CLI
-
若要在 中刪除自訂授權方 API
命令:
aws apigateway delete-authorizer --rest-api-id
1234123412
--authorizer-id7gkfbo
-
如需API詳細資訊,請參閱 命令參考 DeleteAuthorizer
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-base-path-mapping
。
- AWS CLI
-
刪除自訂網域名稱的基本路徑映射
命令:
aws apigateway delete-base-path-mapping --domain-name '
api.domain.tld
' --base-path 'dev
'-
如需API詳細資訊,請參閱 命令參考 DeleteBasePathMapping
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-client-certificate
。
- AWS CLI
-
若要刪除用戶端憑證
命令:
aws apigateway delete-client-certificate --client-certificate-id
a1b2c3
-
如需API詳細資訊,請參閱 命令參考 DeleteClientCertificate
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-deployment
。
- AWS CLI
-
若要刪除 中的部署 API
命令:
aws apigateway delete-deployment --rest-api-id
1234123412
--deployment-ida1b2c3
-
如需API詳細資訊,請參閱 命令參考 DeleteDeployment
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-domain-name
。
- AWS CLI
-
若要刪除自訂網域名稱
命令:
aws apigateway delete-domain-name --domain-name '
api.domain.tld
'-
如需API詳細資訊,請參閱 命令參考 DeleteDomainName
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-integration-response
。
- AWS CLI
-
若要在 中刪除指定資源、方法和狀態碼的整合回應 API
命令:
aws apigateway delete-integration-response --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
--status-code200
-
如需API詳細資訊,請參閱 命令參考 DeleteIntegrationResponse
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-integration
。
- AWS CLI
-
若要在 中刪除指定資源和方法的整合 API
命令:
aws apigateway delete-integration --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
-
如需API詳細資訊,請參閱 命令參考 DeleteIntegration
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-method-response
。
- AWS CLI
-
若要刪除 中指定資源、方法和狀態碼的方法回應 API
命令:
aws apigateway delete-method-response --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
--status-code200
-
如需API詳細資訊,請參閱 命令參考 DeleteMethodResponse
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-method
。
- AWS CLI
-
刪除 中指定資源的方法 API
命令:
aws apigateway delete-method --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
-
如需API詳細資訊,請參閱 命令參考 DeleteMethod
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-model
。
- AWS CLI
-
在指定的 中刪除模型 API
命令:
aws apigateway delete-model --rest-api-id
1234123412
--model-name 'customModel
'-
如需API詳細資訊,請參閱 命令參考 DeleteModel
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-resource
。
- AWS CLI
-
若要刪除 中的資源 API
命令:
aws apigateway delete-resource --rest-api-id
1234123412
--resource-ida1b2c3
-
如需API詳細資訊,請參閱 命令參考 DeleteResource
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-rest-api
。
- AWS CLI
-
若要刪除 API
命令:
aws apigateway delete-rest-api --rest-api-id
1234123412
-
如需API詳細資訊,請參閱 命令參考 DeleteRestApi
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-stage
。
- AWS CLI
-
若要刪除 中的階段 API
命令:
aws apigateway delete-stage --rest-api-id
1234123412
--stage-name 'dev
'-
如需API詳細資訊,請參閱 命令參考 DeleteStage
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-usage-plan-key
。
- AWS CLI
-
從用量計劃中移除API金鑰
命令:
aws apigateway delete-usage-plan-key --usage-plan-id
a1b2c3
--key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu
-
如需API詳細資訊,請參閱 命令參考 DeleteUsagePlanKey
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 delete-usage-plan
。
- AWS CLI
-
刪除用量計劃
命令:
aws apigateway delete-usage-plan --usage-plan-id
a1b2c3
-
如需API詳細資訊,請參閱 命令參考 DeleteUsagePlan
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 flush-stage-authorizers-cache
。
- AWS CLI
-
若要排清階段上的所有授權方快取項目
命令:
aws apigateway flush-stage-authorizers-cache --rest-api-id
1234123412
--stage-namedev
-
如需API詳細資訊,請參閱 命令參考 FlushStageAuthorizersCache
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 flush-stage-cache
。
- AWS CLI
-
若要排清 階段API的快取
命令:
aws apigateway flush-stage-cache --rest-api-id
1234123412
--stage-namedev
-
如需API詳細資訊,請參閱 命令參考 FlushStageCache
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 generate-client-certificate
。
- AWS CLI
-
若要建立用戶端SSL憑證
命令:
aws apigateway generate-client-certificate --description '
My First Client Certificate
'-
如需API詳細資訊,請參閱 命令參考 GenerateClientCertificate
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-account
。
- AWS CLI
-
若要取得API閘道帳戶設定
命令:
aws apigateway get-account
輸出:
{ "cloudwatchRoleArn": "arn:aws:iam::123412341234:role/APIGatewayToCloudWatchLogsRole", "throttleSettings": { "rateLimit": 500.0, "burstLimit": 1000 } }
-
如需API詳細資訊,請參閱 命令參考 GetAccount
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-api-key
。
- AWS 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詳細資訊,請參閱 命令參考 GetApiKey
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 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詳細資訊,請參閱 命令參考 GetApiKeys
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-authorizer
。
- AWS CLI
-
若要取得每個API授權方的API閘道設定
命令:
aws apigateway get-authorizer --rest-api-id
1234123412
--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詳細資訊,請參閱 命令參考 GetAuthorizer
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-authorizers
。
- AWS 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詳細資訊,請參閱 命令參考 GetAuthorizers
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-base-path-mapping
。
- AWS CLI
-
取得自訂網域名稱的基本路徑映射
命令:
aws apigateway get-base-path-mapping --domain-name
subdomain.domain.tld
--base-pathv1
輸出:
{ "basePath": "v1", "restApiId": "1234w4321e", "stage": "api" }
-
如需API詳細資訊,請參閱 命令參考 GetBasePathMapping
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-base-path-mappings
。
- AWS 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詳細資訊,請參閱 命令參考 GetBasePathMappings
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-client-certificate
。
- AWS CLI
-
若要取得用戶端憑證
命令:
aws apigateway get-client-certificate --client-certificate-id
a1b2c3
-
如需API詳細資訊,請參閱 命令參考 GetClientCertificate
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 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詳細資訊,請參閱 命令參考 GetClientCertificates
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-deployment
。
- AWS CLI
-
若要取得部署的相關資訊
命令:
aws apigateway get-deployment --rest-api-id
1234123412
--deployment-idztt4m2
輸出:
{ "description": "myDeployment", "id": "ztt4m2", "createdDate": 1455218022 }
-
如需API詳細資訊,請參閱 命令參考 GetDeployment
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-deployments
。
- AWS 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詳細資訊,請參閱 命令參考 GetDeployments
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-domain-name
。
- AWS CLI
-
若要取得自訂網域名稱的相關資訊
命令:
aws apigateway get-domain-name --domain-name
api.domain.tld
輸出:
{ "domainName": "api.domain.tld", "distributionDomainName": "d1a2f3a4c5o6d.cloudfront.net", "certificateName": "uploadedCertificate", "certificateUploadDate": 1462565487 }
-
如需API詳細資訊,請參閱 命令參考 GetDomainName
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-domain-names
。
- AWS CLI
-
若要取得自訂網域名稱的清單
命令:
aws apigateway get-domain-names
輸出:
{ "items": [ { "distributionDomainName": "d9511k3l09bkd.cloudfront.net", "certificateUploadDate": 1452812505, "certificateName": "my_custom_domain-certificate", "domainName": "subdomain.domain.tld" } ] }
-
如需API詳細資訊,請參閱 命令參考 GetDomainNames
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-export
。
- AWS CLI
-
取得階段的 JSON Swagger 範本
命令:
aws apigateway get-export --rest-api-id
a1b2c3d4e5
--stage-namedev
--export-typeswagger
/path/to/filename.json
取得階段的 JSON Swagger 範本 + API Gateway Extentions
命令:
aws apigateway get-export --parameters extensions='integrations' --rest-api-id
a1b2c3d4e5
--stage-namedev
--export-typeswagger
/path/to/filename.json
取得階段的 JSON Swagger 範本 + Postman 擴充功能
命令:
aws apigateway get-export --parameters extensions='postman' --rest-api-id
a1b2c3d4e5
--stage-namedev
--export-typeswagger
/path/to/filename.json
-
如需API詳細資訊,請參閱 命令參考 GetExport
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-integration-response
。
- AWS CLI
-
取得 的資源下定義HTTP方法RESTAPI的整合回應組態
命令:
aws apigateway get-integration-response --rest-api-id
1234123412
--resource-idy9h6rt
--http-methodGET
--status-code200
輸出:
{ "statusCode": "200", "responseTemplates": { "application/json": null } }
-
如需API詳細資訊,請參閱 命令參考 GetIntegrationResponse
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-integration
。
- AWS CLI
-
取得 的資源下定義HTTP方法RESTAPI的整合組態
命令:
aws apigateway get-integration --rest-api-id
1234123412
--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詳細資訊,請參閱 命令參考 GetIntegration
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-method-response
。
- AWS CLI
-
取得 的資源下定義HTTP方法的方法回應RESTAPI資源組態
命令:
aws apigateway get-method-response --rest-api-id
1234123412
--resource-idy9h6rt
--http-methodGET
--status-code200
輸出:
{ "responseModels": { "application/json": "Empty" }, "statusCode": "200" }
-
如需API詳細資訊,請參閱 命令參考 GetMethodResponse
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-method
。
- AWS CLI
-
取得 的資源下定義HTTP方法的方法RESTAPI資源組態
命令:
aws apigateway get-method --rest-api-id
1234123412
--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詳細資訊,請參閱 命令參考 GetMethod
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-model-template
。
- AWS CLI
-
若要取得在 下定義的模型的映射範本 REST API
命令:
aws apigateway get-model-template --rest-api-id
1234123412
--model-nameEmpty
輸出:
{ "value": "#set($inputRoot = $input.path('$'))\n{ }" }
-
如需API詳細資訊,請參閱 命令參考 GetModelTemplate
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-model
。
- AWS CLI
-
若要取得在 下定義的模型組態 REST API
命令:
aws apigateway get-model --rest-api-id
1234123412
--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詳細資訊,請參閱 命令參考 GetModel
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-models
。
- AWS 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詳細資訊,請參閱 命令參考 GetModels
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-resource
。
- AWS CLI
-
取得資源的相關資訊
命令:
aws apigateway get-resource --rest-api-id
1234123412
--resource-idzwo0y3
輸出:
{ "path": "/path", "pathPart": "path", "id": "zwo0y3", "parentId": "uyokt6ij2g" }
-
如需API詳細資訊,請參閱 命令參考 GetResource
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-resources
。
- AWS CLI
-
若要取得 的資源清單 REST API
命令:
aws apigateway get-resources --rest-api-id
1234123412
輸出:
{ "items": [ { "path": "/resource/subresource", "resourceMethods": { "POST": {} }, "id": "024ace", "pathPart": "subresource", "parentId": "ai5b02" } ] }
-
如需API詳細資訊,請參閱 命令參考 GetResources
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-rest-api
。
- AWS CLI
-
若要取得 的相關資訊 API
命令:
aws apigateway get-rest-api --rest-api-id
1234123412
輸出:
{ "name": "myAPI", "id": "o1y243m4f5", "createdDate": 1453416433 }
-
如需API詳細資訊,請參閱 命令參考 GetRestApi
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-rest-apis
。
- AWS CLI
-
若要取得 的清單 REST APIs
命令:
aws apigateway get-rest-apis
輸出:
{ "items": [ { "createdDate": 1438884790, "id": "12s44z21rb", "name": "My First API" } ] }
-
如需API詳細資訊,請參閱 命令參考 GetRestApis
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-sdk
。
- AWS CLI
-
取得RESTAPI階段SDK的 Android
命令:
aws apigateway get-sdk --rest-api-id
1234123412
--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\"" }
若要取得RESTAPI階段IOSSDK的
命令:
aws apigateway get-sdk --rest-api-id
1234123412
--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\"" }
取得RESTAPI階段SDK的 Javascript
命令:
aws apigateway get-sdk --rest-api-id
1234123412
--stage-namedev
--sdk-typejavascript
/path/to/javascript_sdk.zip
輸出:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"javascript_2016-02-22_23-52Z.zip\"" }
-
如需API詳細資訊,請參閱 命令參考 GetSdk
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-stage
。
- AWS CLI
-
若要取得 API階段的相關資訊
命令:
aws apigateway get-stage --rest-api-id
1234123412
--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詳細資訊,請參閱 命令參考 GetStage
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-stages
。
- AWS 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詳細資訊,請參閱 命令參考 GetStages
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-usage-plan-key
。
- AWS CLI
-
若要取得與用量計劃相關聯的API金鑰詳細資訊
命令:
aws apigateway get-usage-plan-key --usage-plan-id
a1b2c3
--key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu
-
如需API詳細資訊,請參閱 命令參考 GetUsagePlanKey
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-usage-plan-keys
。
- AWS CLI
-
若要取得與用量計劃相關聯的API金鑰清單
命令:
aws apigateway get-usage-plan-keys --usage-plan-id
a1b2c3
-
如需API詳細資訊,請參閱 命令參考 GetUsagePlanKeys
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-usage-plan
。
- AWS CLI
-
若要取得用量計劃的詳細資訊
命令:
aws apigateway get-usage-plan --usage-plan-id
a1b2c3
-
如需API詳細資訊,請參閱 命令參考 GetUsagePlan
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-usage-plans
。
- AWS CLI
-
取得所有用量計劃的詳細資訊
命令:
aws apigateway get-usage-plans
-
如需API詳細資訊,請參閱 命令參考 GetUsagePlans
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 get-usage
。
- AWS CLI
-
若要取得用量計畫的用量詳細資訊
命令:
aws apigateway get-usage --usage-plan-id
a1b2c3
--start-date"2016-08-16"
--end-date"2016-08-17"
-
如需API詳細資訊,請參閱 命令參考 GetUsage
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 import-rest-api
。
- AWS CLI
-
若要匯入 Swagger 範本並建立 API
命令:
aws apigateway import-rest-api --body '
file:///path/to/API_Swagger_template.json
'-
如需API詳細資訊,請參閱 命令參考 ImportRestApi
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 put-integration-response
。
- AWS CLI
-
建立整合回應作為預設回應,並定義映射範本
命令:
aws apigateway put-integration-response --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
--status-code200
--selection-pattern "" --response-templates '{"application/json": "{\"json\": \"template\"}"}
'建立 regex 為 400 且靜態定義的標頭值的整合回應
命令:
aws apigateway put-integration-response --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
--status-code400
--selection-pattern400
--response-parameters '{"method.response.header.custom-header": "'"'"'custom-value'"'"'"}'-
如需API詳細資訊,請參閱 命令參考 PutIntegrationResponse
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 put-integration
。
- AWS CLI
-
建立MOCK整合請求
命令:
aws apigateway put-integration --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
--typeMOCK
--request-templates '{ "application/json": "{\"statusCode\": 200}" }
'建立HTTP整合請求
命令:
aws apigateway put-integration --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
--typeHTTP
--integration-http-methodGET
--uri 'https://domain.tld/path
'建立與 Lambda 函數端點的 AWS 整合請求
命令:
aws apigateway put-integration --rest-api-id
1234123412
--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詳細資訊,請參閱 命令參考 PutIntegration
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 put-method-response
。
- AWS CLI
-
在具有自訂方法回應標頭的指定狀態碼下建立方法回應
命令:
aws apigateway put-method-response --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodGET
--status-code400
--response-parameters"method.response.header.custom-header=false"
-
如需API詳細資訊,請參閱 命令參考 PutMethodResponse
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 put-method
。
- AWS CLI
-
若要在 中為資源建立方法,API但不具有授權、無API金鑰和自訂方法請求標頭
命令:
aws apigateway put-method --rest-api-id
1234123412
--resource-ida1b2c3
--http-methodPUT
--authorization-type"NONE"
--no-api-key-required --request-parameters"method.request.header.custom-header=false"
-
如需API詳細資訊,請參閱 命令參考 PutMethod
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 put-rest-api
。
- AWS CLI
-
API使用 Swagger 範本覆寫現有的
命令:
aws apigateway put-rest-api --rest-api-id
1234123412
--modeoverwrite
--body 'fileb:///path/to/API_Swagger_template.json
'將 Swagger 範本合併至現有的 API
命令:
aws apigateway put-rest-api --rest-api-id
1234123412
--modemerge
--body 'fileb:///path/to/API_Swagger_template.json
'-
如需API詳細資訊,請參閱 命令參考 PutRestApi
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 test-invoke-authorizer
。
- AWS CLI
-
測試叫用請求至自訂授權方,包括所需的標頭和值
命令:
aws apigateway test-invoke-authorizer --rest-api-id
1234123412
--authorizer-id5yid1t
--headers Authorization='Value'-
如需API詳細資訊,請參閱 命令參考 TestInvokeAuthorizer
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 test-invoke-method
。
- AWS CLI
-
透過提出GET請求API來測試在 中叫用根資源
命令:
aws apigateway test-invoke-method --rest-api-id
1234123412
--resource-idavl5sg8fw8
--http-methodGET
--path-with-query-string '/
'使用指定的路徑參數值提出GET請求,API測試在 中叫用子資源
命令:
aws apigateway test-invoke-method --rest-api-id
1234123412
--resource-id3gapai
--http-methodGET
--path-with-query-string '/pets/1
'-
如需API詳細資訊,請參閱 命令參考 TestInvokeMethod
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-account
。
- AWS CLI
-
若要變更ARN記錄至 CloudWatch 日誌IAM的角色
命令:
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詳細資訊,請參閱 命令參考 UpdateAccount
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-api-key
。
- AWS 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詳細資訊,請參閱 命令參考 UpdateApiKey
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-authorizer
。
- AWS CLI
-
變更自訂授權方的名稱
命令:
aws apigateway update-authorizer --rest-api-id
1234123412
--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-id
1234123412
--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詳細資訊,請參閱 命令參考 UpdateAuthorizer
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-base-path-mapping
。
- AWS CLI
-
變更自訂網域名稱的基本路徑
命令:
aws apigateway update-base-path-mapping --domain-name
api.domain.tld
--base-pathprod
--patch-operations op='replace',path='/basePath',value='v1'輸出:
{ "basePath": "v1", "restApiId": "1234123412", "stage": "api" }
-
如需API詳細資訊,請參閱 命令參考 UpdateBasePathMapping
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-client-certificate
。
- AWS CLI
-
更新用戶端憑證的說明
命令:
aws apigateway update-client-certificate --client-certificate-id
a1b2c3
--patch-operations op='replace',path='/description',value='My new description'-
如需API詳細資訊,請參閱 命令參考 UpdateClientCertificate
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-deployment
。
- AWS CLI
-
若要變更部署的描述
命令:
aws apigateway update-deployment --rest-api-id
1234123412
--deployment-idztt4m2
--patch-operations op='replace',path='/description',value='newDescription'輸出:
{ "description": "newDescription", "id": "ztt4m2", "createdDate": 1455218022 }
-
如需API詳細資訊,請參閱 命令參考 UpdateDeployment
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-domain-name
。
- AWS 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閘道API中設定 的自訂網域名稱。
-
如需API詳細資訊,請參閱 命令參考 UpdateDomainName
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-integration-response
。
- AWS CLI
-
若要將整合回應標頭變更為具有 '*' 的靜態映射
命令:
aws apigateway update-integration-response --rest-api-id
1234123412
--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-id
1234123412
--resource-id3gapai
--http-methodGET
--status-code200
--patch-operations op='remove',path='/responseParameters/method.response.header.Access-Control-Allow-Origin'-
如需API詳細資訊,請參閱 命令參考 UpdateIntegrationResponse
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-integration
。
- AWS CLI
-
若要新增以 Input Passthrough 設定的 'Content-Type: Application/json' 映射範本
命令:
aws apigateway update-integration \ --rest-api-id
a1b2c3d4e5
\ --resource-ida1b2c3
\ --http-methodPOST
\ --patch-operations"op='add',path='/requestTemplates/application~1json'"
更新 (取代) 以自訂範本設定的 'Content-Type: Application/json' 映射範本
命令:
aws apigateway update-integration \ --rest-api-id
a1b2c3d4e5
\ --resource-ida1b2c3
\ --http-methodPOST
\ --patch-operations "op='replace',path='/requestTemplates/application~1json',value='{"example": "json"}'"更新 (取代) 與 'Content-Type: application/json' 相關聯的自訂範本,搭配 Input Passthrough
命令:
aws apigateway update-integration \ --rest-api-id
a1b2c3d4e5
\ --resource-ida1b2c3
\ --http-methodPOST
\ --patch-operations"op='replace',path='requestTemplates/application~1json'"
若要移除 'Content-Type:application/json' 映射範本
命令:
aws apigateway update-integration \ --rest-api-id
a1b2c3d4e5
\ --resource-ida1b2c3
\ --http-methodPOST
\ --patch-operations"op='remove',path='/requestTemplates/application~1json'"
-
如需API詳細資訊,請參閱 命令參考 UpdateIntegration
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-method-response
。
- AWS CLI
-
在 方法中為 200 個回應建立新的方法回應標頭,並將其定義為不需要 (預設)
命令:
aws apigateway update-method-response --rest-api-id
1234123412
--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-id
1234123412
--resource-ida1b2c3
--http-methodGET
--status-code200
--patch-operations op="remove",path="/responseModels/application~1json"-
如需API詳細資訊,請參閱 命令參考 UpdateMethodResponse
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-method
。
- AWS CLI
-
範例 1:修改方法以要求API金鑰
下列
update-method
範例會修改 方法,以要求 API金鑰。aws apigateway update-method \ --rest-api-id
1234123412
\ --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-id
1234123412
\ --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-id
1234123412
\ --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閘道CLI建立、設定和測試用量計劃RESTAPI,以及控制和管理API閘道RESTAPI中對 的存取。
-
如需API詳細資訊,請參閱 命令參考 UpdateMethod
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-model
。
- AWS 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詳細資訊,請參閱 命令參考 UpdateModel
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-resource
。
- AWS CLI
-
若要移動資源並將其放置在 中的不同父資源之下 API
命令:
aws apigateway update-resource --rest-api-id
1234123412
--resource-id1a2b3c
--patch-operations op=replace,path=/parentId,value='3c2b1a'輸出:
{ "path": "/resource", "pathPart": "resource", "id": "1a2b3c", "parentId": "3c2b1a" }
若要重新命名 中的資源 (pathPart) API
命令:
aws apigateway update-resource --rest-api-id
1234123412
--resource-id1a2b3c
--patch-operationsop=replace,path=/pathPart,value=newresourcename
輸出:
{ "path": "/newresourcename", "pathPart": "newresourcename", "id": "1a2b3c", "parentId": "3c2b1a" }
-
如需API詳細資訊,請參閱 命令參考 UpdateResource
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-rest-api
。
- AWS 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詳細資訊,請參閱 命令參考 UpdateRestApi
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-stage
。
- AWS CLI
-
範例 1:覆寫資源和方法的階段設定
下列
update-stage
範例會覆寫階段設定,並關閉特定資源和方法的完整請求/回應記錄。aws apigateway update-stage \ --rest-api-id
1234123412
\ --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階段所有資源和方法的完整請求/回應記錄。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詳細資訊,請參閱 命令參考 UpdateStage
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-usage-plan
。
- AWS 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詳細資訊,請參閱 命令參考 UpdateUsagePlan
中的 。 AWS CLI
-
下列程式碼範例示範如何使用 update-usage
。
- AWS CLI
-
在用量計劃中定義的目前期間內暫時修改API金鑰的配額
命令:
aws apigateway update-usage --usage-plan-id
a1b2c3
--key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu
--patch-operations op="replace",path="/remaining",value="50"-
如需API詳細資訊,請參閱 命令參考 UpdateUsage
中的 。 AWS CLI
-