How to create Api Gateway with terraform

Terraform gives us possibility to write these ressources for our api_gateway :
aws_api_gateway_integration  ==> to specify  proxy or not , wich lambda mock endpoint..
aws_api_gateway_integration_response  ====>to specify  proxy or not , wich lambda mock endpoint..
aws_api_gateway_method  : POST GET
aws_api_gateway_method_response  ====>
aws_api_gateway_resource  =====> to create ressource Person Ticket ….
when we write scripts with terraform for an api gateway the first important ressource that we should create is   aws_api_gateway_rest_api 

like PetStore api or demoApi

We have 2 way to write the whole api_gateway script  ( ressources , methods , proxy , models  stage…..)  where ressource will have it’s own script methods it’s own script  with aws_api_gateway_method  and so on …. :

  1.  write a  script for each ressource  from aws_api_gateway_account  to   aws_api_gateway_vpc_link  with the depends_on argument in the end of each script that he can wait the creation of other ressources (fucking headaches approach)

Or the second easy methods

  1. a. use the plateform console to construct your api , deploy it , enter stage section , export it as swagger + extensions API Gateway Exporter en tant que Swagger + extensions API Gateway

    b.copy the json  in file as myApiSpec.json from example

  2. write a ressource api rest as terraform script
    resource "aws_api_gateway_rest_api" "MyDemoAPI" {
      name        = "MyDemoAPI"
      description = "This is my API for demonstration purposes"
      body= "here you can put the myApiSpec.json content it contains all ressource the other ressources that u need "
  3. body – (Optional) An OpenAPI specification that defines the set of routes and integrations to create as part of the REST API.
  4. run terraform apply

Note: If the body argument is provided, the OpenAPI specification will be used to configure the resources, methods and integrations for the Rest API. If this argument is provided, the following resources should not be managed as separate ones, as updates may cause manual resource updates to be overwritten:

Ps: when passing a json body to terraform script’s don’t forget to use the <


Put Here your api contract in swagger format or only in json


More informations from here :

Une réflexion sur “How to create Api Gateway with terraform

Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:


Vous commentez à l’aide de votre compte Déconnexion /  Changer )

Image Twitter

Vous commentez à l’aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s