RestApi

class RestApi : KotlinCustomResource

Manages an API Gateway REST API. The REST API can be configured via importing an OpenAPI specification in the body argument (with other arguments serving as overrides) or via other provider resources to manage the resources (aws.apigateway.Resource resource), methods (aws.apigateway.Method resource), integrations (aws.apigateway.Integration resource), etc. of the REST API. Once the REST API is configured, the aws.apigateway.Deployment resource can be used along with the aws.apigateway.Stage resource to publish the REST API.

Note: Amazon API Gateway Version 1 resources are used for creating and deploying REST APIs. To create and deploy WebSocket and HTTP APIs, use Amazon API Gateway Version 2 resources. !>WARN: When importing Open API Specifications with the body argument, by default the API Gateway REST API will be replaced with the Open API Specification thus removing any existing methods, resources, integrations, or endpoints. Endpoint mutations are asynchronous operations, and race conditions with DNS are possible. To overcome this limitation, use the put_rest_api_mode attribute and set it to merge.

Example Usage

OpenAPI Specification

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.inputs.RestApiEndpointConfigurationArgs;
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 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")
))
))
))
))
)))
.endpointConfiguration(RestApiEndpointConfigurationArgs.builder()
.types("REGIONAL")
.build())
.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());
}
}

Resources

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.Resource;
import com.pulumi.aws.apigateway.ResourceArgs;
import com.pulumi.aws.apigateway.Method;
import com.pulumi.aws.apigateway.MethodArgs;
import com.pulumi.aws.apigateway.Integration;
import com.pulumi.aws.apigateway.IntegrationArgs;
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 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");
var exampleResource = new Resource("exampleResource", ResourceArgs.builder()
.parentId(exampleRestApi.rootResourceId())
.pathPart("example")
.restApi(exampleRestApi.id())
.build());
var exampleMethod = new Method("exampleMethod", MethodArgs.builder()
.authorization("NONE")
.httpMethod("GET")
.resourceId(exampleResource.id())
.restApi(exampleRestApi.id())
.build());
var exampleIntegration = new Integration("exampleIntegration", IntegrationArgs.builder()
.httpMethod(exampleMethod.httpMethod())
.resourceId(exampleResource.id())
.restApi(exampleRestApi.id())
.type("MOCK")
.build());
var exampleDeployment = new Deployment("exampleDeployment", DeploymentArgs.builder()
.restApi(exampleRestApi.id())
.triggers(Map.of("redeployment", Output.tuple(exampleResource.id(), exampleMethod.id(), exampleIntegration.id()).applyValue(values -> {
var exampleResourceId = values.t1;
var exampleMethodId = values.t2;
var exampleIntegrationId = values.t3;
return serializeJson(
jsonArray(
exampleResourceId,
exampleMethodId,
exampleIntegrationId
));
}).applyValue(toJSON -> computeSHA1(toJSON))))
.build());
var exampleStage = new Stage("exampleStage", StageArgs.builder()
.deployment(exampleDeployment.id())
.restApi(exampleRestApi.id())
.stageName("example")
.build());
}
}

Import

aws_api_gateway_rest_api can be imported by using the REST API ID, e.g.,

$ pulumi import aws:apigateway/restApi:RestApi example 12345abcde

Properties

Link copied to clipboard
val apiKeySource: Output<String>

Source of the API key for requests. Valid values are HEADER (default) and AUTHORIZER. If importing an OpenAPI specification via the body argument, this corresponds to the x-amazon-apigateway-api-key-source extension. If the argument value is provided and is different than the OpenAPI value, the argument value will override the OpenAPI value.

Link copied to clipboard
val arn: Output<String>

ARN

Link copied to clipboard

List of binary media types supported by the REST API. By default, the REST API supports only UTF-8-encoded text payloads. If importing an OpenAPI specification via the body argument, this corresponds to the x-amazon-apigateway-binary-media-types extension. If the argument value is provided and is different than the OpenAPI value, the argument value will override the OpenAPI value.

Link copied to clipboard
val body: Output<String>?

