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
23 changes: 6 additions & 17 deletions .github/workflows/build-lambda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,16 @@ jobs:
with:
role-to-assume: ${{ secrets.AWS_IAM_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Setup Python
uses: actions/setup-python@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
python-version: "3.13"
- name: Install UV
uses: astral-sh/setup-uv@v6
node-version: "22"
cache: "yarn"
- name: Build Lambda
run: |
cd scripts

# Create build directory
mkdir -p dist

# Install dependencies to build directory
uv pip install --target ./dist .

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

# Create deployment package
yarn install --frozen-lockfile
yarn build
cd dist
zip -r ../../lambda-function.zip .
cd ../..
Expand Down
4 changes: 2 additions & 2 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.venv
__pycache__/
node_modules/
dist/
1 change: 0 additions & 1 deletion scripts/.python-version

This file was deleted.

45 changes: 0 additions & 45 deletions scripts/lambda-handler.py

This file was deleted.

156 changes: 0 additions & 156 deletions scripts/main.py

This file was deleted.

24 changes: 24 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "pexels-image-fetcher",
"version": "1.0.0",
"description": "A TypeScript script to fetch the links of all featured photos on Pexels using Playwright",
"main": "dist/main.js",
"scripts": {
"build": "tsc",
"start": "tsc && node dist/main.js",
"dev": "ts-node src/main.ts"
},
"dependencies": {
"playwright": "^1.40.0"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.155",
"@types/node": "^20.0.0",
"ts-node": "^10.9.0",
"typescript": "^5.0.0"
},
"packageManager": "yarn@1.22.0",
"engines": {
"node": ">=16.0.0"
}
}
5 changes: 3 additions & 2 deletions scripts/prepare-image-links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ if [ -f "public/data/rolling-images.json" ]; then
exit 0
fi
cd scripts || exit
uv sync
uv run python main.py "../public/data/rolling-images.json"
yarn install
yarn build
node dist/main.js "../public/data/rolling-images.json"
11 changes: 0 additions & 11 deletions scripts/pyproject.toml

This file was deleted.

53 changes: 53 additions & 0 deletions scripts/src/lambda-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
APIGatewayProxyEvent,
APIGatewayProxyResult,
Context,
} from "aws-lambda";
import { getImageLinksPlaywright } from "./main";

/**
* Fetches the latest pexels featured image links using Playwright
*/
export async function lambdaHandler(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_event: APIGatewayProxyEvent,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_context: Context,
): Promise<APIGatewayProxyResult> {
try {
const pexelsUrl =
"https://www.pexels.com/@perry-z-1662054943/featured-uploads/";
const imageLinks = await getImageLinksPlaywright(pexelsUrl);

if (imageLinks && imageLinks.length > 0) {
return {
statusCode: 200,
body: JSON.stringify({
success: true,
image_links: imageLinks,
total_count: imageLinks.length,
}),
};
} else {
return {
statusCode: 200,
body: JSON.stringify({
success: false,
message: "No image links found",
image_links: [],
total_count: 0,
}),
};
}
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({
success: false,
error: error instanceof Error ? error.message : String(error),
image_links: [],
total_count: 0,
}),
};
}
}
Loading