Successfully reported this slideshow.
Your SlideShare is downloading. ×

Auto Retweets Using AWS Lambda

Upcoming SlideShare
Introduction to chef
Introduction to chef
Loading in …3

Check these out next

1 of 40 Ad

More Related Content

Slideshows for you (20)

Similar to Auto Retweets Using AWS Lambda (20)


More from CodeOps Technologies LLP (20)

Recently uploaded (20)


Auto Retweets Using AWS Lambda

  1. 1. Auto Retweet Using AWS Lambda Srushith R @SrushithR CodeOps Technologies Krishna Kishore (KK)
  2. 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: serverless-architectures-cmp211 2
  3. 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: getting-started-with-serverless-architectures-cmp211 3
  4. 4. AWS Lambda 4
  5. 5. Topics covered: AWS Lambda  Overview  Key features  Working with Lambda  Developing, deploying and testing on Lambda  Demo  Logging  Benefits  Use cases 5
  6. 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:
  7. 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:
  8. 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
  9. 9. Classical Architecture 9 Content source:
  10. 10. Serverless Architecture Content source: 10
  11. 11. Lambda integrated with other services 11 Content source:
  12. 12. Triggers for Lambda 12 Content source:
  13. 13. Working with Lambda 13 Content source:
  14. 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. 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:
  16. 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. 17. Three ways to create a Lambda function 17 Content source: Lambda AWS Lambda console (web User Interface) AWS SDK (Software Development Kit) AWS CLI (Command Line Interface)
  18. 18. Deploying you code 18 There are three ways to deploy your code :
  19. 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: Logging Print statements Language specific logging libraries
  20. 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:
  21. 21. Accessing CloudWatch logs for lambda 21 Content source:
  22. 22. Lambda limits 22 Content source:
  23. 23. 1 No Servers to Manage 2 Continuous Scaling 3 Subsecond Metering Benefits 23
  24. 24. Lambda use cases 24 Content source:
  25. 25. 25 DEMO!
  26. 26. Python code sample 26 The code is available in the github repo: 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. 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
  28. 28. Create Lambda 28
  29. 29. Encrypt Environment Variables 29 Enable encryption to encrypt the environment variables choose an encryption key
  30. 30. Lambda function handler 30 handler is of the format: <python code file name>.lambda_handler IAM role with logging permissions
  31. 31. Input to the Lambda 31 twitter user name you want to retweet from (without ‘@’)
  32. 32. Schedule an event 32 choose ‘rules’ under ‘events’ in CouldWatch select ‘schedule’
  33. 33. 33 schedule a fixed rate or as a cron expression Schedule an event
  34. 34. Select target Lambda 34 select the target Lambda function
  35. 35. Pass the input event 35 select ‘constant’ and add the input event in JSON format
  36. 36. Create! 36
  37. 37. Schedule rule 37
  38. 38. Output 38
  39. 39. Serverless Summit Join us at India’s first conference on serverless technologies! 39

Editor's Notes

  • 3
  • 14