47
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Bob Kinney, AWS Serverless (Amazon API Gateway) December 1, 2016 SVR402 Operating Your Production API

AWS re:Invent 2016: Operating Your Production API (SVR402)

Embed Size (px)

Citation preview

Page 1: AWS re:Invent 2016: Operating Your Production API (SVR402)

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Bob Kinney, AWS Serverless (Amazon API Gateway)

December 1, 2016

SVR402

Operating Your Production

API

Page 2: AWS re:Invent 2016: Operating Your Production API (SVR402)

What to Expect from the Session

Brief review of Amazon API Gateway/AWS Lambda

Monitoring Your API

Amazon CloudWatch Metrics/Alarms

Amazon CloudWatch Logs

Protecting Your API

Throttling

Authorization

Usage Plans

Managing Your API

Page 3: AWS re:Invent 2016: Operating Your Production API (SVR402)

Amazon API Gateway

Create a unified

API front end for

multiple

microservices

Authenticate and

authorize

requests to a

back end

DDoS protection

and throttling for

your back end

Throttle, meter,

and monetize API

usage by third-

party developers

Page 4: AWS re:Invent 2016: Operating Your Production API (SVR402)

API Gateway Integrations

Internet

Mobile Apps

Websites

Services

Lambda

functions

AWS

API Gateway

Cache

Endpoints on

Amazon EC2

All publicly

accessible

endpoints

Amazon

CloudWatch

Monitoring

Amazon

CloudFront

Any other

AWS service

Page 5: AWS re:Invent 2016: Operating Your Production API (SVR402)

Cost-effective and

efficient

No infrastructure

to manage

Pay only for what you use

Bring Your

Own Code

Productivity-focused compute platform to build powerful, dynamic, modular

applications in the Cloud

Run code in standard

languages

Focus on business logic

AWS Lambda

1 2 3

Page 6: AWS re:Invent 2016: Operating Your Production API (SVR402)

Meet Doug

Doug loves coffee.

Doug also writes apps.

Doug built TAMPR–a service for

sharing reviews of coffee and coffee

shops.

Doug built the TAMPR back end

serverless, with API Gateway and

Lambda.

Page 7: AWS re:Invent 2016: Operating Your Production API (SVR402)

First Reviews of TAMPR

“I want to love this app, but every time

I try to check in with my morning

coffee, I get errors.”

“The app works great if I’m getting an

afternoon coffee, but during the

mornings it’s almost unusable.”

“Too many errors, it never seems to

work.”

Page 8: AWS re:Invent 2016: Operating Your Production API (SVR402)

Monitoring Your API:

Amazon CloudWatch Metrics

Page 9: AWS re:Invent 2016: Operating Your Production API (SVR402)

Amazon CloudWatch Metrics

API Gateway default metrics set:

Count–Total number of invokes received by API Gateway

4XXError–Number of invokes that generated a 4XX error

(includes throttling)

5XXError–Number of invokes that generated a 5XX error

Latency–Total time API Gateway took to fully process request

IntegrationLatency–Time API Gateway took to call integration

CacheHitCount–Number of successful cache fetches

CacheMissCount–Number of unsuccessful cache fetches

Page 10: AWS re:Invent 2016: Operating Your Production API (SVR402)

Amazon CloudWatch Metrics

Detailed metrics:

Same set of metrics at method level

Can be enabled globally or only for specific methods

GET PUT DELETE

Page 11: AWS re:Invent 2016: Operating Your Production API (SVR402)

Amazon CloudWatch Metrics

Default Metrics

Included for free

Broken down by API stage

Detailed Metrics

Standard CloudWatch pricing

Broken down by method

Page 12: AWS re:Invent 2016: Operating Your Production API (SVR402)

Amazon CloudWatch Alarms

Any metric can be tied to an alarm

Alarm notifications can be sent to an Amazon SNS topic

SNS topic can then send to any number of destinations:

E-mail address

Amazon SQS queue

Lambda function

Page 13: AWS re:Invent 2016: Operating Your Production API (SVR402)

CloudWatch Alarms–NEW

Error and cache metrics now support averages

Alarm on the rate of failures in your API, not just raw count!

Page 14: AWS re:Invent 2016: Operating Your Production API (SVR402)

Demo

Page 15: AWS re:Invent 2016: Operating Your Production API (SVR402)

Check in with Doug

Doug now has alarms to be alerted

when his customers get errors calling

his serverless API, but how does he

know why his customers get errors?

Page 16: AWS re:Invent 2016: Operating Your Production API (SVR402)

Monitoring Your API:

Amazon CloudWatch Logs

Page 17: AWS re:Invent 2016: Operating Your Production API (SVR402)

Amazon CloudWatch Logs

API Gateway logging:

Two levels of logging, ERROR and INFO

Optionally log method request/body content

Set globally in stage, or override per method

Lambda logging:

Logging directly from your code

Basic request information included

Log pivots:

Build metrics based on log filters

Jump to logs that generated metrics

Page 18: AWS re:Invent 2016: Operating Your Production API (SVR402)

Amazon CloudWatch Logs

So many log streams…

Page 19: AWS re:Invent 2016: Operating Your Production API (SVR402)

CloudWatch Logs

apilogs - https://github.com/rpgreen/apilogs

Search and stream your API Gateway logs (and Lambda)

Basic syntax highlighting

View API Gateway and Lambda logs together

Page 20: AWS re:Invent 2016: Operating Your Production API (SVR402)

Demo

Page 21: AWS re:Invent 2016: Operating Your Production API (SVR402)

Check in with Doug

Thanks to logging, Doug now knows

that his API is generating errors during

peak loads because there’s spurious

traffic hitting a particular API method at

a much higher than expected rate due

to a bug in the mobile app.

He now needs a way to to limit the

