AWS Lambda 與 Amazon API Gateway 新功能介紹

43
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Jan 12, 2017 What’s New with AWS Lambda Matt Wu, Business Development Manager Pahud Hsieh, Solution Architect

Transcript of AWS Lambda 與 Amazon API Gateway 新功能介紹

Page 1: AWS Lambda 與 Amazon API Gateway 新功能介紹

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

Jan 12, 2017

What’s New with AWS Lambda

Matt Wu, Business Development Manager

Pahud Hsieh, Solution Architect

Page 2: AWS Lambda 與 Amazon API Gateway 新功能介紹

Lambda API Gateway S3 CloudFront DynamoDB Kinesis

ElastiCache CloudSearch ElasticSearch SQSSES SNS

There Are No Cattle, There Is Only The Herd

Page 3: AWS Lambda 與 Amazon API Gateway 新功能介紹

MOBILE

CHAT APP

AD DATA

ANALYTICS AND

ROUTING

MOBILE APP

ANALYTICS

IMAGE CONTENT

FILTERING

REAL-TIME VIDEO

AD BIDDING

NEWS CONTENT

PROCESSINGGENE SEQUENCE

SEARCH

CLOUD

TELEPHONY

DATA

PROCESSING

WEB

APPLICATIONSWEB APPLICATIONS

THREAT INTELLIGENCE

AND ANALYTICS

NEWS CONTENT

PROCESSINGGAME METRICS ANALYTICS

Serverless Applications

Page 4: AWS Lambda 與 Amazon API Gateway 新功能介紹

CI/CD for serverless appsNew features

AWS SAM

SAM in AWS CloudFormation

Serverless CI/CD pipelines

with AWS CodePipeline and AWS CodeBuild

Dead letter queue

Page 5: AWS Lambda 與 Amazon API Gateway 新功能介紹

Environment

Variables!

Page 6: AWS Lambda 與 Amazon API Gateway 新功能介紹

Environment variables for Lambda functions

Page 7: AWS Lambda 與 Amazon API Gateway 新功能介紹

AWS Serverless Application Model (“SAM”)

• A common language for describing the contents of a

serverless app.

• CloudFormation now “speaks serverless” with native support

for SAM.

• New CloudFormation tools to package and deploy Lambda-

based apps.

• Export Lambda blueprints and functions in SAM

from the AWS Lambda console.

Page 8: AWS Lambda 與 Amazon API Gateway 新功能介紹

AWSTemplateFormatVersion: '2010-09-09’

Transform: AWS::Serverless-2016-10-31

Resources: GetHtmlFunction:

Type: AWS::Serverless::Function

Properties:

CodeUri: s3://flourish-demo-bucket/todo_list.zip

Handler: index.gethtml

Runtime: nodejs4.3

Policies: AmazonDynamoDBReadOnlyAccess

Events:

GetHtml: Type: Api

Properties: Path: /{proxy+} Method: ANY

ListTable: Type: AWS::Serverless::SimpleTable

Functions

APIs

Storage

AWS Serverless Application Model

Page 9: AWS Lambda 與 Amazon API Gateway 新功能介紹

AWSTemplateFormatVersion: '2010-09-09’

Transform: AWS::Serverless-2016-10-31

Resources: GetHtmlFunction:

Type: AWS::Serverless::Function

Properties:

CodeUri: s3://flourish-demo-bucket/todo_list.zip

Handler: index.gethtml

Runtime: nodejs4.3

Policies: AmazonDynamoDBReadOnlyAccess

Events:

GetHtml: Type: Api

Properties: Path: /{proxy+} Method: ANY

ListTable: Type: AWS::Serverless::SimpleTable

AWSTemplateFormatVersion: '2010-09-09'

Resources:

GetHtmlFunctionGetHtmlPermissionProd:

Type: AWS::Lambda::Permission

Properties:

Action: lambda:invokeFunction

Principal: apigateway.amazonaws.com

FunctionName:

Ref: GetHtmlFunction

SourceArn:

Fn::Sub: arn:aws:execute-

