Code Monkey home page Code Monkey logo

lambda-workshop's Introduction

AWS Lambda Workshop

Run a Python script that processes and exports data from external sources to a Google Sheet on AWS Lambda, deployed via AWS ECR.

Workshop prerequisites

  • Python installed on local machine
  • Poetry installed on local machine (e.g. via pip)
  • docker desktop installed on local machine
  • Google Cloud access to create service account
  • AWS access to push to ECR and create Lambda functions

Workshop Steps

  1. Initialize new package
mkdir lambda-workshop
poetry init
git init
  1. Create/copy lambda_function.py, modules/sheet.py, modules/finance.py and .gitginore

  2. Create Google Cloud project and service account, generate and download key as JSON file, add file to root folder as google_account.json

  3. Create Google Sheet, add edit permission for service account and update sheet ID in sheet.py

  4. Add dependencies via Poetry

poetry add yahooquery pandas google-api-python-client
  1. Test script locally
poetry run python -c "import lambda_function as lam; lam.lambda_handler()"
  1. Create/copy Dockerfile

  2. Create AWS ECR repository

  3. Create AWS Lambda function with "lambda-test" execution role and 5 minutes timeout

  4. Follow deployment steps below

App Readme

Setup

Create virtual environment and install dependencies with Poetry

poetry install

Run locally

poetry run python -c "import lambda_function as lam; lam.lambda_handler()"

Deployment (Docker)

  1. Authenticate with ECR (expects configured AWS CLI)
aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 880172922216.dkr.ecr.eu-west-1.amazonaws.com
  1. Build docker image
docker build -t lambda-workshop . --platform linux/amd64
  1. Tag image
docker tag lambda-workshop:latest 880172922216.dkr.ecr.eu-west-1.amazonaws.com/lambda-workshop:latest
  1. Push image
docker push 880172922216.dkr.ecr.eu-west-1.amazonaws.com/lambda-workshop:latest
  1. Update lambda function
aws lambda update-function-code --region eu-west-1 --function-name lambda-workshop --image-uri 880172922216.dkr.ecr.eu-west-1.amazonaws.com/lambda-workshop:latest
  1. Set lambda environment variables (from locally sourced environment)
aws lambda update-function-configuration --region eu-west-1 --function-name lambda-workshop --environment "Variables={SYMBOL=$SYMBOL}"
  1. (Optional) Schedule cron job to trigger function execution

lambda-workshop's People

Contributors

kinosal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.