aws mobile with lambda and sns

29
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Hosted by AWS Technical Evangelists, Danilo Poccia & Ian Massingham AWS Mobile Web Day 24 th March 2016 Follow AWS on Twitter at @AWScloud & AWS Mobile Services at @awsmobile

Upload: amazon-web-services

Post on 19-Jan-2017

1.122 views

Category:

Technology


2 download

TRANSCRIPT

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

Hosted by AWS Technical Evangelists, Danilo Poccia & Ian Massingham

AWS Mobile Web Day

24th March 2016

Follow AWS on Twitter at @AWScloud & AWS Mobile Services at @awsmobile

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

Best Practices: Infrastructure

Deployment and Monitoring with AWS

Lambda and Amazon SNS

Vyom Nagrani, Senior Product Manager, AWS Lambda

Amazon Simple Notification Service (SNS): publish

messages to multiple subscribers

• Follows the “publish-subscribe” (pub-

sub) messaging paradigm

• Group multiple recipients using topics

• Send to mobile device users, email

recipients or distributed services

• No upfront costs and pay as you go

pricing

Publisher

Subscriber

1

Subscriber

2

Subscriber

3

Subscriber

4

Amazon

SNS

Benefits of Amazon SNS for push notifications

“Fast, Flexible, Global Messaging to Any Device or Endpoint”

Global and Fast at Massive

Scale

Send billions of messages per

day with minimal latencies

across the world Use via Java, Python, PHP,

Node.js, or .NET

Support for Multiple Platforms or

Frameworks

Send Messages to Any Device or

Endpoint

Send Notifications via Mobile Push,

SQS, HTTP, Email, SMS, or

Lambda

AWS Lambda: A compute service that runs your code

in response to events

Lambda functions: Stateless, trigger-based code execution

Triggered by events:

• Direct Sync and Async invocations

• Put to an Amazon S3 bucket

• SNS subscription

• And many more …

Makes it easy to

• Build back-end services that perform at scale

• Perform data-driven auditing, analysis, and notification

High performance at any scale;

Cost-effective and efficient

No Infrastructure to manage

Pay only for what you use: Lambda

automatically matches capacity to

your request rate. Purchase

compute in 100ms increments.

Bring Your Own Code

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

applications in the cloud”

Run code in a choice of standard

languages. Use threads, processes,

files, and shell scripts normally.

Focus on business logic, not

infrastructure. You upload code; AWS

Lambda handles everything else.

Benefits of AWS Lambda for building a server-less data

processing engine

1 2 3

Subscribe your Lambda functions to SNS topics

Customer

Systems

End-User Devices

(via AWS Mobile

SDK)

“Direct Publish”

publish (msg, endpointARN)

Topic

“A”

“Topic Publish”

publish(msg,topicArn)

AP

NS

GC

MA

DM

WN

S

Mobile Push Gateways

Amazon SQS Queues

HTTP Destinations

SMS (US Mobile Numbers Only)

Email

AWS Lambda Functions

Walkthrough of using an Amazon SNS message to

invoke AWS Lambda

Amazon

SNS

AWS Lambda Amazon

CloudWatch Logs

Publish

message to

topic

Attaching Lambda functions to Amazon SNS topic

subscriptions

• Multiple subscriptions: Subscribe multiple Lambda functions to same SNS topic

• For every subscribed function, each message to the SNS topic will invoke Lambda once

• Retries: For Amazon SNS, AWS Lambda retries each function at least 3 times

• Permission model: SNS pushes events to Lambda, so grant SNS invocation

permission through a resource policy, and add the execution role to Lambda

• Automatic Scaling: Lambda scales automatically with SNS publish rate

• Safety throttle of 100 concurrent Lambda functions, can be increased by AWS Support Center

Monitoring and Debugging Lambda functions

• Console Dashboard

• Lists all Lambda functions

• Easy editing of resources, event sources and other settings

• At-a-glance metrics

• Metrics in CloudWatch

• Requests

• Errors

• Latency

• Throttles

• Logging in CloudWatch Logs

Using SNS+Lambda for automated responses to alerts

(Infrastructure Monitoring and Deployment)

AWS

Lambda

Amazon

SNS

Amazon

CloudWatch Alarm

ec2

runInstance

ecs

startTask

beanstalk

updateApp

kinesis

splitShard

Any API call

Use cases of SNS+Lambda for Infrastructure

Monitoring and Automation

Input from CloudWatch Alarms

• EC2 metrics: CPU, Disk, Network, Health

• EBS metrics: Read/Write Bytes/Ops

• ELB metrics: HTTPCode

• S3 metrics: NumberObjects, BucketSize

• DynamoDB metrics: Read/Write capacity

• Custom metrics/alarms

Output functionality

• Launch instance/tasks/apps

• Provision tables/shards/storage

• External endpoints

https://aws.amazon.com/blogs/compute/scaling-amazon-ecs-services-automatically-using-amazon-cloudwatch-and-aws-lambda/

Using Lambda to forward SNS messages to external

endpoints

http://danilop.net/aws/2015/07/26/sns2ifttt/ | https://github.com/danilop/SNS2IFTTT

AWS

Lambda

Amazon

SNS

IFTTT via

the Maker

channel

Amazon

CloudWatch Alarm

Amazon

AutoScaling

Using SNS fan out S3 event notifications to multiple

Lambda functions

https://aws.amazon.com/blogs/compute/fanout-s3-event-notifications-to-multiple-endpoints/

Amazon S3 Amazon SNS

AWS Lambda

Function 1

AWS Lambda

Function 2

Using SNS+Lambda to manage and deploy Lambda

functions

https://aws.amazon.com/blogs/compute/dynamic-github-actions-with-aws-lambda/

AWS

Lambda

Amazon

SNS

GitHub Repo

lambda

createFn ()

Three Next Steps

1. Create and test your first Amazon SNS topic. When publishers have information or

updates to notify their subscribers about, they can publish a message to the topic –

which immediately triggers Amazon SNS to deliver the message to all applicable

subscribers.

2. Create and test your first Lambda function. With AWS Lambda, there are no new

languages, tools, or frameworks to learn. You can use any third party library, even

native ones.

3. Subscribe your Lambda function to your SNS topic … A message delivery from

Amazon SNS to an AWS Lambda function creates an instance of the AWS Lambda

function and invokes it with your message as an input.

Thank you!

Visit http://aws.amazon.com/sns, the AWS

Mobile Development blog, and the SNS forum to

learn more and get started using Amazon SNS

Visit http://aws.amazon.com/lambda, the

AWS Compute blog, and the Lambda forum

to learn more and get started using Lambda.