How do I configure an AWS API Gateway REST API?
In this guide, we will configure an AWS API Gateway REST API using Pulumi in TypeScript. The example will include creating a REST API, defining a resource, and setting up a method for the resource.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an API Gateway REST API
const restApi = new aws.apigateway.RestApi("myRestApi", {
name: "myRestApi",
description: "This is my REST API for demonstration purposes",
endpointConfiguration: {
types: "REGIONAL",
},
});
// Create a resource within the API
const resource = new aws.apigateway.Resource("myResource", {
parentId: restApi.rootResourceId,
pathPart: "myresource",
restApi: restApi.id,
});
// Create a GET method for the resource
const method = new aws.apigateway.Method("myMethod", {
authorization: "NONE",
httpMethod: "GET",
resourceId: resource.id,
restApi: restApi.id,
requestParameters: {
"method.request.querystring.name": false,
},
});
// Create a deployment of the API
const deployment = new aws.apigateway.Deployment("myDeployment", {
restApi: restApi.id,
stageName: "dev",
}, { dependsOn: [method] });
// Export the API URL
export const apiUrl = deployment.invokeUrl;
Key Points
- We created an API Gateway REST API using
aws.apigateway.RestApi
. - We defined a resource within the API using
aws.apigateway.Resource
. - We set up a GET method for the resource using
aws.apigateway.Method
. - We deployed the API using
aws.apigateway.Deployment
. - The API URL is exported for easy access.
Summary
This guide demonstrated how to configure an AWS API Gateway REST API using Pulumi in TypeScript. We created a REST API, added a resource, defined a method for the resource, and deployed the API. The API URL was exported for access.
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.