API Gateway

Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. With a few clicks in the AWS Management Console, you can create an API that acts as a “front door” for applications to access data, business logic, or functionality from your back-end services, such as workloads running on Amazon Elastic Compute Cloud (Amazon EC2), code running on AWS Lambda, or any Web application. Amazon API Gateway handles all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including traffic management, authorization and access control, monitoring, and API version management. Amazon API Gateway has no minimum fees or startup costs. You pay only for the API calls you receive and the amount of data transferred out.

Setting up a REST API

class RestApi

To start building an API you need to create a REST API component:

rest_api = aws.add_rest_api(
    name='my-api',
    description='....',
)
name

A name for this API.

description

A description for this API.

Defining resources

class Resource
name

The name of the resource. This is a uri, for example /animal.

There will be an implict / resource created, which you can attach other resources to:

resource = rest_api.get_resource(name='/')
animal = resource.add_resource(
    name='/animal',
)
parent_resource

The resource this resource is attached to:

dog = rest_api.add_resource(
    name='/animal/dog',
    parent_resource=animal,
)

This is optional if you attach a resource directly:

dog = animal.add_resource(name='/animal/dog')

Defining models

class Model
rest_api.add_model(
    name='dog',
    description='dog schema',
    schema='',
    content_type='application/json',
)
name
description
schema
content_type

This defaults to application/json.

Defining deployments

class Deployment
rest_api.add_deployment(
    name='api-deployment',
    stage='production',
)
name
stage
stage_description
cache_cluster_enabled
cache_cluster_size
variables

Adding stages

A stage defines the path through which an API deployment is accessible. With deployment stages, you can have multiple releases for each API, such as alpha, beta, and production. Using stage variables you can configure an API deployment stage to interact with different backend endpoints.

class Stage

You attach new stages to a deployment:

my_stage = deployment.add_stage(
    name='staging',
)
name
description
cache_cluster_enabled
cache_cluster_size
variables

Attaching methods

class Method

You attach an method to a resource:

my_method = resource.add_method(
    method = "GET",
)
name
authorization_type
api_key_required
request_parameters
request_models

Attaching method responses

class MethodResponse

You attach an method response to a resource:

my_method_response = resource.add_method_response(
    name = "GET",
)
name
status_code
response_parameters
response_models

Attaching integrations

class Integration

You attach an integration to a resource:

my_integration = resource.add_integration(
    name = "GET",
)
name

E.g. GET

integration_type

Can be HTTP, AWS or MOCK.

integration_http_method
request_parameters
request_templates
uri
credentials
cache_namespace
cache_key_parameters

Attaching integration responses

class IntegrationResponse

You attach an integration response to a resource:

my_integration_response = resource.add_integration_response(
    name = "GET",
)
name

E.g. GET

status_code
selection_pattern
response_parameters
response_templates