api:${AWS::Region}:${AWS::AccountId}:${Se

rverlessRestApi}/Prod/ANY/*

ServerlessRestApiProdStage:

Type: AWS::ApiGateway::Stage

Properties:

DeploymentId:

Ref: ServerlessRestApiDeployment

RestApiId:

Ref: ServerlessRestApi

StageName: Prod

ListTable:

Type: AWS::DynamoDB::Table

Properties:

ProvisionedThroughput:

WriteCapacityUnits: 5

ReadCapacityUnits: 5

AttributeDefinitions:

- AttributeName: id

AttributeType: S

KeySchema:

- KeyType: HASH

AttributeName: id

GetHtmlFunction:

Type: AWS::Lambda::Function

Properties:

Handler: index.gethtml

Code:

S3Bucket: flourish-demo-bucket

S3Key: todo_list.zip

Role:

Fn::GetAtt:

- GetHtmlFunctionRole

- Arn

Runtime: nodejs4.3

GetHtmlFunctionRole:

Type: AWS::IAM::Role

Properties:

ManagedPolicyArns:

-

arn:aws:iam::aws:policy/AmazonDynamoDB

ReadOnlyAccess

- arn:aws:iam::aws:policy/service-

role/AWSLambdaBasicExecutionRole

AssumeRolePolicyDocument:

Version: '2012-10-17'

Statement:

- Action:

- sts:AssumeRole

Effect: Allow

Principal:

Service:

- lambda.amazonaws.com

ServerlessRestApiDeployment:

Type: AWS::ApiGateway::Deployment

Properties:

RestApiId:

Ref: ServerlessRestApi

Description: 'RestApi deployment id:

127e3fb91142ab1ddc5f5446adb094442581a

90d'

StageName: Stage

GetHtmlFunctionGetHtmlPermissionTest:

Type: AWS::Lambda::Permission

Properties:

Action: lambda:invokeFunction

Principal: apigateway.amazonaws.com

FunctionName:

Ref: GetHtmlFunction

SourceArn:

Fn::Sub: arn:aws:execute-

api:${AWS::Region}:${AWS::AccountId}:${Se

rverlessRestApi}/*/ANY/*

ServerlessRestApi:

Type: AWS::ApiGateway::RestApi

Properties:

Body:

info:

version: '1.0'

title:

Ref: AWS::StackName

paths:

"/{proxy+}":

x-amazon-apigateway-any-method:

x-amazon-apigateway-integration:

httpMethod: ANY

type: aws_proxy

uri:

Fn::Sub:

arn:aws:apigateway:${AWS::Region}:lambda:

path/2015-03-

31/functions/${GetHtmlFunction.Arn}/invocati

ons

responses: {}

swagger: '2.0'

AWS Serverless Application Model

REPLACES:

Page 10: AWS Lambda 與 Amazon API Gateway 新功能介紹

SAM: Open Specification

A common language to

describe the content of a

serverless application

across the ecosystem.

Apache 2.0 licensed

GitHub project

Page 11: AWS Lambda 與 Amazon API Gateway 新功能介紹

Serverless CI/CD pipeline

GitHub

Source Deploy

CloudFormationCodeBuild

Build

NEW!

• Pull source directly from GitHub or AWS CodeCommit using AWS

CodePipeline

• Build and package serverless apps with AWS CodeBuild

• Deploy your completed Lambda app with AWS CloudFormation

Page 12: AWS Lambda 與 Amazon API Gateway 新功能介紹

Easily create reliable end-to-end event processing solutions

• Sends all unprocessed events

to your SQS queue or SNS

topic: 3 strikes rule

• Preserves events even if your

code has an issue or the call

was throttled

• Per-function

• Works for all async invokes,

including S3 and SNS events

Dead-letter queue for events

Amazon

SNS

Error

Handler

Failed

eventsPublish

Original

Function

Page 13: AWS Lambda 與 Amazon API Gateway 新功能介紹

DEMO

Page 14: AWS Lambda 與 Amazon API Gateway 新功能介紹

AWS Serverless Application Model (“SAM”)

Page 15: AWS Lambda 與 Amazon API Gateway 新功能介紹

Serverless CI/CD

Page 16: AWS Lambda 與 Amazon API Gateway 新功能介紹

DLQ(Dead Letter Queue)

Page 17: AWS Lambda 與 Amazon API Gateway 新功能介紹
Page 18: AWS Lambda 與 Amazon API Gateway 新功能介紹
Page 19: AWS Lambda 與 Amazon API Gateway 新功能介紹
Page 20: AWS Lambda 與 Amazon API Gateway 新功能介紹

New API Gateway featuresAWS Marketplace SaaS integration

Binary encoding

New places you can use Lambda functionsAmazon Kinesis Firehose

Lambda@Edge/CDN

Page 21: AWS Lambda 與 Amazon API Gateway 新功能介紹

API Gateway and AWS Marketplace integration

• Use API Gateway to simplify

building and operating APIs

• Sell your APIs on the AWS

Marketplace

• Easy discovery and procurement for

your API’s consumers

• Track API usage by consumer / key

• Automated billing through AWS

URL Reputation APIs

Speech understanding

APIs

Monetize your microservices!

Page 22: AWS Lambda 與 Amazon API Gateway 新功能介紹

Binary encoding

Serve images,

audio, and other

binary content

Uses Content-Type and Accept headers

Automatically base64-encodes Lambda integrations

Page 23: AWS Lambda 與 Amazon API Gateway 新功能介紹

Amazon Kinesis Firehose integration

• Simple, real-time data

streaming

• Transform, audit, or

aggregate records

in flight with Lambda

• Flexible buffering

• Lambda and Firehose

both scale automatically

AWS

Lambda

Page 24: AWS Lambda 與 Amazon API Gateway 新功能介紹

Lambda@Edge

• Low-latency request/response

customization

• Supports viewer and origin events

• Preview limitations:

• Node.js only

• 50 ms max

• Headers only

• Pricing: $0.60/M requests and

$0.00000625125 per 128MB-s

• 4K requests free/month

Sign up to join the preview!

Page 25: AWS Lambda 與 Amazon API Gateway 新功能介紹

DEMO

Page 26: AWS Lambda 與 Amazon API Gateway 新功能介紹

API Gateway Binary Support

Page 27: AWS Lambda 與 Amazon API Gateway 新功能介紹

Add Content-Type in Integration Request

Page 28: AWS Lambda 與 Amazon API Gateway 新功能介紹

Add media types in Binary Support

Page 29: AWS Lambda 與 Amazon API Gateway 新功能介紹

Let’s cURL it!

Page 30: AWS Lambda 與 Amazon API Gateway 新功能介紹

Firehose with Lambda

Page 31: AWS Lambda 與 Amazon API Gateway 新功能介紹

Define Lambda Function in Firehose

Page 32: AWS Lambda 與 Amazon API Gateway 新功能介紹

Scenarios

• General Firehose Processing (custom logic)

• Apache Log to JSON

• Apache Log to CSV

• Syslog to JSON

• Syslog to CSV

Page 33: AWS Lambda 與 Amazon API Gateway 新功能介紹

Lambda Blueprints

Page 34: AWS Lambda 與 Amazon API Gateway 新功能介紹

Developer ecosystem — open source

Chalice Framework

Page 35: AWS Lambda 與 Amazon API Gateway 新功能介紹

More new features

Page 36: AWS Lambda 與 Amazon API Gateway 新功能介紹

New Lambda featuresC# with .NET Core

Page 37: AWS Lambda 與 Amazon API Gateway 新功能介紹

C# and .NET Core

• Write Lambda

functions in C#

• netcoreapp 1.0 on

Amazon Linux

• Built-in logging and

metrics

• Supports common

AWS event types

(S3, SNS)

Page 38: AWS Lambda 與 Amazon API Gateway 新功能介紹

Choreographing Lambda functions

Page 39: AWS Lambda 與 Amazon API Gateway 新功能介紹

Attempt a function more than 3X

Add callbacks to asynchronous functions

Handle situations that require waiting

Chain function execution (ABC)

Supports long-running workflows

AWS Step Functions

Reliably orchestrate multiple Lambda functions

Page 40: AWS Lambda 與 Amazon API Gateway 新功能介紹

Capabilities of a serverless platform

Page 41: AWS Lambda 與 Amazon API Gateway 新功能介紹

Learn more

Serverless

CI / CD

Live Demo at booth

AWS Lambda

in C#

02:05pm - 02:45pm

Step

Functions

03:15pm - 03:55pm

02:05pm - 02:45pm

Amazon

Polly

03:15pm - 03:55pm

Serverless

and Alexa IoT

Page 43: AWS Lambda 與 Amazon API Gateway 新功能介紹

Remember to complete

your evaluations!