Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/build-lambda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Build the lambda function zip file and push to S3
name: Publish to S3
on:
push:
branches:
- main
paths:
- scripts/**
jobs:
push-artifacts-to-s3:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_IAM_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.13"
- name: Build Lambda
run: |
# Create build directory
mkdir -p dist

# Install dependencies to build directory
uv sync --no-cache --target dist
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uv sync --target command expects a virtual environment, but this installs packages directly to the dist directory. Consider using uv pip install -r requirements.txt --target dist or create a virtual environment first.

Suggested change
uv sync --no-cache --target dist
uv pip install -r requirements.txt --target dist

Copilot uses AI. Check for mistakes.

# Copy Lambda function files to build directory
cp scripts/lambda-handler.py dist/
cp scripts/main.py dist/

# Create deployment package
cd dist
zip -r ../lambda-function.zip .
cd ..
- name: Deploy to S3
run: |
# Upload the Lambda function zip to S3
aws s3 cp lambda-function.zip s3://${{ secrets.AWS_S3_BUCKET }}/lambda/lambda-function.zip
2 changes: 1 addition & 1 deletion .github/workflows/push-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: yarn cibuild
- name: Deploy to S3
run: |
aws s3 sync ./dist s3://${{ secrets.AWS_S3_BUCKET }} --delete
aws s3 sync ./dist s3://${{ secrets.AWS_S3_BUCKET }}/website --delete
- name: Invalidate CloudFront cache
uses: foxdalas/cloudfront-invalidator@v4
with:
Expand Down
45 changes: 45 additions & 0 deletions scripts/lambda-handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
import os

sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from main import get_image_links_selenium

def lambda_handler(event, context):
"""
Fetches the latest pexels featured image links using Selenium
"""
try:
pexels_url = "https://www.pexels.com/@perry-z-1662054943/featured-uploads/"
image_links = get_image_links_selenium(pexels_url)

if image_links:
return {
'statusCode': 200,
'body': {
'success': True,
'image_links': image_links,
'total_count': len(image_links)
}
}
else:
return {
'statusCode': 200,
'body': {
'success': False,
'message': 'No image links found',
'image_links': [],
'total_count': 0
}
}

except Exception as e:
return {
'statusCode': 500,
'body': {
'success': False,
'error': str(e),
'image_links': [],
'total_count': 0
}
}