0
0
AwsHow-ToBeginner · 3 min read

How to Deploy API in AWS API Gateway: Step-by-Step Guide

To deploy an API in AWS API Gateway, create or select your API, then create a deployment by specifying a stage name. This publishes your API so clients can access it via the stage URL.
📐

Syntax

The deployment process in AWS API Gateway involves creating a deployment resource linked to a specific API and stage.

  • API ID: The unique identifier of your API.
  • Stage Name: The environment name like dev, test, or prod.
  • Deployment Description: Optional text describing the deployment.
bash
aws apigateway create-deployment --rest-api-id <api-id> --stage-name <stage-name> --description "Deployment description"
💻

Example

This example shows how to deploy an existing API with ID abc123xyz to a stage named prod. This makes the API available at the prod stage URL.

bash
aws apigateway create-deployment --rest-api-id abc123xyz --stage-name prod --description "Initial production deployment"
Output
{ "id": "a1b2c3d4", "createdDate": "2024-06-01T12:00:00Z", "description": "Initial production deployment", "apiSummary": {} }
⚠️

Common Pitfalls

Common mistakes when deploying APIs in API Gateway include:

  • Not specifying a stage-name, which causes deployment to fail.
  • Deploying without updating the API resources or methods, so changes are not reflected.
  • Using the wrong rest-api-id, which deploys the wrong API or causes errors.
  • Forgetting to redeploy after making API changes.

Always verify your API ID and stage name before deploying.

bash
aws apigateway create-deployment --rest-api-id wrong-id --stage-name prod
# This will fail or deploy the wrong API

# Correct usage:
aws apigateway create-deployment --rest-api-id correct-api-id --stage-name prod
📊

Quick Reference

Remember these key points when deploying your API:

  • Use the correct rest-api-id from your API Gateway console.
  • Choose a meaningful stage-name like dev, test, or prod.
  • Include a description to track deployments.
  • Redeploy after any API changes to update the stage.

Key Takeaways

Always specify the correct API ID and stage name when deploying.
Create a deployment to publish your API to a stage accessible by clients.
Redeploy your API after making any changes to update the stage.
Use descriptive deployment messages to track versions.
Check for errors if deployment fails due to missing or incorrect parameters.