Skip to content

jpatata/lambda-workshop

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 89.0%
  • Dockerfile 11.0%