Stage Args
/* Manages an API Gateway Stage. A stage is a named reference to a deployment, which can be done via the aws.apigateway.Deployment
resource. Stages can be optionally managed further with the aws.apigateway.BasePathMapping
resource, aws.apigateway.DomainName
resource, and aws_api_method_settings
resource. For more information, see the API Gateway Developer Guide.
Example Usage
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.apigateway.RestApi;
import com.pulumi.aws.apigateway.RestApiArgs;
import com.pulumi.aws.apigateway.Deployment;
import com.pulumi.aws.apigateway.DeploymentArgs;
import com.pulumi.aws.apigateway.Stage;
import com.pulumi.aws.apigateway.StageArgs;
import com.pulumi.aws.apigateway.MethodSettings;
import com.pulumi.aws.apigateway.MethodSettingsArgs;
import com.pulumi.aws.apigateway.inputs.MethodSettingsSettingsArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var exampleRestApi = new RestApi("exampleRestApi", RestApiArgs.builder()
.body(serializeJson(
jsonObject(
jsonProperty("openapi", "3.0.1"),
jsonProperty("info", jsonObject(
jsonProperty("title", "example"),
jsonProperty("version", "1.0")
)),
jsonProperty("paths", jsonObject(
jsonProperty("/path1", jsonObject(
jsonProperty("get", jsonObject(
jsonProperty("x-amazon-apigateway-integration", jsonObject(
jsonProperty("httpMethod", "GET"),
jsonProperty("payloadFormatVersion", "1.0"),
jsonProperty("type", "HTTP_PROXY"),
jsonProperty("uri", "https://ip-ranges.amazonaws.com/ip-ranges.json")
))
))
))
))
)))
.build());
var exampleDeployment = new Deployment("exampleDeployment", DeploymentArgs.builder()
.restApi(exampleRestApi.id())
.triggers(Map.of("redeployment", exampleRestApi.body().applyValue(body -> serializeJson(
body)).applyValue(toJSON -> computeSHA1(toJSON))))
.build());
var exampleStage = new Stage("exampleStage", StageArgs.builder()
.deployment(exampleDeployment.id())
.restApi(exampleRestApi.id())
.stageName("example")
.build());
var exampleMethodSettings = new MethodSettings("exampleMethodSettings", MethodSettingsArgs.builder()
.restApi(exampleRestApi.id())
.stageName(exampleStage.stageName())
.methodPath("*/*")
.settings(MethodSettingsSettingsArgs.builder()
.metricsEnabled(true)
.loggingLevel("INFO")
.build())
.build());
}
}
Managing the API Logging CloudWatch Log Group
API Gateway provides the ability to enable CloudWatch API logging. To manage the CloudWatch Log Group when this feature is enabled, the aws.cloudwatch.LogGroup
resource can be used where the name matches the API Gateway naming convention. If the CloudWatch Log Group previously exists, the aws.cloudwatch.LogGroup
resource can be imported as a one time operation and recreation of the environment can occur without import.
The below configuration uses
dependsOn
to prevent ordering issues with API Gateway automatically creating the log group first and a variable for naming consistency. Other ordering and naming methodologies may be more appropriate for your environment.
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.apigateway.RestApi;
import com.pulumi.aws.cloudwatch.LogGroup;
import com.pulumi.aws.cloudwatch.LogGroupArgs;
import com.pulumi.aws.apigateway.Stage;
import com.pulumi.aws.apigateway.StageArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var config = ctx.config();
final var stageName = config.get("stageName").orElse("example");
var exampleRestApi = new RestApi("exampleRestApi");
var exampleLogGroup = new LogGroup("exampleLogGroup", LogGroupArgs.builder()
.retentionInDays(7)
.build());
var exampleStage = new Stage("exampleStage", StageArgs.builder()
.stageName(stageName)
.build(), CustomResourceOptions.builder()
.dependsOn(exampleLogGroup)
.build());
}
}
Import
aws_api_gateway_stage
can be imported using REST-API-ID/STAGE-NAME
, e.g.,
$ pulumi import aws:apigateway/stage:Stage example 12345abcde/example
Constructors
Properties
Enables access logs for the API stage. See Access Log Settings below.
Whether a cache cluster is enabled for the stage
Size of the cache cluster for the stage, if enabled. Allowed values include 0.5
, 1.6
, 6.1
, 13.5
, 28.4
, 58.2
, 118
and 237
.
Configuration settings of a canary deployment. See Canary Settings below.
Identifier of a client certificate for the stage.
ID of the deployment that the stage points to
Description of the stage.
Version of the associated API documentation
Whether active tracing with X-ray is enabled. Defaults to false
.