Create a deployment for a REST API in API Gateway - Amazon API Gateway
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Create a deployment for a REST API in API Gateway

In API Gateway, a REST API deployment is represented by a Deployment resource. It's similar to an executable of an API that is represented by a RestApi resource.

For the client to call your API, you must create a deployment and associate a stage with it. A stage is represented by a Stage resource. It represents a snapshot of the API, including methods, integrations, models, mapping templates, and Lambda authorizers (formerly known as custom authorizers). When you update the API, you can redeploy the API by associating a new stage with the existing deployment. We discuss creating a stage in Set up a stage for a REST API in API Gateway.

Create a deployment

The following procedures show how to create a deployment for a REST API.

Amazon Web Services Management Console

You must have created a REST API before deploying it for the first time. For more information, see Develop REST APIs in API Gateway.

The API Gateway console lets you deploy an API by creating a deployment and associating it with a new or existing stage.

  1. Sign in to the API Gateway console at https://console.amazonaws.cn/apigateway.

  2. In the APIs navigation pane, choose the API you want to deploy.

  3. In the Resources pane, choose Deploy API.

  4. For Stage, select from the following:

    1. To create a new stage, select New stage, and then enter a name in Stage name. Optionally, you can provide a description for the deployment in Deployment description.

    2. To choose an existing stage, select the stage name from the dropdown menu. You might want to provide a description of the new deployment in Deployment description.

    3. To create a deployment that is not associated with a stage, select No stage. Later, you can associate this deployment with a stage.

  5. Choose Deploy.

Amazon CLI

When you create a deployment, you instantiate the Deployment resource. You can use the API Gateway console, the Amazon CLI, an Amazon SDK, or the API Gateway REST API to create a deployment.

To use the CLI to create a deployment, use the create-deployment command:

aws apigateway create-deployment --rest-api-id <rest-api-id> --region <region>

The API is not callable until you associate this deployment with a stage. With an existing stage, you can do this by updating the stage's deploymentId property with the newly created deployment ID (<deployment-id>).

aws apigateway update-stage --region <region> \ --rest-api-id <rest-api-id> \ --stage-name <stage-name> \ --patch-operations op='replace',path='/deploymentId',value='<deployment-id>'

When deploying an API the first time, you can combine the stage creation and deployment creation at the same time:

aws apigateway create-deployment --region <region> \ --rest-api-id <rest-api-id> \ --stage-name <stage-name>

This is what is done behind the scenes in the API Gateway console when you deploy an API the first time, or when you redeploy the API to a new stage.

Redeploy a REST API to a stage

To redeploy an API, perform the same steps as in Create a deployment. You can reuse the same stage as many times as desired.

Update the stage configuration of a REST API deployment

After an API is deployed, you can modify the stage settings to enable or disable the API cache, logging, or request throttling. You can also choose a client certificate for the backend to authenticate API Gateway and set stage variables to pass deployment context to the API integration at runtime. For more information, see Update stage settings.

Important

After modifying stage settings, you must redeploy the API for the changes to take effect.

Note

If the updated settings, such as enabling logging, requires a new IAM role, you can add the required IAM role without redeploying the API. However, it can take a few minutes before the new IAM role takes effect. Before that happens, traces of your API calls are not logged even if you have enabled the logging option.

Set stage variables for a REST API deployment

For a deployment, you can set or modify stage variables to pass deployment-specific data to the API integration at runtime. You can do this on the Stage Variables tab in the Stage Editor. For more information, see instructions in Use stage variables for a REST API in API Gateway.

Associate a stage with a different REST API deployment

Because a deployment represents an API snapshot and a stage defines a path into a snapshot, you can choose different deployment-stage combinations to control how users call into different versions of the API. This is useful, for example, when you want to roll back API state to a previous deployment or to merge a 'private branch' of the API into the public one.

The following procedure shows how to do this using the Stage Editor in the API Gateway console. It is assumed that you must have deployed an API more than once.

  1. If you're not already on the Stages pane, in the main navigation pane, choose Stages.

  2. Select the stage you want to update.

  3. On the Deployment history tab, select the deployment you want the stage to use.

  4. Choose Change active deployment.

  5. Confirm you want to change the active deployment and choose Change active deployment in the Make active deployment dialog box.