There are more AWS SDK examples available in the AWS Doc SDK Examples
API Gateway examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with API Gateway.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use create-api-key.
- AWS CLI
-
To create an API key that is enabled for an existing API and Stage
The following
create-api-keyexample creates an API key that is enabled for an existing API and stage.aws apigateway create-api-key \ --name 'Dev API Key' \ --description 'Used for development' \ --enabled \ --stage-keys restApiId='a1b2c3d4e5',stageName='dev'Output:
{ "id": "c2b7jkd5ge", "value": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6EXAMPLE", "name": "Dev API Key", "description": "Used for development", "enabled": true, "createdDate": "2022-07-18T10:11:18-07:00", "lastUpdatedDate": "2022-07-18T10:11:18-07:00", "stageKeys": [ "a1b2c3d4e5/dev" ] }For more information, see Set up API keys for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateApiKey
in AWS CLI Command Reference.
-
The following code example shows how to use create-authorizer.
- AWS CLI
-
Example 1: To create a token-based API Gateway Custom Authorizer for the API
The following
create-authorizerexample creates a token-based 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:123456789012:function:customAuthFunction/invocations' \ --identity-source 'method.request.header.Authorization' \ --authorizer-result-ttl-in-seconds300Output:
{ "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:123456789012:function:customAuthFunction/invocations", "authorizerResultTtlInSeconds": 300, "identitySource": "method.request.header.Authorization", "type": "TOKEN", "id": "z40xj0" }For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
Example 2: To create a Cognito User Pools based API Gateway Custom Authorizer for the API
The following
create-authorizerexample creates a Cognito User Pools based API Gateway Custom Authorizer.aws apigateway create-authorizer \ --rest-api-id1234123412\ --name 'First_Cognito_Custom_Authorizer' \ --typeCOGNITO_USER_POOLS\ --provider-arns 'arn:aws:cognito-idp:us-west-2:123456789012:userpool/us-west-2_aWcZeQbuD' \ --identity-source 'method.request.header.Authorization'Output:
{ "authType": "cognito_user_pools", "identitySource": "method.request.header.Authorization", "name": "First_Cognito_Custom_Authorizer", "providerARNs": [ "arn:aws:cognito-idp:us-west-2:123456789012:userpool/us-west-2_aWcZeQbuD" ], "type": "COGNITO_USER_POOLS", "id": "5yid1t" }For more information, see Control access to REST APIs using Amazon Cognito user pools as an authorizer in the Amazon API Gateway Developer Guide.
Example 3: To create a request-based API Gateway Custom Authorizer for the API
The following
create-authorizerexample creates a request-based 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:123456789012:function:customAuthFunction/invocations' \ --identity-source 'method.request.header.Authorization,context.accountId' \ --authorizer-result-ttl-in-seconds300Output:
{ "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:123456789012:function:customAuthFunction/invocations", "identitySource": "method.request.header.Authorization,context.accountId", "authorizerResultTtlInSeconds": 300 }For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
-
For API details, see CreateAuthorizer
in AWS CLI Command Reference.
-
The following code example shows how to use create-base-path-mapping.
- AWS CLI
-
To create the base path mapping for a custom domain name
The following
create-base-path-mappingexample creates the base path mapping for a custom domain name.aws apigateway create-base-path-mapping \ --domain-namesubdomain.domain.tld\ --rest-api-id1234123412\ --stageprod\ --base-pathv1Output:
{ "basePath": "v1", "restApiId": "1234123412", "stage": "prod" }For more information, see Custom domain name for public REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateBasePathMapping
in AWS CLI Command Reference.
-
The following code example shows how to use create-deployment.
- AWS CLI
-
Example 1: To deploy the configured resources for an API to a new Stage
The following
create-deploymentexample deploys the configured resources for an API to a new stage.aws apigateway create-deployment \ --rest-api-id1234123412\ --stage-namedev\ --stage-description 'Development Stage' \ --description 'First deployment to the dev stage'Output:
{ "id": "ztt4m2", "description": "First deployment to the dev stage", "createdDate": "2022-07-18T10:11:18-07:00" }Example 2: To deploy the configured resources for an API to an existing stage
The following
create-deploymentexample deploys the configured resources for an API to an existing stage.aws apigateway create-deployment \ --rest-api-id1234123412\ --stage-namedev\ --description 'Second deployment to the dev stage'Output:
{ "id": "u3v4x5", "description": "Second deployment to the dev stage", "createdDate": "2022-07-18T10:19:04-07:00" }Example 3: To deploy the configured resources for an API to an existing stage with Stage Variables
The following
create-deploymentexample deploys the configured resources for an API to an existing stage with stage variables.aws apigateway create-deployment \ --rest-api-id1234123412\ --stage-namedev\ --description 'Third deployment to the dev stage' \ --variables key='value',otherKey='otherValue'Output:
{ "id": "w5x6y7", "description": "Third deployment to the dev stage", "createdDate": "2022-07-18T10:25:42-07:00" }For more information, see Deploy REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateDeployment
in AWS CLI Command Reference.
-
The following code example shows how to use create-domain-name-access-association.
- AWS CLI
-
To create a domain name access association
The following
create-domain-name-access-associationexample creates a domain name access association between a private custom domain name and VPC endpoint.aws apigateway create-domain-name-access-association \ --domain-name-arnarn:aws:apigateway:us-west-2:123456789111:/domainnames/my.private.domain.tld+abcd1234\ --access-association-sourcevpce-abcd1234efg\ --access-association-source-typeVPCEOutput:
{ "domainNameAccessAssociationArn": "arn:aws:apigateway:us-west-2:123456789222:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg", "accessAssociationSource": "vpce-abcd1234efg", "accessAssociationSourceType": "VPCE", "domainNameArn" : "arn:aws:apigateway:us-west-2:123456789111:/domainnames/private.example.com+abcd1234" }For more information, see Custom domain names for private APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateDomainNameAccessAssociation
in AWS CLI Command Reference.
-
The following code example shows how to use create-domain-name.
- AWS CLI
-
Example 1: To create a public custom domain name
The following
create-domain-nameexample creates a public custom 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:123456789012:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3'Output:
{ "domainName": "my.domain.tld", "certificateName": "my.domain.tld cert", "certificateArn": "arn:aws:acm:us-east-1:123456789012: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" }For more information, see Custom domain name for public REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
Example 2: To create a private custom domain name
The following
create-domain-nameexample creates a private custom 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-west-2:123456789012:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3' \ --endpoint-configuration '{"types": ["PRIVATE"]}' \ --security-policy 'TLS_1_2' \ --policyfile://policy.jsonContents of
policy.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" } } } ] }Output:
{ "domainName": "my.private.domain.tld", "domainNameId": "abcd1234", "domainNameArn": "arn:aws:apigateway:us-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234", "certificateArn": "arn:aws:acm:us-west-2:123456789012: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-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234\"},{\"Effect\":\"Deny\",\"Principal\":\"*\",\"Action\":\"execute-api:Invoke\",\"Resource\":\"arn:aws:execute-api:us-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234\",\"Condition\":{\"StringNotEquals\":{\"aws:SourceVpc\":\"vpc-1a2b3c4d\"}}}]}" }For more information, see Custom domain name for public REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateDomainName
in AWS CLI Command Reference.
-
The following code example shows how to use create-model.
- AWS CLI
-
To create a model for an API
The following
create-modelexample creates a model namedfirstModelfor the specified 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" } } } } }'Output:
{ "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\" } } } } }" }For more information, see Data models for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see CreateModel
in AWS CLI Command Reference.
-
The following code example shows how to use create-resource.
- AWS CLI
-
To create a resource in an API
The following
create-resourceexample creates a resource with the path partnew-resourceunder the specified parent resource in an API.aws apigateway create-resource \ --rest-api-id1234123412\ --parent-ida1b2c3\ --path-part 'new-resource'Output:
{ "id": "b2c3d4", "parentId": "a1b2c3", "pathPart": "new-resource", "path": "/new-resource" }For more information, see Develop REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateResource
in AWS CLI Command Reference.
-
The following code example shows how to use create-rest-api.
- AWS CLI
-
Example 1: To create an API
The following
create-rest-apiexample creates an API namedMy First API.aws apigateway create-rest-api \ --name 'My First API' \ --description 'This is my first API'Output:
{ "id": "1234123412", "name": "My First API", "description": "This is my first API", "createdDate": "2022-07-18T10:11:18-07:00", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "EDGE" ] }, "disableExecuteApiEndpoint": false, "rootResourceId": "a1b2c3d4e5" }Example 2: To create a duplicate API from an existing API
The following
create-rest-apiexample creates a duplicate of an existing API by cloning it.aws apigateway create-rest-api \ --name 'Copy of My First API' \ --description 'This is a copy of my first API' \ --clone-from1234123412Output:
{ "id": "5678567856", "name": "Copy of My First API", "description": "This is a copy of my first API", "createdDate": "2022-07-18T10:19:04-07:00", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "EDGE" ] }, "disableExecuteApiEndpoint": false, "rootResourceId": "f6g7h8i9j0" }For more information, see Develop REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateRestApi
in AWS CLI Command Reference.
-
The following code example shows how to use create-stage.
- AWS CLI
-
Example 1: To create a stage in an API which will contain an existing deployment
The following
create-stageexample creates a stage nameddevin an API, which contains an existing deployment.aws apigateway create-stage \ --rest-api-id1234123412\ --stage-name 'dev' \ --description 'Development stage' \ --deployment-ida1b2c3Output:
{ "deploymentId": "a1b2c3", "stageName": "dev", "description": "Development stage", "cacheClusterEnabled": false, "cacheClusterStatus": "NOT_AVAILABLE", "methodSettings": {}, "tracingEnabled": false, "createdDate": "2022-07-18T10:11:18-07:00", "lastUpdatedDate": "2022-07-18T10:11:18-07:00" }Example 2: To create a stage in an API which will contain an existing deployment and custom Stage Variables
The following
create-stageexample creates a stage nameddevin an API, which contains an existing deployment and custom stage variables.aws apigateway create-stage \ --rest-api-id1234123412\ --stage-name 'dev' \ --description 'Development stage' \ --deployment-ida1b2c3\ --variables key='value',otherKey='otherValue'Output:
{ "deploymentId": "a1b2c3", "stageName": "dev", "description": "Development stage", "cacheClusterEnabled": false, "cacheClusterStatus": "NOT_AVAILABLE", "methodSettings": {}, "variables": { "key": "value", "otherKey": "otherValue" }, "tracingEnabled": false, "createdDate": "2022-07-18T10:11:18-07:00", "lastUpdatedDate": "2022-07-18T10:11:18-07:00" }For more information, see Set up a stage for a REST API in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateStage
in AWS CLI Command Reference.
-
The following code example shows how to use create-usage-plan-key.
- AWS CLI
-
To associate an existing API key with a Usage Plan
The following
create-usage-plan-keyexample associates an existing API key with a usage plan.aws apigateway create-usage-plan-key \ --usage-plan-ida1b2c3\ --key-type"API_KEY"\ --key-id4vq3yryqm5Output:
{ "id": "4vq3yryqm5", "type": "API_KEY", "value": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0", "name": "My API Key" }For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateUsagePlanKey
in AWS CLI Command Reference.
-
The following code example shows how to use create-usage-plan.
- AWS CLI
-
To create a usage plan with throttle and quota limits that resets at the beginning of the month
The following
create-usage-planexample creates a usage plan with throttle and quota limits that resets at the beginning of the month.aws apigateway create-usage-plan \ --name"New Usage Plan"\ --description"A new usage plan"\ --throttleburstLimit=10,rateLimit=5\ --quotalimit=500,offset=0,period=MONTHOutput:
{ "id": "a1b2c3", "name": "New Usage Plan", "description": "A new usage plan", "apiStages": [], "throttle": { "burstLimit": 10, "rateLimit": 5.0 }, "quota": { "limit": 500, "offset": 0, "period": "MONTH" } }For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see CreateUsagePlan
in AWS CLI Command Reference.
-
The following code example shows how to use delete-api-key.
- AWS CLI
-
To delete an API key
The following
delete-api-keyexample deletes the specified API key.aws apigateway delete-api-key \ --api-key8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blkThis command produces no output.
For more information, see Set up API keys for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteApiKey
in AWS CLI Command Reference.
-
The following code example shows how to use delete-authorizer.
- AWS CLI
-
To delete a Custom Authorizer in an API
The following
delete-authorizerexample deletes a custom authorizer in an API.aws apigateway delete-authorizer \ --rest-api-id1234123412\ --authorizer-id7gkfboThis command produces no output.
For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteAuthorizer
in AWS CLI Command Reference.
-
The following code example shows how to use delete-base-path-mapping.
- AWS CLI
-
To delete a base path mapping for a custom domain name
The following
delete-base-path-mappingexample deletes a base path mapping for a custom domain name.aws apigateway delete-base-path-mapping \ --domain-name 'api.domain.tld' \ --base-path 'dev'This command produces no output.
For more information, see Use API mappings to connect API stages to a custom domain name for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteBasePathMapping
in AWS CLI Command Reference.
-
The following code example shows how to use delete-client-certificate.
- AWS CLI
-
To delete a client certificate
The following
delete-client-certificateexample deletes the specified client certificate.aws apigateway delete-client-certificate \ --client-certificate-ida1b2c3This command produces no output.
For more information, see Use an API Gateway-generated certificate for backend authentication in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteClientCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use delete-deployment.
- AWS CLI
-
To delete a deployment in an API
The following
delete-deploymentexample deletes a deployment in an API.aws apigateway delete-deployment \ --rest-api-id1234123412\ --deployment-ida1b2c3This command produces no output.
For more information, see Deploy REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteDeployment
in AWS CLI Command Reference.
-
The following code example shows how to use delete-domain-name-access-association.
- AWS CLI
-
To delete a domain name access association
The following
delete-domain-name-access-associationexample deletes a domain name access association between a private custom domain name and VPC endpoint.aws apigateway delete-domain-name-access-association \ --domain-name-access-association-arnarn:aws:apigateway:us-west-2:123456789012:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efgThis command produces no output.
For more information, see Custom domain names for private APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteDomainNameAccessAssociation
in AWS CLI Command Reference.
-
The following code example shows how to use delete-domain-name.
- AWS CLI
-
To delete a custom domain name
The following
delete-domain-nameexample deletes a custom domain name.aws apigateway delete-domain-name \ --domain-name 'api.domain.tld'This command produces no output.
For more information, see Custom domain name for public REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteDomainName
in AWS CLI Command Reference.
-
The following code example shows how to use delete-integration-response.
- AWS CLI
-
To delete an integration response for a given resource, method, and status code in an API
The following
delete-integration-responseexample deletes an integration response for a given resource, method, and status code in an API.aws apigateway delete-integration-response \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --status-code200This command produces no output.
For more information, see Set up an integration response in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteIntegrationResponse
in AWS CLI Command Reference.
-
The following code example shows how to use delete-integration.
- AWS CLI
-
To delete an integration for a given resource and method in an API
The following
delete-integrationexample deletes an integration for a given resource and method in an API.aws apigateway delete-integration \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGETThis command produces no output.
For more information, see Integrations for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteIntegration
in AWS CLI Command Reference.
-
The following code example shows how to use delete-method-response.
- AWS CLI
-
To delete a method response for the given resource, method, and status code in an API
The following
delete-method-responseexample deletes a method response for the given resource, method, and status code in an API.aws apigateway delete-method-response \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --status-code200This command produces no output.
For more information, see Set up a method response in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteMethodResponse
in AWS CLI Command Reference.
-
The following code example shows how to use delete-method.
- AWS CLI
-
To delete a method for the given resource in an API
The following
delete-methodexample deletes a method for the given resource in an API.aws apigateway delete-method \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGETThis command produces no output.
For more information, see Methods for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteMethod
in AWS CLI Command Reference.
-
The following code example shows how to use delete-model.
- AWS CLI
-
To delete a model in the given API
The following
delete-modelexample deletes a model in the given API.aws apigateway delete-model \ --rest-api-id1234123412\ --model-name 'customModel'This command produces no output.
For more information, see Data models for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteModel
in AWS CLI Command Reference.
-
The following code example shows how to use delete-resource.
- AWS CLI
-
To delete a resource in an API
The following
delete-resourceexample deletes a resource in an API.aws apigateway delete-resource \ --rest-api-id1234123412\ --resource-ida1b2c3This command produces no output.
For more information, see Develop REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteResource
in AWS CLI Command Reference.
-
The following code example shows how to use delete-rest-api.
- AWS CLI
-
To delete an API
The following
delete-rest-apiexample deletes the specified API.aws apigateway delete-rest-api \ --rest-api-id1234123412This command produces no output.
For more information, see Develop REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteRestApi
in AWS CLI Command Reference.
-
The following code example shows how to use delete-stage.
- AWS CLI
-
To delete a stage in an API
The following
delete-stageexample deletes a stage in an API.aws apigateway delete-stage \ --rest-api-id1234123412\ --stage-name 'dev'This command produces no output.
For more information, see Set up a stage for a REST API in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteStage
in AWS CLI Command Reference.
-
The following code example shows how to use delete-usage-plan-key.
- AWS CLI
-
To remove an API key from a Usage Plan
The following
delete-usage-plan-keyexample removes an API key from a usage plan.aws apigateway delete-usage-plan-key \ --usage-plan-ida1b2c3\ --key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2SipnuThis command produces no output.
For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteUsagePlanKey
in AWS CLI Command Reference.
-
The following code example shows how to use delete-usage-plan.
- AWS CLI
-
To delete a Usage Plan
The following
delete-usage-planexample deletes the specified usage plan.aws apigateway delete-usage-plan \ --usage-plan-ida1b2c3This command produces no output.
For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see DeleteUsagePlan
in AWS CLI Command Reference.
-
The following code example shows how to use flush-stage-authorizers-cache.
- AWS CLI
-
To flush all authorizer cache entries on a stage
The following
flush-stage-authorizers-cacheexample flushes all authorizer cache entries on a stage.aws apigateway flush-stage-authorizers-cache \ --rest-api-id1234123412\ --stage-namedevThis command produces no output.
For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
-
For API details, see FlushStageAuthorizersCache
in AWS CLI Command Reference.
-
The following code example shows how to use flush-stage-cache.
- AWS CLI
-
To flush the cache for an API's stage
The following
flush-stage-cacheexample flushes the cache of a stage.aws apigateway flush-stage-cache \ --rest-api-id1234123412\ --stage-namedevThis command produces no output.
For more information, see Cache settings for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see FlushStageCache
in AWS CLI Command Reference.
-
The following code example shows how to use generate-client-certificate.
- AWS CLI
-
To create a Client-Side SSL Certificate
The following
generate-client-certificateexample creates a client-side SSL certificate.aws apigateway generate-client-certificate \ --description 'My First Client Certificate'Output:
{ "clientCertificateId": "a1b2c3", "description": "My First Client Certificate", "pemEncodedCertificate": "-----BEGIN CERTIFICATE-----\nMIIC6TCCAdGgAwIBAgIJAKbyiCf2f5J2MA0GCSqGSIb3DQEBCwUAMDQxCzAJBgNVEXAMPLE\n-----END CERTIFICATE-----\n", "createdDate": "2016-02-23T23:39:00+00:00", "expirationDate": "2017-02-23T23:39:00+00:00", "tags": {} }For more information, see Use an API Gateway-generated certificate for backend authentication in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GenerateClientCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use get-account.
- AWS CLI
-
To get API Gateway account settings
The following
get-accountexample gets the API Gateway account settings.aws apigateway get-accountOutput:
{ "cloudwatchRoleArn": "arn:aws:iam::123456789012:role/APIGatewayToCloudWatchLogsRole", "throttleSettings": { "rateLimit": 500.0, "burstLimit": 1000 } }For more information, see Set up CloudWatch logging for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetAccount
in AWS CLI Command Reference.
-
The following code example shows how to use get-api-key.
- AWS CLI
-
To get the information about a specific API key
The following
get-api-keyexample gets information about a specific API key.aws apigateway get-api-key \ --api-key8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blkOutput:
{ "description": "My first key", "enabled": true, "stageKeys": [ "a1b2c3d4e5/dev", "e5d4c3b2a1/dev" ], "lastUpdatedDate": 1456184515, "createdDate": 1456184452, "id": "8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk", "name": "My key" }For more information, see Set up API keys for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetApiKey
in AWS CLI Command Reference.
-
The following code example shows how to use get-api-keys.
- AWS CLI
-
To get the list of API keys
The following
get-api-keysexample gets the list of API keys.aws apigateway get-api-keysOutput:
{ "items": [ { "description": "My first key", "enabled": true, "stageKeys": [ "a1b2c3d4e5/dev", "e5d4c3b2a1/dev" ], "lastUpdatedDate": 1456184515, "createdDate": 1456184452, "id": "8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk", "name": "My key" } ] }For more information, see Set up API keys for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetApiKeys
in AWS CLI Command Reference.
-
The following code example shows how to use get-authorizer.
- AWS CLI
-
To get the API Gateway per-API Authorizer settings
The following
get-authorizerexample gets the settings of the specified per-API authorizer.aws apigateway get-authorizer \ --rest-api-id1234123412\ --authorizer-idgfi4n3Output:
{ "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:123456789012:function:authorizer_function/invocations", "id": "gfi4n3" }For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
-
For API details, see GetAuthorizer
in AWS CLI Command Reference.
-
The following code example shows how to use get-authorizers.
- AWS CLI
-
To get the list of authorizers for a REST API
The following
get-authorizersexample gets the list of authorizers for a REST API.aws apigateway get-authorizers \ --rest-api-id1234123412Output:
{ "items": [ { "name": "MyAuthorizer", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:function:My_Authorizer_Function/invocations", "authorizerResultTtlInSeconds": 300, "identitySource": "method.request.header.Authorization", "type": "TOKEN", "id": "gfi4n3" } ] }For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
-
For API details, see GetAuthorizers
in AWS CLI Command Reference.
-
The following code example shows how to use get-base-path-mapping.
- AWS CLI
-
To get the base path mapping for a custom domain name
The following
get-base-path-mappingexample gets the base path mapping for a custom domain name.aws apigateway get-base-path-mapping \ --domain-namesubdomain.domain.tld\ --base-pathv1Output:
{ "basePath": "v1", "restApiId": "1234w4321e", "stage": "api" }For more information, see Use API mappings to connect API stages to a custom domain name for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see GetBasePathMapping
in AWS CLI Command Reference.
-
The following code example shows how to use get-base-path-mappings.
- AWS CLI
-
To get the base path mappings for a custom domain name
The following
get-base-path-mappingsexample gets the base path mappings for the custom domain namesubdomain.domain.tld.aws apigateway get-base-path-mappings \ --domain-namesubdomain.domain.tldOutput:
{ "items": [ { "basePath": "(none)", "restApiId": "1234w4321e", "stage": "dev" }, { "basePath": "v1", "restApiId": "1234w4321e", "stage": "api" } ] }For more information, see Use API mappings to connect API stages to a custom domain name for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see GetBasePathMappings
in AWS CLI Command Reference.
-
The following code example shows how to use get-client-certificate.
- AWS CLI
-
To get a client certificate
The following
get-client-certificateexample gets the client certificate with the IDa1b2c3.aws apigateway get-client-certificate \ --client-certificate-ida1b2c3Output:
{ "clientCertificateId": "a1b2c3", "description": "My First Client Certificate", "pemEncodedCertificate": "-----BEGIN CERTIFICATE-----\nMIIC6TCCAdGgAwIBAgIJAKbyiCf2f5J2MA0GCSqGSIb3DQEBCwUAMDQxCzAJBgNVEXAMPLE\n-----END CERTIFICATE-----\n", "createdDate": "2016-02-23T23:39:00+00:00", "expirationDate": "2017-02-23T23:39:00+00:00", "tags": {} }For more information, see Use an API Gateway-generated certificate for backend authentication in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetClientCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use get-client-certificates.
- AWS CLI
-
To get a list of client certificates
The following
get-client-certificatesexample gets a list of client certificates.aws apigateway get-client-certificatesOutput:
{ "items": [ { "pemEncodedCertificate": "-----BEGIN CERTIFICATE----- <certificate content> -----END CERTIFICATE-----", "clientCertificateId": "a1b2c3", "expirationDate": 1483556561, "description": "My Client Certificate", "createdDate": 1452020561 } ] }For more information, see Use an API Gateway-generated certificate for backend authentication in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetClientCertificates
in AWS CLI Command Reference.
-
The following code example shows how to use get-deployment.
- AWS CLI
-
To get information about a deployment
The following
get-deploymentexample gets information about the specified deployment of a REST API.aws apigateway get-deployment \ --rest-api-id1234123412\ --deployment-idztt4m2Output:
{ "description": "myDeployment", "id": "ztt4m2", "createdDate": 1455218022 }For more information, see Create a deployment for a REST API in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetDeployment
in AWS CLI Command Reference.
-
The following code example shows how to use get-deployments.
- AWS CLI
-
To get a list of deployments for a REST API
The following
get-deploymentsexample gets a list of deployments for the specified REST API.aws apigateway get-deployments \ --rest-api-id1234123412Output:
{ "items": [ { "createdDate": 1453797217, "id": "0a2b4c", "description": "Deployed my API for the first time" } ] }For more information, see Create a deployment for a REST API in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetDeployments
in AWS CLI Command Reference.
-
The following code example shows how to use get-domain-name-access-associations.
- AWS CLI
-
Example 1: To list all domain name access associations
The following
get-domain-name-access-associationsexample lists all domain name access associations.aws apigateway get-domain-name-access-associationsOutput:
{ "items": [ { "domainNameAccessAssociationArn": "arn:aws:apigateway:us-west-2:123456789222:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg", "accessAssociationSource": "vpce-abcd1234efg", "accessAssociationSourceType": "VPCE", "domainNameArn": "arn:aws:apigateway:us-west-2:123456789111:/domainnames/private.example.com+abcd1234" } ] }For more information, see Custom domain names for private APIs in API Gateway in the Amazon API Gateway Developer Guide.
Example 2: To list all domain name access associations owned by this AWS account
The following
get-domain-name-access-associationsexample lists all the domain name access associations owned by the current AWS account.aws apigateway get-domain-name-access-associations \ --resource-ownerSELFOutput:
{ "items": [ { "domainNameAccessAssociationArn": "arn:aws:apigateway:us-west-2:123456789222:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg", "accessAssociationSource": "vpce-abcd1234efg", "accessAssociationSourceType": "VPCE", "domainNameArn": "arn:aws:apigateway:us-west-2:123456789111:/domainnames/private.example.com+abcd1234" } ] }For more information, see Custom domain names for private APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetDomainNameAccessAssociations
in AWS CLI Command Reference.
-
The following code example shows how to use get-domain-name.
- AWS CLI
-
Example 1: To get information about a public custom domain name
The following
get-domain-nameexample gets information about a public custom domain name.aws apigateway get-domain-name \ --domain-nameapi.domain.tldOutput:
{ "domainName": "api.domain.tld", "distributionDomainName": "d1a2f3a4c5o6d.cloudfront.net", "certificateName": "uploadedCertificate", "certificateUploadDate": 1462565487 }For more information, see Custom domain name for public REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
Example 2: To get information about a private custom domain name
The following
get-domain-nameexample gets information about a private custom domain name.aws apigateway get-domain-name \ --domain-nameapi.private.domain.tld\ --domain-name-idabcd1234Output:
{ "domainName": "my.private.domain.tld", "domainNameId": "abcd1234", "domainNameArn": "arn:aws:apigateway:us-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234", "certificateArn": "arn:aws:acm:us-west-2:123456789012: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-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234\"},{\"Effect\":\"Deny\",\"Principal\":\"*\",\"Action\":\"execute-api:Invoke\",\"Resource\":\"arn:aws:execute-api:us-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234\",\"Condition\":{\"StringNotEquals\":{\"aws:SourceVpc\":\"vpc-1a2b3c4d\"}}}]}" }For more information, see Custom domain name for public REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetDomainName
in AWS CLI Command Reference.
-
The following code example shows how to use get-domain-names.
- AWS CLI
-
Example 1: To get a list of custom domain names
The following
get-domain-namesexample gets a list of domain names.aws apigateway get-domain-namesOutput:
{ "items": [ { "distributionDomainName": "d9511k3l09bkd.cloudfront.net", "certificateUploadDate": 1452812505, "certificateName": "my_custom_domain-certificate", "domainName": "subdomain.domain.tld" } ] }For more information, see Custom domain names for private APIs in API Gateway in the Amazon API Gateway Developer Guide.
Example 2: To get a list of custom domain names owned by this AWS account
The following
get-domain-namesexample gets a list of domain names owned by this AWS account.aws apigateway get-domain-names \ --resource-ownerSELFOutput:
{ "items": [ { "domainName": "my.domain.tld", "domainNameArn": "arn:aws:apigateway:us-west-2::/domainnames/my.private.domain.tld", "certificateUploadDate": "2024-08-15T17:02:55-07:00", "regionalDomainName": "d-abcd1234.execute-api.us-west-2.amazonaws.com", "regionalHostedZoneId": "Z1UJRXOUMOOFQ8", "regionalCertificateArn": "arn:aws:acm:us-west-2:123456789012: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-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234", "certificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/fb1b9770-a305-495d-aefb-27e5e101ff3", "certificateUploadDate": "2024-11-26T11:44:40-08:00", "endpointConfiguration": { "types": [ "PRIVATE" ] }, "domainNameStatus": "AVAILABLE", "securityPolicy": "TLS_1_2" } ] }For more information, see Custom domain names for private APIs in API Gateway in the Amazon API Gateway Developer Guide.
Example 3: To get a list of custom domain names owned by other AWS accounts that you can create a domain name access association with.
The following
get-domain-namesexample gets a list of domain names owned by other AWS accounts that you have access to create a domain name access association with.aws apigateway get-domain-names \ --resource-ownerOTHER_ACCOUNTSOutput:
{ "items": [ { "domainName": "my.private.domain.tld", "domainNameId": "abcd1234", "domainNameArn": "arn:aws:apigateway:us-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234" } ] }For more information, see Custom domain names for private APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetDomainNames
in AWS CLI Command Reference.
-
The following code example shows how to use get-export.
- AWS CLI
-
Example 1: To get the JSON Swagger template for a stage
The following
get-exportexample gets the JSON Swagger template for thedevstage and saves it to a file.aws apigateway get-export/path/to/filename.json\ --rest-api-ida1b2c3d4e5\ --stage-namedev\ --export-typeswaggerOutput:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"swagger_2016-02-22_23-52Z.json\"" }For more information, see Export a REST API from API Gateway in the Amazon API Gateway Developer Guide.
Example 2: To get the JSON Swagger template + API Gateway Extensions for a stage
The following
get-exportexample gets the JSON Swagger template with API Gateway Extensions for thedevstage and saves it to a file.aws apigateway get-export/path/to/filename.json\ --parameters extensions='integrations' \ --rest-api-ida1b2c3d4e5\ --stage-namedev\ --export-typeswaggerOutput:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"swagger_2016-02-22_23-52Z.json\"" }For more information, see Export a REST API from API Gateway in the Amazon API Gateway Developer Guide.
Example 3: To get the JSON Swagger template + Postman Extensions for a stage
The following
get-exportexample gets the JSON Swagger template with Postman Extensions for thedevstage and saves it to a file.aws apigateway get-export/path/to/filename.json\ --parameters extensions='postman' \ --rest-api-ida1b2c3d4e5\ --stage-namedev\ --export-typeswaggerOutput:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"swagger_2016-02-22_23-52Z.json\"" }For more information, see Export a REST API from API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetExport
in AWS CLI Command Reference.
-
The following code example shows how to use get-integration-response.
- AWS CLI
-
To get the integration response configuration for a HTTP method defined under a REST API's resource
The following
get-integration-responseexample gets the integration response configuration for the200status code of theGETmethod defined under a REST API's resource.aws apigateway get-integration-response \ --rest-api-id1234123412\ --resource-idy9h6rt\ --http-methodGET\ --status-code200Output:
{ "statusCode": "200", "responseTemplates": { "application/json": null } }For more information, see Set up an integration response in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetIntegrationResponse
in AWS CLI Command Reference.
-
The following code example shows how to use get-integration.
- AWS CLI
-
To get the integration configuration for a HTTP method defined under a REST API's resource
The following
get-integrationexample gets the integration configuration for theGETmethod defined under a REST API's resource.aws apigateway get-integration \ --rest-api-id1234123412\ --resource-idy9h6rt\ --http-methodGETOutput:
{ "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:123456789012:function:My_Function/invocations", "cacheNamespace": "y9h6rt" }For more information, see Integrations for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetIntegration
in AWS CLI Command Reference.
-
The following code example shows how to use get-method-response.
- AWS CLI
-
To get the method response resource configuration for a HTTP method defined under a REST API's resource
The following
get-method-responseexample gets the method response resource configuration for the200status code of theGETmethod defined under a REST API's resource.aws apigateway get-method-response \ --rest-api-id1234123412\ --resource-idy9h6rt\ --http-methodGET\ --status-code200Output:
{ "responseModels": { "application/json": "Empty" }, "statusCode": "200" }For more information, see Set up a method response in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetMethodResponse
in AWS CLI Command Reference.
-
The following code example shows how to use get-method.
- AWS CLI
-
To get the method resource configuration for a HTTP method defined under a REST API's resource
The following
get-methodexample gets the method resource configuration for theGETmethod defined under a REST API's resource.aws apigateway get-method \ --rest-api-id1234123412\ --resource-idy9h6rt\ --http-methodGETOutput:
{ "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:123456789012:function:My_Function/invocations", "httpMethod": "POST", "cacheNamespace": "y9h6rt", "type": "AWS" }, "requestParameters": {}, "methodResponses": { "200": { "responseModels": { "application/json": "Empty" }, "statusCode": "200" } }, "authorizationType": "NONE" }For more information, see Methods for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetMethod
in AWS CLI Command Reference.
-
The following code example shows how to use get-model-template.
- AWS CLI
-
To get the mapping template for a model defined under a REST API
The following
get-model-templateexample gets the mapping template for theEmptymodel defined under a REST API.aws apigateway get-model-template \ --rest-api-id1234123412\ --model-nameEmptyOutput:
{ "value": "#set($inputRoot = $input.path('$'))\n{ }" }For more information, see Mapping template transformations for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetModelTemplate
in AWS CLI Command Reference.
-
The following code example shows how to use get-model.
- AWS CLI
-
To get the configuration for a model defined under a REST API
The following
get-modelexample gets the configuration for theEmptymodel defined under a REST API.aws apigateway get-model \ --rest-api-id1234123412\ --model-nameEmptyOutput:
{ "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}" }For more information, see Data models for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see GetModel
in AWS CLI Command Reference.
-
The following code example shows how to use get-models.
- AWS CLI
-
To get a list of models for a REST API
The following
get-modelsexample gets a list of models for the specified REST API.aws apigateway get-models \ --rest-api-id1234123412Output:
{ "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" } ] }For more information, see Data models for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see GetModels
in AWS CLI Command Reference.
-
The following code example shows how to use get-resource.
- AWS CLI
-
To get information about a resource
The following
get-resourceexample gets information about the specified resource.aws apigateway get-resource \ --rest-api-id1234123412\ --resource-idzwo0y3Output:
{ "path": "/path", "pathPart": "path", "id": "zwo0y3", "parentId": "uyokt6ij2g" }For more information, see Develop REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetResource
in AWS CLI Command Reference.
-
The following code example shows how to use get-resources.
- AWS CLI
-
To get a list of resources for a REST API
The following
get-resourcesexample gets a list of resources for the specified REST API.aws apigateway get-resources \ --rest-api-id1234123412Output:
{ "items": [ { "path": "/resource/subresource", "resourceMethods": { "POST": {} }, "id": "024ace", "pathPart": "subresource", "parentId": "ai5b02" } ] }For more information, see Develop REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetResources
in AWS CLI Command Reference.
-
The following code example shows how to use get-rest-api.
- AWS CLI
-
To get information about an API
The following
get-rest-apiexample gets information about the specified REST API.aws apigateway get-rest-api \ --rest-api-id1234123412Output:
{ "name": "myAPI", "id": "o1y243m4f5", "createdDate": 1453416433 }For more information, see API Gateway REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see GetRestApi
in AWS CLI Command Reference.
-
The following code example shows how to use get-rest-apis.
- AWS CLI
-
To get a list of REST APIs
The following
get-rest-apisexample gets a list of REST APIs.aws apigateway get-rest-apisOutput:
{ "items": [ { "createdDate": 1438884790, "id": "12s44z21rb", "name": "My First API" } ] }For more information, see API Gateway REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see GetRestApis
in AWS CLI Command Reference.
-
The following code example shows how to use get-sdk.
- AWS CLI
-
Example 1: To get the Android SDK for a REST API stage
The following
get-sdkexample gets the Android SDK for thedevstage of a REST API and saves it to a file.aws apigateway get-sdk/path/to/android_sdk.zip\ --rest-api-id1234123412\ --stage-namedev\ --sdk-typeandroid\ --parameters groupId='com.mycompany',invokerPackage='com.mycompany.clientsdk',artifactId='Mycompany-client',artifactVersion='1.0.0'Output:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"android_2016-02-22_23-52Z.zip\"" }For more information, see Use an Android SDK generated by API Gateway for a REST API in the Amazon API Gateway Developer Guide.
Example 2: To get the IOS SDK for a REST API stage
The following
get-sdkexample gets the iOS SDK for thedevstage of a REST API and saves it to a file.aws apigateway get-sdk/path/to/iOS_sdk.zip\ --rest-api-id1234123412\ --stage-namedev\ --sdk-typeobjectivec\ --parameters classPrefix='myprefix'Output:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"objectivec_2016-02-22_23-52Z.zip\"" }For more information, see Use iOS SDK generated by API Gateway for a REST API in Objective-C or Swift in the Amazon API Gateway Developer Guide.
Example 3: To get the Javascript SDK for a REST API stage
The following
get-sdkexample gets the JavaScript SDK for thedevstage of a REST API and saves it to a file.aws apigateway get-sdk/path/to/javascript_sdk.zip\ --rest-api-id1234123412\ --stage-namedev\ --sdk-typejavascriptOutput:
{ "contentType": "application/octet-stream", "contentDisposition": "attachment; filename=\"javascript_2016-02-22_23-52Z.zip\"" }For more information, see Use a JavaScript SDK generated by API Gateway for a REST API in the Amazon API Gateway Developer Guide.
-
For API details, see GetSdk
in AWS CLI Command Reference.
-
The following code example shows how to use get-stage.
- AWS CLI
-
To get information about an API's stage
The following
get-stageexample gets information about thedevstage of a REST API.aws apigateway get-stage \ --rest-api-id1234123412\ --stage-namedevOutput:
{ "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 } } }For more information, see Set up a stage for a REST API in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetStage
in AWS CLI Command Reference.
-
The following code example shows how to use get-stages.
- AWS CLI
-
To get the list of stages for a REST API
The following
get-stagesexample gets the list of stages for the specified REST API.aws apigateway get-stages \ --rest-api-id1234123412Output:
{ "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 } } } ] }For more information, see Set up a stage for a REST API in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetStages
in AWS CLI Command Reference.
-
The following code example shows how to use get-usage-plan-key.
- AWS CLI
-
To get the details of an API key associated with a Usage Plan
The following
get-usage-plan-keyexample gets the details of an API key associated with the specified usage plan.aws apigateway get-usage-plan-key \ --usage-plan-ida1b2c3\ --key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2SipnuOutput:
{ "id": "1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu", "type": "API_KEY", "name": "MyApiKey" }For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetUsagePlanKey
in AWS CLI Command Reference.
-
The following code example shows how to use get-usage-plan-keys.
- AWS CLI
-
To get the list of API keys associated with a Usage Plan
The following
get-usage-plan-keysexample gets the list of API keys associated with the specified usage plan.aws apigateway get-usage-plan-keys \ --usage-plan-ida1b2c3Output:
{ "items": [ { "id": "1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu", "type": "API_KEY", "name": "MyApiKey" } ] }For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetUsagePlanKeys
in AWS CLI Command Reference.
-
The following code example shows how to use get-usage-plan.
- AWS CLI
-
To get the details of a Usage Plan
The following
get-usage-planexample gets the details of the specified usage plan.aws apigateway get-usage-plan \ --usage-plan-ida1b2c3Output:
{ "id": "a1b2c3", "name": "MyUsagePlan", "description": "My usage plan", "apiStages": [ { "apiId": "1234123412", "stage": "dev" } ], "throttle": { "burstLimit": 100, "rateLimit": 50.0 }, "quota": { "limit": 5000, "offset": 0, "period": "MONTH" } }For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetUsagePlan
in AWS CLI Command Reference.
-
The following code example shows how to use get-usage-plans.
- AWS CLI
-
To get the details of all Usage Plans
The following
get-usage-plansexample gets the details of all usage plans.aws apigateway get-usage-plansOutput:
{ "items": [ { "id": "a1b2c3", "name": "My Usage Plan", "description": "A sample usage plan", "apiStages": [ { "apiId": "1234123412", "stage": "Prod" } ], "throttle": { "burstLimit": 10, "rateLimit": 5.0 }, "quota": { "limit": 500, "offset": 0, "period": "MONTH" }, "tags": {} } ] }For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetUsagePlans
in AWS CLI Command Reference.
-
The following code example shows how to use get-usage.
- AWS CLI
-
To get the usage details for a Usage Plan
The following
get-usageexample gets the usage details for the specified usage plan between 2016-08-16 and 2016-08-17.aws apigateway get-usage \ --usage-plan-ida1b2c3\ --start-date"2016-08-16"\ --end-date"2016-08-17"Output:
{ "usagePlanId": "a1b2c3", "startDate": "2016-08-16", "endDate": "2016-08-17", "items": { "a1b2c3d4e5f6g7h8i9j0": [ [ 13, 487 ], [ 7, 480 ] ] } }For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see GetUsage
in AWS CLI Command Reference.
-
The following code example shows how to use import-rest-api.
- AWS CLI
-
To import a Swagger template and create an API
The following
import-rest-apiexample imports a Swagger template and creates an API.aws apigateway import-rest-api \ --body 'fileb:///path/to/API_Swagger_template.json'Output:
{ "id": "a1b2c3d4e5", "name": "MyAPI", "description": "API imported from a Swagger template", "createdDate": "2016-02-23T23:39:00+00:00", "version": "1.0", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "EDGE" ] }, "disableExecuteApiEndpoint": false, "rootResourceId": "a1b2c3d4f5" }For more information, see Develop REST APIs using OpenAPI in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see ImportRestApi
in AWS CLI Command Reference.
-
The following code example shows how to use put-integration-response.
- AWS CLI
-
Example 1: To create an integration response as the default response with a mapping template defined
The following
put-integration-responseexample creates an integration response as the default response with a mapping template defined.aws apigateway put-integration-response \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --status-code200\ --selection-pattern "" \ --response-templates '{"application/json": "{\"json\": \"template\"}"}'Output:
{ "statusCode": "200", "selectionPattern": "", "responseTemplates": { "application/json": "{\"json\": \"template\"}" } }For more information, see Set up an integration response in API Gateway in the Amazon API Gateway Developer Guide.
Example 2: To create an integration response with a regex of 400 and a statically defined header value
The following
put-integration-responseexample creates an integration response with a regex of 400 and a statically defined header value.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'"'"'"}'Output:
{ "statusCode": "400", "selectionPattern": "400", "responseParameters": { "method.response.header.custom-header": "'custom-value'" } }For more information, see Set up an integration response in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see PutIntegrationResponse
in AWS CLI Command Reference.
-
The following code example shows how to use put-integration.
- AWS CLI
-
Example 1: To create a MOCK integration request
The following
put-integrationexample creates a MOCK integration request.aws apigateway put-integration \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --typeMOCK\ --request-templates '{ "application/json": "{\"statusCode\": 200}" }'Output:
{ "type": "MOCK", "requestTemplates": { "application/json": "{\"statusCode\": 200}" }, "passthroughBehavior": "WHEN_NO_MATCH", "timeoutInMillis": 29000, "cacheNamespace": "a1b2c3", "cacheKeyParameters": [] }For more information, see Mock integrations for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
Example 2: To create a HTTP integration request
The following
put-integrationexample creates an HTTP integration request.aws apigateway put-integration \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --typeHTTP\ --integration-http-methodGET\ --uri 'https://domain.tld/path'Output:
{ "type": "HTTP", "httpMethod": "GET", "uri": "https://domain.tld/path", "connectionType": "INTERNET", "passthroughBehavior": "WHEN_NO_MATCH", "timeoutInMillis": 29000, "cacheNamespace": "a1b2c3", "cacheKeyParameters": [] }For more information, see HTTP integrations for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
Example 3: To create an AWS integration request with a Lambda Function endpoint
The following
put-integrationexample creates an AWS integration request with a Lambda function endpoint.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:123456789012:function:function_name/invocations'Output:
{ "type": "AWS", "httpMethod": "POST", "uri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:function:function_name/invocations", "passthroughBehavior": "WHEN_NO_MATCH", "timeoutInMillis": 29000, "cacheNamespace": "a1b2c3", "cacheKeyParameters": [] }For more information, see Lambda integrations for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see PutIntegration
in AWS CLI Command Reference.
-
The following code example shows how to use put-method-response.
- AWS CLI
-
To create a method response under the specified status code with a custom method response header
The following
put-method-responseexample creates a method response under the specified status code with a custom method response header.aws apigateway put-method-response \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --status-code400\ --response-parameters"method.response.header.custom-header=false"Output:
{ "statusCode": "400", "responseParameters": { "method.response.header.custom-header": false } }For more information, see Set up a method response in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see PutMethodResponse
in AWS CLI Command Reference.
-
The following code example shows how to use put-method.
- AWS CLI
-
To create a method for a resource in an API with no authorization, no API key, and a custom method request header
The following
put-methodexample creates a method for a resource in an API with no authorization, no API key, and a custom method request header.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"Output:
{ "httpMethod": "PUT", "authorizationType": "NONE", "apiKeyRequired": false, "requestParameters": { "method.request.header.custom-header": false } }For more information, see Set up a method request in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see PutMethod
in AWS CLI Command Reference.
-
The following code example shows how to use put-rest-api.
- AWS CLI
-
Example 1: To overwrite an existing API using a Swagger template
The following
put-rest-apiexample overwrites an existing API using a Swagger template.aws apigateway put-rest-api \ --rest-api-id1234123412\ --modeoverwrite\ --body 'fileb:///path/to/API_Swagger_template.json'Output:
{ "id": "1234123412", "name": "MyAPI", "description": "API defined by a Swagger template", "createdDate": "2016-02-23T23:39:00+00:00", "version": "1.0", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "EDGE" ] }, "disableExecuteApiEndpoint": false, "rootResourceId": "a1b2c3d4f5" }For more information, see Import an OpenAPI file to update an existing API definition in the Amazon API Gateway Developer Guide.
Example 2: To merge a Swagger template into an existing API
The following
put-rest-apiexample merges a Swagger template into an existing API.aws apigateway put-rest-api \ --rest-api-id1234123412\ --modemerge\ --body 'fileb:///path/to/API_Swagger_template.json'Output:
{ "id": "1234123412", "name": "MyAPI", "description": "API defined by a Swagger template", "createdDate": "2016-02-23T23:39:00+00:00", "version": "1.0", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "EDGE" ] }, "disableExecuteApiEndpoint": false, "rootResourceId": "a1b2c3d4f5" }For more information, see Import an OpenAPI file to update an existing API definition in the Amazon API Gateway Developer Guide.
-
For API details, see PutRestApi
in AWS CLI Command Reference.
-
The following code example shows how to use reject-domain-name-access-association.
- AWS CLI
-
To reject a domain name access association
The following
reject-domain-name-access-associationexample rejects a domain name access association between a private custom domain name and VPC endpoint.aws apigateway reject-domain-name-access-association \ --domain-name-access-association-arnarn:aws:apigateway:us-west-2:123456789012:/domainnameaccessassociations/domainname/my.private.domain.tld/vpcesource/vpce-abcd1234efg\ --domain-name-arnarn:aws:apigateway:us-west-2:123456789012:/domainnames/my.private.domain.tld+abcd1234This command produces no output.
For more information, see Custom domain names for private APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see RejectDomainNameAccessAssociation
in AWS CLI Command Reference.
-
The following code example shows how to use test-invoke-authorizer.
- AWS CLI
-
To test invoke a request to a Custom Authorizer including the required header and value
The following
test-invoke-authorizerexample tests a request to a Custom Authorizer including the required header and value.aws apigateway test-invoke-authorizer \ --rest-api-id1234123412\ --authorizer-id5yid1t\ --headers Authorization='Value'Output:
{ "clientStatus": 0, "log": "Execution log for request a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\nWed Feb 24 00:51:47 UTC 2016 : Starting authorizer: 5yid1t for request: a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\nWed Feb 24 00:51:47 UTC 2016 : Successfully completed authorizer execution\n", "latency": 250, "principalId": "user", "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"execute-api:Invoke\",\"Effect\":\"Allow\",\"Resource\":\"arn:aws:execute-api:us-west-2:123456789012:1234123412/*/GET/\"}]}", "authorization": { "Authorization": [ "Value" ] }, "claims": {} }For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
-
For API details, see TestInvokeAuthorizer
in AWS CLI Command Reference.
-
The following code example shows how to use test-invoke-method.
- AWS CLI
-
Example 1: To test invoke the root resource in an API by making a GET request
The following
test-invoke-methodexample tests an invocation of the root resource in an API by making a GET request.aws apigateway test-invoke-method \ --rest-api-id1234123412\ --resource-idavl5sg8fw8\ --http-methodGET\ --path-with-query-string '/'Output:
{ "status": 200, "body": "{\"message\": \"Welcome to the root resource\"}", "headers": { "Content-Type": "application/json" }, "multiValueHeaders": { "Content-Type": [ "application/json" ] }, "log": "Execution log for request a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\nWed Feb 24 00:51:47 UTC 2016 : Starting execution for request: a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\nWed Feb 24 00:51:47 UTC 2016 : HTTP Method: GET, Resource Path: /\nWed Feb 24 00:51:47 UTC 2016 : Method completed with status: 200\n", "latency": 45 }For more information, see Use the API Gateway console to test a REST API method in the Amazon API Gateway Developer Guide.
Example 2: To test invoke a sub-resource in an API by making a GET request with a path parameter value specified
The following
test-invoke-methodexample tests an invocation of a sub-resource in an API by making a GET request with a path parameter value specified.aws apigateway test-invoke-method \ --rest-api-id1234123412\ --resource-id3gapai\ --http-methodGET\ --path-with-query-string '/pets/1'Output:
{ "status": 200, "body": "{\"id\": 1, \"type\": \"dog\", \"price\": 249.99}", "headers": { "Content-Type": "application/json" }, "multiValueHeaders": { "Content-Type": [ "application/json" ] }, "log": "Execution log for request a1b2c3d4-5678-90ab-cdef-EXAMPLE22222\nWed Feb 24 00:51:47 UTC 2016 : Starting execution for request: a1b2c3d4-5678-90ab-cdef-EXAMPLE22222\nWed Feb 24 00:51:47 UTC 2016 : HTTP Method: GET, Resource Path: /pets/1\nWed Feb 24 00:51:47 UTC 2016 : Method completed with status: 200\n", "latency": 52 }For more information, see Use the API Gateway console to test a REST API method in the Amazon API Gateway Developer Guide.
-
For API details, see TestInvokeMethod
in AWS CLI Command Reference.
-
The following code example shows how to use update-account.
- AWS CLI
-
To change the IAM Role ARN for logging to CloudWatch Logs
The following
update-accountexample changes the IAM Role ARN for logging to CloudWatch Logs.aws apigateway update-account \ --patch-operations op='replace',path='/cloudwatchRoleArn',value='arn:aws:iam::123456789012:role/APIGatewayToCloudWatchLogs'Output:
{ "cloudwatchRoleArn": "arn:aws:iam::123456789012:role/APIGatewayToCloudWatchLogs", "throttleSettings": { "rateLimit": 1000.0, "burstLimit": 2000 } }For more information, see Set up CloudWatch logging for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateAccount
in AWS CLI Command Reference.
-
The following code example shows how to use update-api-key.
- AWS CLI
-
Example 1: To change the name for an API Key
The following
update-api-keyexample changes the name for an API Key.aws apigateway update-api-key \ --api-keysNvjQDMReA1eEQPNAW8r37XsU2rDD7fc7m2SiMnu\ --patch-operations op='replace',path='/name',value='newName'Output:
{ "description": "currentDescription", "enabled": true, "stageKeys": [ "41t2j324r5/dev" ], "lastUpdatedDate": 1470086052, "createdDate": 1445460347, "id": "sNvjQDMReA1vEQPNzW8r3dXsU2rrD7fcjm2SiMnu", "name": "newName" }For more information, see Set up API keys for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
Example 2: To disable the API Key
The following
update-api-keyexample disables the API Key.aws apigateway update-api-key \ --api-keysNvjQDMReA1eEQPNAW8r37XsU2rDD7fc7m2SiMnu\ --patch-operations op='replace',path='/enabled',value='false'Output:
{ "description": "currentDescription", "enabled": false, "stageKeys": [ "41t2j324r5/dev" ], "lastUpdatedDate": 1470086052, "createdDate": 1445460347, "id": "sNvjQDMReA1vEQPNzW8r3dXsU2rrD7fcjm2SiMnu", "name": "newName" }For more information, see Set up API keys for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateApiKey
in AWS CLI Command Reference.
-
The following code example shows how to use update-authorizer.
- AWS CLI
-
Example 1: To change the name of the Custom Authorizer
The following
update-authorizerexample changes the name of the Custom Authorizer.aws apigateway update-authorizer \ --rest-api-id1234123412\ --authorizer-idgfi4n3\ --patch-operations op='replace',path='/name',value='testAuthorizer'Output:
{ "authType": "custom", "name": "testAuthorizer", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:function:customAuthorizer/invocations", "authorizerResultTtlInSeconds": 300, "identitySource": "method.request.header.Authorization", "type": "TOKEN", "id": "gfi4n3" }For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
Example 2: To change the Lambda Function that is invoked by the Custom Authorizer
The following
update-authorizerexample changes the Lambda Function that is invoked by the Custom Authorizer.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:123456789012:function:newAuthorizer/invocations'Output:
{ "authType": "custom", "name": "testAuthorizer", "authorizerUri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:function:newAuthorizer/invocations", "authorizerResultTtlInSeconds": 300, "identitySource": "method.request.header.Authorization", "type": "TOKEN", "id": "gfi4n3" }For more information, see Use API Gateway Lambda authorizers in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateAuthorizer
in AWS CLI Command Reference.
-
The following code example shows how to use update-base-path-mapping.
- AWS CLI
-
To change the base path for a custom domain name
The following
update-base-path-mappingexample changes the base path for a custom domain name.aws apigateway update-base-path-mapping \ --domain-nameapi.domain.tld\ --base-pathprod\ --patch-operations op='replace',path='/basePath',value='v1'Output:
{ "basePath": "v1", "restApiId": "1234123412", "stage": "api" }For more information, see Use API mappings to connect API stages to a custom domain name for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateBasePathMapping
in AWS CLI Command Reference.
-
The following code example shows how to use update-client-certificate.
- AWS CLI
-
To update the description of a client certificate
The following
update-client-certificateexample updates the description of a client certificate.aws apigateway update-client-certificate \ --client-certificate-ida1b2c3\ --patch-operations op='replace',path='/description',value='My new description'Output:
{ "clientCertificateId": "a1b2c3", "description": "My new description", "pemEncodedCertificate": "-----BEGIN CERTIFICATE-----\nMIIC6TCCAdGgAwIBAgIJAKbyiCf2f5J2MA0GCSqGSIb3DQEBCwUAMDQxCzAJBgNVEXAMPLE\n-----END CERTIFICATE-----\n", "createdDate": "2016-02-23T23:39:00+00:00", "expirationDate": "2017-02-23T23:39:00+00:00", "tags": {} }For more information, see Use an API Gateway-generated certificate for backend authentication in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateClientCertificate
in AWS CLI Command Reference.
-
The following code example shows how to use update-deployment.
- AWS CLI
-
To change the description of a deployment
The following
update-deploymentexample changes the description of a deployment.aws apigateway update-deployment \ --rest-api-id1234123412\ --deployment-idztt4m2\ --patch-operations op='replace',path='/description',value='newDescription'Output:
{ "description": "newDescription", "id": "ztt4m2", "createdDate": 1455218022 }For more information, see Deploy REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateDeployment
in AWS CLI Command Reference.
-
The following code example shows how to use update-domain-name.
- AWS CLI
-
To change the certificate name for a custom domain name
The following
update-domain-nameexample changes the certificate name for a custom domain.aws apigateway update-domain-name \ --domain-nameapi.domain.tld\ --patch-operations op='replace',path='/certificateArn',value='arn:aws:acm:us-west-2:123456789012:certificate/CERTEXAMPLE123EXAMPLE'Output:
{ "domainName": "api.domain.tld", "distributionDomainName": "d123456789012.cloudfront.net", "certificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/CERTEXAMPLE123EXAMPLE", "certificateUploadDate": 1462565487 }For more information, see Custom domain name for public REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateDomainName
in AWS CLI Command Reference.
-
The following code example shows how to use update-integration-response.
- AWS CLI
-
Example 1: To change an integration response header to have a static mapping of '*'
The following
update-integration-responseexample changes an integration response header to have a static mapping of '*'.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='"'"'*'"'"'Output:
{ "statusCode": "200", "responseParameters": { "method.response.header.Access-Control-Allow-Origin": "'*'" } }Example 2: To remove an integration response header
The following
update-integration-responseexample removes an integration response header.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'Output:
{ "statusCode": "200" }For more information, see Set up an integration response in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateIntegrationResponse
in AWS CLI Command Reference.
-
The following code example shows how to use update-integration.
- AWS CLI
-
Example 1: To add the 'Content-Type: application/json' Mapping Template configured with Input Passthrough
The following
update-integrationexample adds the 'Content-Type: application/json' Mapping Template configured with Input Passthrough.aws apigateway update-integration \ --rest-api-ida1b2c3d4e5\ --resource-ida1b2c3\ --http-methodPOST\ --patch-operations"op='add',path='/requestTemplates/application~1json'"Output:
{ "type": "MOCK", "requestTemplates": { "application/json": null }, "passthroughBehavior": "WHEN_NO_MATCH", "timeoutInMillis": 29000, "cacheNamespace": "a1b2c3", "cacheKeyParameters": [] }Example 2: To update (replace) the 'Content-Type: application/json' Mapping Template configured with a custom template
The following
update-integrationexample updates (replaces) the 'Content-Type: application/json' Mapping Template configured with a custom template.aws apigateway update-integration \ --rest-api-ida1b2c3d4e5\ --resource-ida1b2c3\ --http-methodPOST\ --patch-operations "op='replace',path='/requestTemplates/application~1json',value='{"example": "json"}'"Output:
{ "type": "MOCK", "requestTemplates": { "application/json": "{\"example\": \"json\"}" }, "passthroughBehavior": "WHEN_NO_MATCH", "timeoutInMillis": 29000, "cacheNamespace": "a1b2c3", "cacheKeyParameters": [] }Example 3: To update (replace) a custom template associated with 'Content-Type: application/json' with Input Passthrough
The following
update-integrationexample updates (replaces) a custom template associated with 'Content-Type: application/json' with Input Passthrough.aws apigateway update-integration \ --rest-api-ida1b2c3d4e5\ --resource-ida1b2c3\ --http-methodPOST\ --patch-operations"op='replace',path='requestTemplates/application~1json'"Output:
{ "type": "MOCK", "requestTemplates": { "application/json": null }, "passthroughBehavior": "WHEN_NO_MATCH", "timeoutInMillis": 29000, "cacheNamespace": "a1b2c3", "cacheKeyParameters": [] }Example 4: To remove the 'Content-Type: application/json' Mapping Template
The following
update-integrationexample removes the 'Content-Type: application/json' Mapping Template.aws apigateway update-integration \ --rest-api-ida1b2c3d4e5\ --resource-ida1b2c3\ --http-methodPOST\ --patch-operations"op='remove',path='/requestTemplates/application~1json'"Output:
{ "type": "MOCK", "passthroughBehavior": "WHEN_NO_MATCH", "timeoutInMillis": 29000, "cacheNamespace": "a1b2c3", "cacheKeyParameters": [] }For more information, see Mapping template transformations for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateIntegration
in AWS CLI Command Reference.
-
The following code example shows how to use update-method-response.
- AWS CLI
-
Example 1: To create a new method response header for the 200 response in a method and define it as not required (default)
The following
update-method-responseexample creates a new method response header for the 200 response in a method and defines it as not required (default).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"Output:
{ "statusCode": "200", "responseParameters": { "method.response.header.custom-header": false }, "responseModels": { "application/json": "Empty" } }Example 2: To delete a response model for the 200 response in a method
The following
update-method-responseexample deletes a response model for the 200 response in a method.aws apigateway update-method-response \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --status-code200\ --patch-operations op="remove",path="/responseModels/application~1json"Output:
{ "statusCode": "200" }For more information, see Set up a method response in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateMethodResponse
in AWS CLI Command Reference.
-
The following code example shows how to use update-method.
- AWS CLI
-
Example 1: To modify a method to require an API key
The following
update-methodexample modifies the method to require an API key.aws apigateway update-method \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --patch-operations op="replace",path="/apiKeyRequired",value="true"Output:
{ "httpMethod": "GET", "authorizationType": "NONE", "apiKeyRequired": true, "methodResponses": { "200": { "statusCode": "200", "responseModels": {} } }, "methodIntegration": { "type": "AWS", "httpMethod": "POST", "uri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789111:function:hello-world/invocations", "passthroughBehavior": "WHEN_NO_MATCH", "contentHandling": "CONVERT_TO_TEXT", "timeoutInMillis": 29000, "cacheNamespace": "h7i8j9", "cacheKeyParameters": [], "integrationResponses": { "200": { "statusCode": "200", "responseTemplates": {} } } } }Example 2: To modify a method to require IAM authorization
The following
update-methodexample modifies the method to require IAM authorization.aws apigateway update-method \ --rest-api-id1234123412\ --resource-ida1b2c3\ --http-methodGET\ --patch-operations op="replace",path="/authorizationType",value="AWS_IAM"Output:
{ "httpMethod": "GET", "authorizationType": "AWS_IAM", "apiKeyRequired": false, "methodResponses": { "200": { "statusCode": "200", "responseModels": {} } }, "methodIntegration": { "type": "AWS", "httpMethod": "POST", "uri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789111:function:hello-world/invocations", "passthroughBehavior": "WHEN_NO_MATCH", "contentHandling": "CONVERT_TO_TEXT", "timeoutInMillis": 29000, "cacheNamespace": "h7i8j9", "cacheKeyParameters": [], "integrationResponses": { "200": { "statusCode": "200", "responseTemplates": {} } } } }Example 3: To modify a method to require Lambda authorization
The following
update-methodexample modifies the method to required Lambda authorization.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"Output:
{ "httpMethod": "GET", "authorizationType": "CUSTOM", "authorizerId" : "e4f5g6", "apiKeyRequired": false, "methodResponses": { "200": { "statusCode": "200", "responseModels": {} } }, "methodIntegration": { "type": "AWS", "httpMethod": "POST", "uri": "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789111:function:hello-world/invocations", "passthroughBehavior": "WHEN_NO_MATCH", "contentHandling": "CONVERT_TO_TEXT", "timeoutInMillis": 29000, "cacheNamespace": "h7i8j9", "cacheKeyParameters": [], "integrationResponses": { "200": { "statusCode": "200", "responseTemplates": {} } } } }For more information, see Create, configure, and test usage plans using the API Gateway CLI and REST API and Controlling and managing access to a REST API in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateMethod
in AWS CLI Command Reference.
-
The following code example shows how to use update-model.
- AWS CLI
-
Example 1: To change the description of a model in an API
The following
update-modelexample changes the description of a model in an API.aws apigateway update-model \ --rest-api-id1234123412\ --model-name 'Empty' \ --patch-operations op=replace,path=/description,value='New Description'Output:
{ "id": "a1b2c3", "name": "Empty", "description": "New Description", "schema": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"title\" : \"Empty Schema\",\n \"type\" : \"object\"\n}", "contentType": "application/json" }Example 2: To change the schema of a model in an API
The following
update-modelexample changes the schema of a model in an 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\" }"'Output:
{ "id": "a1b2c3", "name": "Empty", "description": "This is a default empty schema model", "schema": "{ \"$schema\": \"http://json-schema.org/draft-04/schema#\", \"title\" : \"Empty Schema\", \"type\" : \"object\" }", "contentType": "application/json" }For more information, see Data models for REST APIs in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateModel
in AWS CLI Command Reference.
-
The following code example shows how to use update-resource.
- AWS CLI
-
Example 1: To move a resource and place it under a different parent resource in an API
The following
update-resourceexample moves a resource and places it under a different parent resource in an API.aws apigateway update-resource \ --rest-api-id1234123412\ --resource-id1a2b3c\ --patch-operations op=replace,path=/parentId,value='3c2b1a'Output:
{ "path": "/resource", "pathPart": "resource", "id": "1a2b3c", "parentId": "3c2b1a" }Example 2: To rename a resource (pathPart) in an API
The following
update-resourceexample renames a resource (pathPart) in an API.aws apigateway update-resource \ --rest-api-id1234123412\ --resource-id1a2b3c\ --patch-operationsop=replace,path=/pathPart,value=newresourcenameOutput:
{ "path": "/newresourcename", "pathPart": "newresourcename", "id": "1a2b3c", "parentId": "3c2b1a" }For more information, see Develop REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateResource
in AWS CLI Command Reference.
-
The following code example shows how to use update-rest-api.
- AWS CLI
-
Example 1: To change the name of an API
The following
update-rest-apiexample changes the name of an API.aws apigateway update-rest-api \ --rest-api-id1234123412\ --patch-operations op=replace,path=/name,value='New Name'Output:
{ "id": "1234123412", "name": "New Name", "description": "My API description", "createdDate": "2022-10-06T15:32:41+00:00", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "EDGE" ], "ipAddressType": "ipv4" }, "disableExecuteApiEndpoint": false, "rootResourceId": "a1b2c3d4e5" }Example 2: To change the description of an API
The following
update-rest-apiexample changes the description of an API.aws apigateway update-rest-api \ --rest-api-id1234123412\ --patch-operations op=replace,path=/description,value='New Description'Output:
{ "id": "1234123412", "name": "MyAPI", "description": "New Description", "createdDate": "2022-10-06T15:32:41+00:00", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "EDGE" ], "ipAddressType": "ipv4" }, "disableExecuteApiEndpoint": false, "rootResourceId": "a1b2c3d4e5" }For more information, see Develop REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateRestApi
in AWS CLI Command Reference.
-
The following code example shows how to use update-stage.
- AWS CLI
-
Example 1: To override the stage settings for a resource and method
The following
update-stageexample overrides the stage settings and turns off full request/response logging for a specific resource and method.aws apigateway update-stage \ --rest-api-id1234123412\ --stage-name 'dev' \ --patch-operationsop=replace,path=/~1resourceName/GET/logging/dataTrace,value=falseOutput:
{ "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" }For more information, see Setting up a stage for a REST API in the Amazon API Gateway Developer Guide.
Example 2: To update the stage settings for all resources and methods of an API stage
The following
update-stageexample turns on full request/response logging for all resources and methods of an API stage.aws apigateway update-stage \ --rest-api-id1234123412\ --stage-name 'dev' \ --patch-operations 'op=replace,path=/*/*/logging/dataTrace,value=true'Output:
{ "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" }For more information, see Setting up a stage for a REST API in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateStage
in AWS CLI Command Reference.
-
The following code example shows how to use update-usage-plan.
- AWS CLI
-
Example 1: To change the period defined in a Usage Plan
The following
update-usage-planexample changes the period defined in a Usage Plan.aws apigateway update-usage-plan \ --usage-plan-ida1b2c3\ --patch-operations op="replace",path="/quota/period",value="MONTH"Output:
{ "id": "a1b2c3", "name": "MyUsagePlan", "description": "My usage plan", "apiStages": [ { "apiId": "1234123412", "stage": "dev" } ], "throttle": { "burstLimit": 100, "rateLimit": 50.0 }, "quota": { "limit": 5000, "offset": 0, "period": "MONTH" } }Example 2: To change the quota limit defined in a Usage Plan
The following
update-usage-planexample changes the quota limit defined in a Usage Plan.aws apigateway update-usage-plan \ --usage-plan-ida1b2c3\ --patch-operations op="replace",path="/quota/limit",value="500"Output:
{ "id": "a1b2c3", "name": "MyUsagePlan", "description": "My usage plan", "apiStages": [ { "apiId": "1234123412", "stage": "dev" } ], "throttle": { "burstLimit": 100, "rateLimit": 50.0 }, "quota": { "limit": 500, "offset": 0, "period": "MONTH" } }Example 3: To change the throttle rate limit defined in a Usage Plan
The following
update-usage-planexample changes the throttle rate limit defined in a Usage Plan.aws apigateway update-usage-plan \ --usage-plan-ida1b2c3\ --patch-operations op="replace",path="/throttle/rateLimit",value="10"Output:
{ "id": "a1b2c3", "name": "MyUsagePlan", "description": "My usage plan", "apiStages": [ { "apiId": "1234123412", "stage": "dev" } ], "throttle": { "burstLimit": 100, "rateLimit": 10.0 }, "quota": { "limit": 5000, "offset": 0, "period": "MONTH" } }Example 4: To change the throttle burst limit defined in a Usage Plan
The following
update-usage-planexample changes the throttle burst limit defined in a Usage Plan.aws apigateway update-usage-plan \ --usage-plan-ida1b2c3\ --patch-operations op="replace",path="/throttle/burstLimit",value="20"Output:
{ "id": "a1b2c3", "name": "MyUsagePlan", "description": "My usage plan", "apiStages": [ { "apiId": "1234123412", "stage": "dev" } ], "throttle": { "burstLimit": 20, "rateLimit": 50.0 }, "quota": { "limit": 5000, "offset": 0, "period": "MONTH" } }For more information, see Set up usage plans for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateUsagePlan
in AWS CLI Command Reference.
-
The following code example shows how to use update-usage.
- AWS CLI
-
To temporarily modify the quota on an API key for the current period defined in the Usage Plan
The following
update-usageexample temporarily modifies the quota on an API key for the current period defined in the Usage Plan.aws apigateway update-usage \ --usage-plan-ida1b2c3\ --key-id1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu\ --patch-operations op="replace",path="/remaining",value="50"Output:
{ "usagePlanId": "a1b2c3", "startDate": "2016-08-16", "endDate": "2016-08-16", "items": { "1NbjQzMReAkeEQPNAW8r3dXsU2rDD7fc7f2Sipnu": [ [ 0, 50 ] ] } }For more information, see Maintain a usage plan for REST APIs in API Gateway in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateUsage
in AWS CLI Command Reference.
-
The following code example shows how to use update-vpc-link.
- AWS CLI
-
Example 1: To update an existing VPC link name
The following
update-vpc-linkexample updates the name of the specified VPC link.aws apigateway update-vpc-link \ --vpc-link-idab3de6\ --patch-operationsop=replace,path=/name,value=my-vpc-linkOutput:
{ "id": "ab3de6", "name": "my-vpc-link", "targetArns": [ "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/net/my-lb/12a456s89aaa12345" ], "status": "AVAILABLE", "statusMessage": "Your vpc link is ready for use", "tags": {} }For more information, see Private integration using VPC links V1 (legacy) in the Amazon API Gateway Developer Guide.
Example 2: To update an existing VPC link name and description
The following
update-vpc-linkexample updates name of the specified VPC link.aws apigateway update-vpc-link \ --vpc-link-idab3de6\ --patch-operationsop=replace,path=/name,value=my-vpc-linkop=replace,path=/description,value="My custom description"Output:
{ "id": "ab3de6", "name": "my-vpc-link", "description": "My custom description", "targetArns": [ "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/net/my-lb/12a456s89aaa12345" ], "status": "AVAILABLE", "statusMessage": "Your vpc link is ready for use", "tags": {} }For more information, see Private integration using VPC links V1 (legacy) in the Amazon API Gateway Developer Guide.
-
For API details, see UpdateVpcLink
in AWS CLI Command Reference.
-