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
Collection of AWS Fault Injection Simulator (FIS) experiment templates.

Collection of AWS Fault Injection Simulator (FIS) experiment templates. These templates let you perform chaos engineering experiments on resources (applications, network, and infrastructure) in the A

Adrian Hornsby 8 Nov 27, 2022
An API wrapper for Discord written in Python.

disnake A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. About disnake All the contributors and develop

557 Jan 05, 2023
Opasium AI was specifically designed for the Opasium Games discord only. It is a bot that covers the basic functions of any other bot.

OpasiumAI Opasium AI was specifically designed for the Opasium Games discord only. It is a bot that covers the basic functions of any other bot. Insta

Dan 3 Oct 15, 2021
Simple integrate of API udemy.com with python

Pyudemy Simple integrate of API udemy.com with python Quick start $ pip install pyudemy or $ python setup.py install Authentication To make any calls

Hudson Brendon 30 Jan 02, 2023
A Simple Google Translate Bot By VndGroup ❤️ Made With Python

VndGroup Google Translator Heroku Deploy ❤️ Functions This Bot Can Translate 95 Languages We Can Set Custom Language Group Support Mandatory Vars [+]

Venuja Sadew 1 Oct 09, 2022
A discord.py code generator program. Compatible with both linux and windows.

Astro-Cord A discord.py code generator program. Compatible with both linux and windows. About This is a program made to make discord.py bot developmen

Astro Inc. 2 Dec 23, 2021
Senexia - A powerful telegram bot to manage your groups as effectively as possible

⚡ Kenechi bot ⚡ A Powerful, Smart And Simple Group Manager ... Written with AioG

Akhi 2 Jan 11, 2022
"zpool iostats" for humans; find the slow parts of your ZFS pool

Getting the gist of zfs statistics vpool-demo.mp4 The ZFS command "zpool iostat" provides a histogram listing of how often it takes to do things in pa

Chad 57 Oct 24, 2022
A program to convert YouTube channel registration information into Json files for ThirdTube.

ThirdTubeImporter A program to convert YouTube channel registration information into Json files for ThirdTube. Usage Japanese https://takeout.google.c

Hidegon 2 Dec 18, 2021
Wanna play on the Overwatch NA servers?

OverwatchRegionSwapper-NA- Wanna play on the Overwatch NA servers? Use at you own risk. LIST OF IPs EU Netherlands: From: 5.42.168.0 to: 5.42.175.255

1 Jun 08, 2022
Experimental bridges between Telegram calls and other platforms.

Bridges by Calls Music Experimental bridges between Telegram calls and other platforms. Current bridges Bridge 1 (YouTube, Twitch, Facebook, etc...) B

Calls Music 14 Oct 08, 2022
Powerful Url uploader bot With Mongodb support 🔥

Uploader X Bot Telegram RoBot to Upload Links. Features: 👉 Upload YouTube-dl Supported Links to Telegram. 👉 Upload HTTP/HTTPS as File/Video to Teleg

C͡linton Abraꫝam 250 Jan 06, 2023
Python Twitter API

Python Twitter Tools The Minimalist Twitter API for Python is a Python API for Twitter, everyone's favorite Web 2.0 Facebook-style status updater for

2.9k Dec 29, 2022
Get notifications in your Discord server of any software releases from Apple.

Apple Releases Get notifications in your Discord server of any software releases from Apple. Running To locally host your own instance, create a Disco

adam 17 Oct 22, 2022
Unofficial YooMoney API python library

API Yoomoney - unofficial python library This is an unofficial YooMoney API python library. Summary Introduction Features Installation Quick start Acc

Aleksey Korshuk 136 Dec 30, 2022
A repo containing toolings and software useful for a DevOps Engineer

DevOps-Tooling A repo containing toolings and software useful for a DevOps Engineer (or if you're setting up your Mac from the beginning) Currently se

Mohamed Abukar 45 Dec 12, 2022
Code for paper "Adversarial score matching and improved sampling for image generation"

Adversarial score matching and improved sampling for image generation This repo contains the official implementation for the ICLR 2021 paper Adversari

Alexia Jolicoeur-Martineau 114 Dec 11, 2022
A Rich renderable for viewing Multiple Sequence Alignments in the terminal.

rich-msa A simple module to render colorful Multiple Sequence Alignment with rich in the terminal. 🔧 Installing Install the rich-msa package directly

Martin Larralde 64 Dec 04, 2022
Passive income method via SerpClix. Uses a bot to accept clicks.

SerpClixBotSearcher This bot allows you to get passive income from SerpClix. Each click is usually $0.10 (sometimes $0.05 if offer isnt from the US).

Jason Mei 3 Sep 01, 2021