1. Answers
  2. Building AWS API Gateway Method Settings

How do I build an AWS API Gateway Method Settings?

Introduction

In this guide, we’ll demonstrate how to configure Method Settings for an AWS API Gateway. API Gateway is a powerful tool for building and managing APIs. By setting up Method Settings, you can define various settings like throttling, caching, and logging for specific methods on your API.

To achieve this, we’ll set up an API Gateway, create a resource, attach a method to this resource, and finally configure Method Settings for the method.

Key Points

  • We’re defining an API Gateway REST API.
  • Creating a resource within the API.
  • Adding an HTTP method to the resource.
  • Configuring Method Settings for the method.

The Program

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Define the API Gateway REST API
const example = new aws.apigateway.RestApi("example", {
    name: "example-api",
    description: "Example API Gateway",
});
// Define the API Gateway resource
const exampleResource = new aws.apigateway.Resource("example", {
    restApi: example.id,
    parentId: example.rootResourceId,
    pathPart: "example",
});
// Define the HTTP method
const exampleMethod = new aws.apigateway.Method("example", {
    restApi: example.id,
    resourceId: exampleResource.id,
    httpMethod: "POST",
    authorization: "NONE",
});
// Define the method settings for the POST method
const exampleMethodSettings = new aws.apigateway.MethodSettings("example", {
    restApi: example.id,
    stageName: "example",
    methodPath: pulumi.interpolate`${exampleResource.pathPart}/${exampleMethod.httpMethod}`,
    settings: {
        metricsEnabled: true,
        loggingLevel: "INFO",
        dataTraceEnabled: true,
        throttlingRateLimit: 100,
        throttlingBurstLimit: 200,
        cachingEnabled: false,
    },
});
export const apiId = example.id;
export const resourceId = exampleResource.id;
export const methodHttp = exampleMethod.httpMethod;

Summary

In this example, we created a REST API gateway, added a resource, defined an HTTP POST method for that resource, and configured the method settings to include logging, metrics, and throttling settings. This setup helps in managing API performance and monitoring.

Key Points

  • Established an API Gateway REST API and a resource.
  • Created an HTTP method with no authorization.
  • Configured Method Settings for logging, metrics, and throttling.
  • Exported key identifiers for the API, resource, and method.

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