Deploying our service behind Amazon API Gateway

Pausing the theory, let us quickly jump into an example. Our goal is to set up the API Gateway for the previously deployed books API as a target. Follow these steps:

  1. Let us create a new project and write a new Terraform script that creates and deploys an API on Amazon API Gateway, as follows:
touch $GOPATH/src/github.com/git-user/chapter13/intro/api_gateway.tf

It also links our EC2 instance and API endpoints.

  1. Let us add the Gateway REST API component to the script:
// New API on Amazon API Gatewayresource "aws_api_gateway_rest_api" "test" {  name        = "EC2Example"  description = "Terraform EC2 REST API Example"  endpoint_configuration {    types = ["REGIONAL"]  }}

It takes a few important attributes, ...

Get Hands-On RESTful Web Services with Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.