OpenAPI specification that defines the set of routes and integrations to create as part of the REST API. This configuration, and any updates to it, will replace all REST API configuration except values overridden in this resource configuration and other resource updates applied after this resource but before any aws.apigateway.Deployment creation. More information about REST API OpenAPI support can be found in the API Gateway Developer Guide.

Link copied to clipboard
val createdDate: Output<String>

Creation date of the REST API

Link copied to clipboard
val description: Output<String>

Description of the REST API. If importing an OpenAPI specification via the body argument, this corresponds to the info.description field. If the argument value is provided and is different than the OpenAPI value, the argument value will override the OpenAPI value.

Link copied to clipboard

Whether clients can invoke your API by using the default execute-api endpoint. By default, clients can invoke your API with the default https://{api_id}.execute-api.{region}.amazonaws.com endpoint. To require that clients use a custom domain name to invoke your API, disable the default endpoint. Defaults to false. If importing an OpenAPI specification via the body argument, this corresponds to the x-amazon-apigateway-endpoint-configuration extension disableExecuteApiEndpoint property. If the argument value is true and is different than the OpenAPI value, the argument value will override the OpenAPI value.

Link copied to clipboard

Configuration block defining API endpoint configuration including endpoint type. Defined below.

Link copied to clipboard
val executionArn: Output<String>

Execution ARN part to be used in lambda_permission's source_arn when allowing API Gateway to invoke a Lambda function, e.g., arn:aws:execute-api:eu-west-2:123456789012:z4675bid1j, which can be concatenated with allowed stage, method and resource path.

Link copied to clipboard
val failOnWarnings: Output<Boolean>?

Whether warnings while API Gateway is creating or updating the resource should return an error or not. Defaults to false

Link copied to clipboard
val id: Output<String>
Link copied to clipboard

Minimum response size to compress for the REST API. Integer between -1 and 10485760 (10MB). Setting a value greater than -1 will enable compression, -1 disables compression (default). If importing an OpenAPI specification via the body argument, this corresponds to the x-amazon-apigateway-minimum-compression-size extension. If the argument value (except -1) is provided and is different than the OpenAPI value, the argument value will override the OpenAPI value.

Link copied to clipboard
val name: Output<String>

Name of the REST API. If importing an OpenAPI specification via the body argument, this corresponds to the info.title field. If the argument value is different than the OpenAPI value, the argument value will override the OpenAPI value.

Link copied to clipboard
val parameters: Output<Map<String, String>>?

Map of customizations for importing the specification in the body argument. For example, to exclude DocumentationParts from an imported API, set ignore equal to documentation. Additional documentation, including other parameters such as basepath, can be found in the API Gateway Developer Guide.

Link copied to clipboard
val policy: Output<String>

JSON formatted policy document that controls access to the API Gateway. For more information about building AWS IAM policy documents with Pulumi, see the AWS IAM Policy Document Guide. The provider will only perform drift detection of its value when present in a configuration. We recommend using the aws.apigateway.RestApiPolicy resource instead. If importing an OpenAPI specification via the body argument, this corresponds to the x-amazon-apigateway-policy extension. If the argument value is provided and is different than the OpenAPI value, the argument value will override the OpenAPI value.

Link copied to clipboard
val pulumiChildResources: Set<KotlinResource>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val putRestApiMode: Output<String>?

Mode of the PutRestApi operation when importing an OpenAPI specification via the body argument (create or update operation). Valid values are merge and overwrite. If unspecificed, defaults to overwrite (for backwards compatibility). This corresponds to the x-amazon-apigateway-put-integration-method extension. If the argument value is provided and is different than the OpenAPI value, the argument value will override the OpenAPI value.

Link copied to clipboard
val rootResourceId: Output<String>

Resource ID of the REST API's root

Link copied to clipboard
val tags: Output<Map<String, String>>?

Key-value map of resource tags. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

Link copied to clipboard
val tagsAll: Output<Map<String, String>>

Map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

Link copied to clipboard
val urn: Output<String>