A serverless application that fetches and converts the New York Times front page to JPEG format using AWS SAM (Serverless Application Model).
This application uses:
- AWS Lambda (Python 3.9) - Fetches NYT front page PDF and converts to JPEG
- API Gateway - REST API endpoint for accessing the Lambda function
- Lambda Layer - Poppler library for PDF processing
- Custom Domain - nyt.lachlanteale.com
- AWS CLI configured with appropriate credentials
- AWS SAM CLI installed (Installation Guide)
- Python 3.9
- Docker (for building with --use-container)
pip install -r requirements.txt# Build locally
sam build
# Or build using Docker (recommended for consistent builds)
sam build --use-container# Start local API Gateway
sam local start-api
# Invoke function directly
sam local invoke MainFunctionsam validate --lintThe application automatically deploys to AWS when code is pushed to the master or main branch.
Required GitHub Secrets:
AWS_ROLE_ARN- ARN of IAM role for OIDC authentication (recommended)
OR
AWS_ACCESS_KEY_ID- AWS Access KeyAWS_SECRET_ACCESS_KEY- AWS Secret Key
# Deploy using default configuration
sam deploy
# Deploy with guided prompts (first time)
sam deploy --guided
# Deploy to production environment
npm run deploy:prodnpm run validate # Validate SAM template
npm run build # Build application locally
npm run build:container # Build using Docker
npm run deploy # Deploy to AWS
npm run deploy:prod # Deploy to production
npm run deploy:guided # Deploy with guided setup
npm run local:api # Start local API Gateway
npm run local:invoke # Invoke function locally
npm run logs # Tail Lambda logs
npm run delete # Delete CloudFormation stackProduction URL: https://nyt.lachlanteale.com/
Method: GET
Response: Base64-encoded JPEG image of the NYT front page
curl https://nyt.lachlanteale.com/ | base64 -d > nyt_frontpage.jpgDaily-NYT/
├── .github/
│ └── workflows/
│ └── deploy.yml # GitHub Actions workflow
├── layers/
│ └── poppler.zip # Poppler PDF library Lambda Layer
├── handler.py # Lambda function code
├── requirements.txt # Python dependencies
├── template.yaml # SAM template (CloudFormation)
├── samconfig.toml # SAM CLI configuration
└── package.json # NPM scripts and metadata
To use a custom domain, you need to:
- Have an ACM certificate in the same region as your API
- Configure the following parameters in
template.yaml:DomainCertificateArn- ARN of your ACM certificateHostedZoneId- Route53 Hosted Zone ID
Or update the template to remove the custom domain configuration.
Lambda environment variables can be configured in template.yaml under Globals.Function.Environment.Variables.
View Lambda logs:
# Tail logs in real-time
npm run logs
# View logs in AWS CloudWatch Console
aws logs tail /aws/lambda/daily-nyt-main --followThis project was migrated from Serverless Framework to AWS SAM. Key changes:
serverless.yml→template.yaml(SAM template)- Removed Serverless Framework plugins
- Added GitHub Actions for CI/CD
- Simplified deployment process
- Better CloudFormation integration
If you encounter build issues, try using Docker:
sam build --use-containerCheck CloudFormation stack events:
aws cloudformation describe-stack-events --stack-name daily-nyt-prodCheck Lambda logs:
npm run logsSee LICENSE.txt for details.
MrTeale