traffic from those devices to let other

traffic through.

Page 22: AWS re:Invent 2016: Operating Your Production API (SVR402)

Protecting Your API:

Throttling

Page 23: AWS re:Invent 2016: Operating Your Production API (SVR402)

API Gateway Throttling

Three levels of throttling for APIs:

API key-level throttling–Configurable in usage plan

Method-level throttling–Configurable in stage settings

Account-level throttling–Limits can be increased

Page 24: AWS re:Invent 2016: Operating Your Production API (SVR402)

API Gateway Throttling

Token bucket algorithm:

Burst–the maximum size of the bucket

Rate–the number of tokens added to the bucket

Page 25: AWS re:Invent 2016: Operating Your Production API (SVR402)

API Gateway Throttling–NEW

Limits apply in order of most specific to least specific:

API key, method, account

Requests throttled for any reason will no longer be billed

Page 26: AWS re:Invent 2016: Operating Your Production API (SVR402)

Demo

Page 27: AWS re:Invent 2016: Operating Your Production API (SVR402)

Check in with Doug

Thanks to throttling, Doug has limited

the impact from the buggy version of

the application to affecting only the

one method.

He can ship updates to affected

customers to re-route traffic as

needed.

Page 28: AWS re:Invent 2016: Operating Your Production API (SVR402)

TAMPR Promotions

TAMPR has become popular, and

coffee shops and roasters are

contacting Doug to discuss

possibilities of promotions through the

app.

Doug needs a way to allow these

shops to create accounts and create

and edit promotions on demand.

Page 29: AWS re:Invent 2016: Operating Your Production API (SVR402)

Protecting Your API:

Authentication/Authorization

Page 30: AWS re:Invent 2016: Operating Your Production API (SVR402)

Authentication Type Comparison

Feature AWS IAM CUSTOM AMAZON

COGNITO

Authentication X X X

Authorization X X

Signature V4 X

Amazon Cognito User Pools X X

Third-Party Authentication X

Additional Costs NONE Pay per

authorizer invoke

NONE

Page 31: AWS re:Invent 2016: Operating Your Production API (SVR402)

API Gateway Authorization–NEW

CUSTOM authorizers support additional returned context:

key/value dictionary

Requests that fail authorization will no longer be billed

Page 32: AWS re:Invent 2016: Operating Your Production API (SVR402)

Demo

Page 33: AWS re:Invent 2016: Operating Your Production API (SVR402)

Check in with Doug

TAMPR promotions have been a hit,

and the app is more popular than ever.

Doug is now speaking with other

services, such as a new site focused

on brunch spots, on how they can

work together.

Doug wants a way he can expose

portions of his API to these third

parties, but track their usage for

potential billing opportunities.

Page 34: AWS re:Invent 2016: Operating Your Production API (SVR402)

Protecting Your API:

Usage Plans

Page 35: AWS re:Invent 2016: Operating Your Production API (SVR402)

API Key Throttling

Rate/Burst per API Key

API Key Usage

Daily usage records

API Key Quota

Periodic limits per API Key

API Gateway Usage Plans

Page 36: AWS re:Invent 2016: Operating Your Production API (SVR402)

Demo

Page 37: AWS re:Invent 2016: Operating Your Production API (SVR402)

Check in with Doug

TAMPR is continuing to grow, and

Doug is now bringing in people to help

work on updates.

He is looking for ways to formalize the

update process.

Page 38: AWS re:Invent 2016: Operating Your Production API (SVR402)

Managing Your API

Page 39: AWS re:Invent 2016: Operating Your Production API (SVR402)

Stages are named links to a deployed version of your API

Recommended for managing API lifecycle:

dev/test/prod

alpha/beta/gamma

Support for parameterized values via stage variables

API Stages

Page 40: AWS re:Invent 2016: Operating Your Production API (SVR402)

Maintain multiple versions of your Lambda code and link a

named alias

Works great in combination with API stages and stage

variables

Lambda Versions

Page 41: AWS re:Invent 2016: Operating Your Production API (SVR402)

Run your APIs within your own DNS zone

Recommended for supporting multiple versions:

api.tampr.com/v1 -> restapi1

api.tampr.com/v2 -> restapi2

Custom Domains

Page 42: AWS re:Invent 2016: Operating Your Production API (SVR402)

Portable API definition (JSON/YAML)

Import/export your API:

Swagger extensions for API Gateway

Recommended for tracking changes to your API

Swagger

Page 43: AWS re:Invent 2016: Operating Your Production API (SVR402)

Chalice - https://github.com/awslabs/chalice

Python microframework, includes deployment scripts

Serverless - https://github.com/serverless/serverless

Node.js, Python, Java, and Scala

Describe API and other resources

SAM - https://github.com/awslabs/serverless-application-model

Serverless Application Model

Extends AWS CloudFormation

Can integrate with AWS CodePipeline for CI/CD solution

Deployment Mechanisms

Page 44: AWS re:Invent 2016: Operating Your Production API (SVR402)

Be Like Doug

• Monitor your APIs with metrics and

alarms to find problems.

• Use logging to diagnose problems

with your APIs.

• Make use of throttling and

authentication to limit blast radius

and protect critical API components.

• Make your API available to third

parties via usage plans.

• Manage your API with

stages/versions and deployment

tools.

Page 45: AWS re:Invent 2016: Operating Your Production API (SVR402)

Have Questions?

Visit the Application Services Booth!

Forums

https://forums.aws.amazon.com/

StackOverflow

http://stackoverflow.com/questions/tagged/aws-api-gateway

Page 46: AWS re:Invent 2016: Operating Your Production API (SVR402)

Thank you!

Page 47: AWS re:Invent 2016: Operating Your Production API (SVR402)

Remember to complete

your evaluations!