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
Social Framework

Social Int Framework Social Int Framework its a Selenium script that scrape the IG photos and do a Reverse search on google and yandex for finding ano

29 Dec 06, 2022
An accessible Archive of Our Own reader application written in python.

AO3-A11y. Important disclaimer. This project is under active development. Many features might not yet be present, or some things might not work at all

4 Nov 11, 2022
This project checks the weather in the next 12 hours and sends an SMS to your phone number if it's going to rain to remind you to take your umbrella.

RainAlert-Request-Twilio This project checks the weather in the next 12 hours and sends an SMS to your phone number if it's going to rain to remind yo

9 Apr 15, 2022
A Discord bot to combat phishing links for Steam trades and Discord gifts.

delink-bot A Discord bot to combat phishing links for Steam trades and Discord gifts. Requirement python3 -m pip install -U discord.py python3 -m pip

hugonun 15 Dec 09, 2022
Easy & powerful bot to check if your all Telegram bots are working or not

Easy & powerful bot to check if your all Telegram bots are working or not. This bot status bot updates every 105 minutes & runs for 24x7 hours.

35 Dec 30, 2022
Running Performance Calculator

Running Performance Calculator 👉 Have you ever wondered if you ran 10km at 2000

Davide Liu 6 Oct 26, 2022
Lamblayer: a minimal deployment tool for AWS Lambda layers

lamblayer lamblayer is a minimal deployment tool for AWS Lambda layers. lamblayer does, Create a Layers of built pip-installable python packages. Crea

Yusuke Takahashi 2 Aug 19, 2022
AminoSpamKilla - Spam bot for amino that uses multiprocessing module

AminoSpamKilla Spam bot for amino that uses multiprocessing module Pydroid Open

4 Jun 27, 2022
Telegram bot for stream music on telegram, powered by py-tgcalls and Pyrogram

Telegram Streamer Bot Telegram bot for stream music on telegram, powered by py-tgcalls and Pyrogram ✨ Features Coming soon, help me to improve it 🛠 C

Shohih Abdul 11 Oct 21, 2022
Another Autoscaler is a Kubernetes controller that automatically starts, stops, or restarts pods from a deployment at a specified time using a cron annotation.

Another Autoscaler Another Autoscaler is a Kubernetes controller that automatically starts, stops, or restarts pods from a deployment at a specified t

Diego Najar 66 Nov 19, 2022
I was sick of having to hand my friends my phone, so I gave my Spotify some SMS features!

SMSpotifY Just a little tool so that my friends can text a phone number and add to my spotify queue for parties and such:) Features Roles / Access Con

Sara 2 Jan 17, 2022
Discord Webhook Proxy for Roblox payloads.

RoProxy A Discord webhook proxy passthrough for roblox. Setup Your port and endpoint are in the config.json, make sure both app.py and config.json are

PythonSerious 2 Nov 05, 2021
👨‍💼Linkedin API for Python

linkedin_api 👨‍💼 Linkedin API for Python No "official" API access required - just use a valid Linkedin account! Programmatically send messages, get

Tom Quirk 918 Dec 29, 2022
Your custom slash commands Discord bot!

Slashy - Your custom slash-commands bot Hey, I'm Slashy - your friendly neighborhood custom-command bot! The code for this bot exists because I'm like

Omar Zunic 8 Dec 20, 2022
Music bot for Discord

Treble Music bot for Discord Youtube is after music bots on Discord. So we are here to fill the void. Introducing Treble, the next generation of Disco

Aja Khanal 0 Sep 16, 2022
Análise de dados abertos do programa Taxigov.

Análise de dados do Taxigov Este repositório contém os cadernos Jupyter usados no projeto de análise de dados do Taxigov. Conjunto de dados O conjunto

Augusto Herrmann 1 Jan 10, 2022
Tiktok BOT 1 link Vidio otomatis : - Nambah view - Nambah love - Nambah share - Nambah love komen (semua komen ke love)

Install Bahannya pip install selenium pip install pyfiglet==0.7.5 Cara Install dan Menjalankannya Git-clone this repo! Install selenium and pyfiglet u

Ahmad Ghozali 1 Mar 01, 2022
A combination between python-flask, that fetch and send data from league client during champion select thanks to LCU

A combination between python-flask, that fetch data and send from league client during champion select thanks to LCU and compare picked champs to the gamesDataBase that we need to collect using my ot

Anas Hamrouni 1 Jan 19, 2022
This wrapper now has async support, its basically the same except it uses asyncio

This is a python wrapper for my api api_url = "https://api.dhravya.me/" This wrapper now has async support, its basically the same except it uses asyn

Dhravya Shah 5 Mar 10, 2022
Discord Mafia Game Bot using nextcord

Mafia-Bot Discord Mafia Game Bot using nextcord Features Mafia Game Game Replays Installation Run the following command to install required modules: p

Nian 6 Nov 19, 2022