1. Answers
  2. Deploy an AWS API Gateway Integration Response

How do I deploy an AWS API Gateway integration response?

In this guide, we will deploy an AWS API Gateway Integration Response using Pulumi. We will create an API Gateway, define a resource and method, and then configure an integration response for the method.

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

// Create an API Gateway REST API
const api = new aws.apigateway.RestApi("myApi", {
    description: "My API Gateway",
});

// Create a resource for the API
const resource = new aws.apigateway.Resource("myResource", {
    restApi: api.id,
    parentId: api.rootResourceId,
    pathPart: "myresource",
});

// Create a method for the resource
const method = new aws.apigateway.Method("myMethod", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: "GET",
    authorization: "NONE",
});

// Create an integration for the method
const integration = new aws.apigateway.Integration("myIntegration", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: method.httpMethod,
    integrationHttpMethod: "POST",
    type: "MOCK",
    requestTemplates: {
        "application/json": `{"statusCode": 200}`,
    },
});

// Create an integration response for the method
const integrationResponse = new aws.apigateway.IntegrationResponse("myIntegrationResponse", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: method.httpMethod,
    statusCode: "200",
    responseTemplates: {
        "application/json": `{"message": "Hello, World!"}`,
    },
});

// Create a method response for the method
const methodResponse = new aws.apigateway.MethodResponse("myMethodResponse", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: method.httpMethod,
    statusCode: "200",
    responseModels: {
        "application/json": "Empty",
    },
});

// Export the API Gateway URL
export const url = api.executionArn.apply(arn => `https://${arn.split(":")[5]}.execute-api.${aws.config.region}.amazonaws.com/prod/myresource`);

Key Points

  • We created an API Gateway REST API.
  • We defined a resource and a method for the API.
  • We configured an integration and an integration response for the method.
  • We also set up a method response to match the integration response.

Summary

We successfully deployed an AWS API Gateway Integration Response using Pulumi. This setup includes creating an API Gateway, defining resources and methods, and configuring both integration and method responses.

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