How do I configure an AWS API Gateway REST API?
To set up an AWS API Gateway REST API, follow these steps: We will define the API Gateway REST API, resources under the API, and a method for one of those resources. Additionally, we need to create a deployment for the API and a stage to deploy it. This example includes all necessary resource definitions.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Define the API Gateway REST API
const exampleApi = new aws.apigateway.RestApi("example_api", {
name: "example-rest-api",
description: "Example API Gateway REST API",
});
// Create a resource (endpoint) within the API
const exampleResource = new aws.apigateway.Resource("example_resource", {
restApi: exampleApi.id,
parentId: exampleApi.rootResourceId,
pathPart: "example",
});
// Define a method for the resource
const exampleMethod = new aws.apigateway.Method("example_method", {
restApi: exampleApi.id,
resourceId: exampleResource.id,
httpMethod: "GET",
authorization: "NONE",
});
// Define a method response
const exampleMethodResponse = new aws.apigateway.MethodResponse("example_method_response", {
restApi: exampleMethod.restApi,
resourceId: exampleMethod.resourceId,
httpMethod: exampleMethod.httpMethod,
statusCode: "200",
});
// Define the API Gateway deployment
const exampleDeployment = new aws.apigateway.Deployment("example_deployment", {
restApi: exampleApi.id,
stageName: "dev",
});
export const apiEndpoint = pulumi.interpolate`${exampleDeployment.invokeUrl}/example`;
In this configuration, we have created an API Gateway REST API, added a resource with the path /example
, and defined a GET method for that resource. We then created a deployment and specified a stage for the API. Lastly, an output was defined to export the API endpoint URL. This setup serves as a basic framework for creating and deploying an API in AWS.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.