1. Auto Retweet Using AWS
Lambda
Srushith R
@SrushithR
CodeOps Technologies
Krishna Kishore (KK)
2. How will the application
handle server hardware failure?
How can I control
Serversaccess from my servers?
When should I decideto
scale out my servers?
When should I decideto
scale up myservers?
What size servers are
right for my budget?
How much remaining
capacity do my
servers have?
(AAHHHHHHHHH!!)
How will I keep
my server OS
patched?
How many
servers should I
budget for?
Content source: https://www.slideshare.net/AmazonWebServices/aws-reinvent-2016-getting-started-with-
serverless-architectures-cmp211
2
3. • VMs
• Machine as the unit of scale
• Abstracts the hardware
• Containers
• Application as the unit of scale
• Abstracts the OS
• Serverless
• Functions as the unit of scale
• Abstracts the language runtime
AWS Lambda
Amazon ECS
Amazon EC2
What is Serverless
computing?
Content source: https://www.slideshare.net/AmazonWebServices/aws-reinvent-2016-
getting-started-with-serverless-architectures-cmp211
3
5. Topics covered: AWS
Lambda
Overview
Key features
Working with Lambda
Developing, deploying and testing on Lambda
Demo
Logging
Benefits
Use cases
5
6. Lambda: Overview
AWS Lambda is a serverless compute service that
runs your code in response to events and
automatically manages the underlying compute
resources for you
It executes your code only when needed and scales
automatically, from a few requests per day to
thousands per second
6
Content source: https://aws.amazon.com/documentation/
7. Lambda: Overview
You pay only for the compute time you consume -
there is no charge when your code is not running
With AWS Lambda, you can run code for virtually any
type of application or backend service - all with zero
administration
7
Content source: https://aws.amazon.com/documentation/
8. Lambda: Key features 8
Extend Other
AWS Services
with Custom
Logic
Build Custom
Back-end
Services
Completely
Automated
Administration
Built-in Fault
Tolerance
Automatic
Scaling
Run Code at
Edge Locations
Integrated
Security Model
14. Bring your own code
• Node.js, Java, Python
• Bring your own libraries
(even native ones)
Simple resource model
• Select power rating from
128 MB to 1.5 GB
• CPU and network
allocated proportionately
• Reports actual usage
Flexible authorization
• Securely grant access to
resources, including
VPCs
• Fine-grained control
over who can call your
functions
Flexible use
• Call or send events
• Integrated with other
AWS services
• Build whole serverless
ecosystems
Using Lambda 14
15. Lambda execution
environment
15
Linux kernel version –
4.4.51-
40.60.amzn1.x86_64
Public Amazon Linux AMI
version (AMI name: amzn-
ami-hvm-
2016.03.3.x86_64-gp2)
Image source: https://en.wikipedia.org/wiki/Linux_kernel
16. Lambda runtime
Lambda supports the following runtime versions:
16
Node.js
• v4.3.2
• v6.10.2
Java
• Java 8
Python
• Python
3.6
• Python
2.7
.NET Core
• .NET
Core
1.0.1 (C#)
Note: If you are using any native binaries in your code, make sure they are compiled in this
environment. Also note that only 64-bit binaries are supported on AWS Lambda
17. Three ways to create a
Lambda function
17
Content source: https://aws.amazon.com/documentation/
Lambda
AWS Lambda
console (web
User
Interface)
AWS SDK
(Software
Development
Kit)
AWS CLI
(Command
Line Interface)
19. Logging in AWS Lambda
19
Your Lambda function can contain logging statements. AWS Lambda
writes these logs to CloudWatch. Logging can be done in two ways:
Content source: https://aws.amazon.com/documentation/
Logging
Print statements
Language specific
logging libraries
20. Amazon CloudWatch logs
You can use Amazon CloudWatch Logs to monitor,
store, and access your log files from AWS
Lambda. You can then retrieve the associated log
data from CloudWatch Logs
Archive Log Data—You can use CloudWatch Logs to
store your log data in highly durable storage
20
Content source: https://aws.amazon.com/documentation/
21. Accessing CloudWatch logs
for lambda
21
Content source: https://www.slideshare.net/AmazonWebServices/aws-lambda-and-the-serverless-cloud
26. Python code sample 26
The code is available in the github repo:
https://github.com/CodeOpsTechnologies/Real_time_retweets
Prerequisites for the zip file:
1. Python-twitter module:
The module must be installed into a separate folder. Use
the modified pip command:
pip install --target <target folder path> python-twitter
Note: The python code uses boto3 module, but installing it is not
required as it is available as a default module in AWS Lambda
27. Steps to deploy code to
Lambda
1. Create a zip file with the python code and dependency
modules (python-twitter).
2. Create a Lambda function
Upload the zip file
Define environment variables and encrypt them
3. Create an event to schedule the lambda every one hour
27