Python + AWS Lambda Hands OnPython + AWS Lambda Hands On

Overview

Python + AWS Lambda Hands On

Python

Preparação do Ambiente

Criação do ambiente:

python3 -m venv ./hands-on-env

Ativação do ambiente:

# Linux
./hands-on-env/bin/activate
# Windows
hands-on-env/Script/activate.bat

PIP

  • É o gerenciador de pacotes do Python.
  • Gradle/Maven/NPM do Python

Instalação das dependências

pip install <NOME DO PACOTE>

# OU

pip install -r requirements.txt

Exemplos de script

exemplos/1-hello-world.py

Notebooks

jupyter notebook notebooks
  1. Python Básico
  2. Bot Bitcoin
  3. Analise Dados Bitcoin

AWS Lambda

  • Function as a service (FAAS)
  • Functions são configuradas, carregadas e executadas por uma runtime
  • Configuramos somente a memória. CPU é alocada indiretamente
  • Pagamos pelo tempo de duração da execução da função
  • Uma das peças principais de uma arquitetura Serverless

Pontos principais (Cai nas certificações):

  • Tempo máximo de duração 15 min
  • Pacote pode ter até 50 Mb zipado e 250 Mb deszipado
  • 512 Mb storage disponível no /tmp
  • Mínimo 128 MB and máximo 3GB

Permissões

  • AWS Lambda execution role

Exemplo: Assume role policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow",
    }
  ]
}

Versões

  • Cada deploy de uma lambda recebe uma versão sequencial e um ARN.
  • O ARN com sufixo latest aponta para o último deploy
  • Por essa caracteristica de imutabilidade de versão, podemos utilizar apelidos (Alias). Feature muito utilizada em integrações com o API Gateway para os modelos de deploy Blue Green
# Criar um apelido
aws lambda create-alias --function-name my-function --name alias-name --function-version version-number --description " "
# Alterar o apelido
aws lambda update-alias --function-name my-function --name alias-name --function-version version-number 
To delete an alias, use the delete-alias command.
# Deletar o apelido
aws lambda delete-alias --function-name my-function --name alias-name 

Ciclo de Vida

image

Fase Inicial:

  • Cria ou descongela a função
  • Faz download do código;
  • Configura as variáveis de ambiente;
  • Roda as funções de inicialização - Tudo que não pertença à função handler

Fase Execução:

  • A função handler é executada. Só pagamos por esse tempo (Billing execution).

Fase Desligamento:

  • Quando a função não recebe requisições por x segundos, a lambda é desligada.

Criação da Infraestrutura

Criação do Projeto

Podemos criar o projeto utilizando o Serverless Application Model (SAM).

  1. Instalar o client

  2. Criar a base do projeto:

sam init
# Seguir o passo a passo

Execução local

sam local invoke FunctionExemplo --event events/event.json
Owner
Marcelo Ortiz de Santana
Marcelo Ortiz de Santana
Sentiment Analysis web app using Streamlit - American Airlines Tweets

Analyse des sentiments à partir des Tweets L'application est développée par Streamlit L'analyse sentimentale est effectuée sur l'ensemble de données d

Abida Hassan 2 Feb 04, 2022
Skautský discord bot

Jáchym 🤖 Open-source skautský discord bot postavený na discord.py O čem? • Funkce • TODO • Poděkování ❓ O čem? Jáchym vznikl jako projekt do odborky

10 May 12, 2022
A modular Telegram Python bot running on python3 with a sqlalchemy database

Nao Tomori Robot Found Me On Telegram As Nao Tomori 🌼 A modular Telegram Python bot running on python3 with a sqlalchemy database. How to setup/deplo

Sena 84 Jan 04, 2023
Parse 11.000 free proxies!

Proxy Machine Description I did this project in order to boost views with the teleboost ✈️ in my Telegram channel. You can use it not only for boostin

VLDSLV 77 Jan 08, 2023
A Python module for communicating with the Twilio API and generating TwiML.

twilio-python The default branch name for this repository has been changed to main as of 07/27/2020. Documentation The documentation for the Twilio AP

Twilio 1.6k Jan 05, 2023
A module to complement discord.py that has Music, Paginator and Levelling.

discord-super-utils A modern python module including many useful features that make discord bot programming extremely easy. Features Modern leveling m

Yash 106 Dec 19, 2022
This is a translator that i made by myself in python with the 'googletrans' library

Translator-Python This is a translator that i made by myself in python with the 'googletrans' library This application completely made in python allow

Thadeuks 2 Jun 17, 2022
Auslesen, entschlüsseln und parsen von Smart Meter Telegrammen

Netz-NÖ SmartMeter-P1-Reader https://www.netz-noe.at/Download-(1)/Smart-Meter/218_9_SmartMeter_Kundenschnittstelle_lektoriert_14.aspx Dieses Skript en

3 Jan 14, 2022
A Python wrapper around the Pushbullet API to send different types of push notifications to your phone or/and computer.

pushbullet-python A Python wrapper around the Pushbullet API to send different types of push notifications to your phone or/and computer. Installation

Janu Lingeswaran 1 Jan 14, 2022
Python module and command line script client for http://urbandictionary.com

py-urbandict py-urbandict is a client for urbandictionary.com. Project page on github: https://github.com/novel/py-urbandict PyPI: https://pypi.org/pr

Roman Bogorodskiy 32 Oct 01, 2022
Python client library for Bigcommerce API

Bigcommerce API Python Client Wrapper over the requests library for communicating with the Bigcommerce v2 API. Install with pip install bigcommerce or

BigCommerce 81 Dec 26, 2022
A Telegram bot to transcribe audio, video and image into text.

Transcriber Bot A Telegram bot to transcribe audio, video and image into text. Deploy to Heroku Local Deploying Install the FFmpeg. Make sure you have

10 Dec 19, 2022
A telegram bot help you to get stylish fonts and text

Stylish Font Bot 🐿 This is a telegram bot help you to get stylish fonts and text. Config Vars 🤖 API_HASH: Get this value from my.telegram.org. API_K

MSTL updates 1 Nov 08, 2021
CSUL Discord Bot

Cruzeiro This is the same old bot running on the Discord Server of CSUL, but i've changed the code. It's better now. Discord.py Heroku How i did The b

Operaho 6 Jan 31, 2022
Available slots checker for Spanish Passport

Bot that checks for available slots to make an appointment to issue the Spanish passport at the Uruguayan consulate page

1 Nov 30, 2021
A repository for 8G server's discord bot

8G Discord-Bot A general-purpose discord bot for the 8G Discord-Server To setup: Create a new file called secrets.py and make it look like this TOKEN=

1 Jan 12, 2022
Send song lyrics to iMessage users using the Genius lyrics API

pyMessage Send song lyrics to iMessage users using the Genius lyrics API. Setup 1.) Open the main.py file, and add your API key on line 7. 2.) Install

therealkingnull 1 Jan 23, 2022
Fully undetected auto skillcheck hack for dead by daylight that works decently well

Auto-skillcheck was made by Love ❌ code ✅ ❔ ・How to use Start off by installing python ofc Open cmd in the same directory and type pip install -r requ

Rdimo 10 Aug 13, 2022
A module grouping multiple translation APIs

translatepy (originally: translate) An aggregation of multiple translation API Translate, transliterate, get the language of texts in no time with the

349 Jan 06, 2023
🐙 Share your Github stats for 2020 on Twitter

Year on Github 🐙 Share your Github stats for 2020 on Twitter. This project contains a small web app that let's you share stats about your Github acti

Johannes Rieke 129 Dec 25, 2022