1. Answers
  2. Enabling Automatic Deployment to Stages for New API Versions

How do I enable automatic deployment to stages for new API versions?

In this guide, we will enable automatic deployment to stages for new API versions using Pulumi. We will use AWS API Gateway to create an API, deploy it, and configure a stage that will automatically deploy new versions of the API.

The following Pulumi program will:

  1. Create an API Gateway.
  2. Create a deployment for the API.
  3. Create a stage that automatically deploys new versions of the API when they are available.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create an API Gateway
const api = new aws.apigatewayv2.Api("myApi", {
    protocolType: "HTTP",
    name: "myApi",
});

// Create a deployment for the API
const deployment = new aws.apigatewayv2.Deployment("myDeployment", {
    apiId: api.id,
    description: "Initial deployment of the API",
});

// Create a stage with auto-deploy enabled
const stage = new aws.apigatewayv2.Stage("myStage", {
    apiId: api.id,
    deploymentId: deployment.id,
    name: "prod",
    autoDeploy: true, // Enable automatic deployment
    description: "Production stage",
});

export const apiEndpoint = stage.invokeUrl;

Key Points

  • We created an API Gateway using aws.apigatewayv2.Api.
  • We deployed the API using aws.apigatewayv2.Deployment.
  • We created a stage with autoDeploy set to true to enable automatic deployment of new API versions.

Summary

In this guide, we configured an API Gateway with automatic deployment to stages for new API versions using Pulumi. This setup ensures that any new deployment of the API will be automatically available in the specified stage, streamlining the release process and ensuring that the latest version of the API is always available.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up