Skip to content
Cyrus Pastelero
Case study

AWS Product Scraper: Serverless Data Pipeline

Cyrus David Pastelero1

1 Software engineer, Singapore; cyrus@pastelero.ph

Abstract

Learning AWS the hard way by building a production scraping system. Understanding Lambda cold starts, DynamoDB costs, and why infrastructure as code matters.

Keywords: AWS Lambda; DynamoDB; TypeScript

Cover for AWS Product Scraper: Serverless Data Pipeline

The problem

I needed to collect product data from multiple websites regularly. Running scrapers on my local machine wasn't sustainable. Leaving a server running 24/7 for jobs that run a few times a day seemed wasteful.

This seemed like a perfect use case for serverless. Pay only when the scraper runs, scale automatically when needed, and not worry about server maintenance.

What I built

A fully serverless scraping pipeline on AWS:

The pipeline: EventBridge triggers the scraper, SQS hands jobs to the processor, and clean data lands in DynamoDB.

Tech stack

LayerTechnologyWhy
ComputeAWS Lambda[1]Pay per execution, auto scaling
SchedulerEventBridge[2]Cron expressions, serverless
QueueSQS[3]Decoupled processing
DatabaseDynamoDB[4]Serverless NoSQL
StorageS3[5]Raw file storage
InfrastructureAWS CDK[6]TypeScript infra as code

What building this taught me

1. Cold starts are real and they hurt

My first Lambda functions took 3 to 5 seconds to start from cold. For scraping, that added up fast.

I learned to optimize bundle sizes, use provisioned concurrency[7] for critical paths, and accept that some latency is just part of serverless life.

// Before: v2, bundled with the function (3-5 second cold starts)
import * as AWS from 'aws-sdk' // Huge bundle
 
// After: <1 second cold starts
import { DynamoDB } from '@aws-sdk/client-dynamodb' // Tree-shakeable

Resources:

2. DynamoDB pricing is tricky

I assumed "pay per request" meant cheap. Then I saw my first bill.

Scan operations[11] are expensive. Provisioned capacity vs on demand changes costs dramatically. I rewrote queries multiple times to reduce costs.

DynamoDB cost for one million reads a month, by capacity mode, at 2024 prices.

On-demand reads cost $0.25 per million when I wrote this, and $0.125 since AWS halved on-demand prices in November 2024[12].

The lesson: design your access patterns first, then design your table. Not the other way around.

Resources:

3. Infrastructure as code saves your future self

I started clicking around the AWS console. It worked until I needed to replicate the setup for staging.

CDK[6] seemed like overkill initially, but having version controlled infrastructure made everything reproducible and debuggable.

// Define entire scraping infrastructure in TypeScript
const scraperFunction = new lambda.Function(this, 'Scraper', {
  runtime: lambda.Runtime.NODEJS_18_X, // Current in 2024; Lambda deprecated Node 18 on 1 September 2025
  handler: 'scraper.handler',
  code: lambda.Code.fromAsset('lambda'),
  timeout: Duration.minutes(5),
  memorySize: 1024,
})
 
// Schedule runs every 6 hours
new events.Rule(this, 'ScraperSchedule', {
  schedule: events.Schedule.rate(Duration.hours(6)),
  targets: [new targets.LambdaFunction(scraperFunction)],
})

Resources:

4. Scrapers break constantly

Websites change their HTML structure without warning. I built monitoring and alerting so I know when scrapers fail, and I designed the system to gracefully handle partial failures without losing data.

// Graceful error handling with partial success
async function scrapeProducts(urls: string[]) {
  const results = await Promise.allSettled(urls.map(url => scrapeOne(url)))
 
  const successful = results.filter(r => r.status === 'fulfilled')
  const failed = results.filter(r => r.status === 'rejected')
 
  // Log failures but don't lose successful scrapes
  if (failed.length > 0) {
    await alertSlack(`${failed.length}/${urls.length} scrapes failed`)
  }
 
  return successful.map(r => r.value)
}

Resources:

5. Memory equals speed equals cost

Lambda pricing ties memory and CPU together. Sometimes allocating more memory actually costs less because the function runs faster.

Lambda memory against duration: more memory, shorter runs.

Sweet spot: 1024 MB costs about 20% more per run (1.5 against 1.25 GB-seconds[20]) but runs about 6.7x faster than 128 MB.

I experimented to find the sweet spot for each function.

Resources:

Polite scraping

I built in rate limiting, request delays, and respect for robots.txt. Partly that is the ethical thing to do, and partly it is self-preservation: aggressive scraping gets your IP banned fast.

const rateLimiter = new Bottleneck({
  minTime: 2000, // 2 second delay between requests
  maxConcurrent: 1, // One request at a time
})
 
// Respect robots.txt
const robotsParser = await fetchRobotsTxt(domain)
if (!robotsParser.isAllowed(url)) {
  console.log(`Skipping ${url} - blocked by robots.txt`)
  return null
}

The bigger realization

Building this scraper taught me that serverless is a different way of thinking about architecture, more than "functions in the cloud." You design around events, embrace eventual consistency, and accept that distributed systems have distributed problems.

What I would do differently

Start with Step Functions[22] for orchestration. I cobbled together Lambda triggers and SQS queues manually. Step Functions would have given me better visibility into the pipeline and easier error handling.

  • Source: private

References

  1. Lambda. aws.amazon.com. https://aws.amazon.com/lambda/ ↑
  2. EventBridge. aws.amazon.com. https://aws.amazon.com/eventbridge/ ↑
  3. SQS. aws.amazon.com. https://aws.amazon.com/sqs/ ↑
  4. DynamoDB. aws.amazon.com. https://aws.amazon.com/dynamodb/ ↑
  5. S3. aws.amazon.com. https://aws.amazon.com/s3/ ↑
  6. AWS CDK. aws.amazon.com. https://aws.amazon.com/cdk/ ↑
  7. provisioned concurrency. docs.aws.amazon.com. https://docs.aws.amazon.com/lambda/latest/dg/provisioned-concurrency.html ↑
  8. Lambda Cold Start Optimization. aws.amazon.com. https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/ ↑
  9. AWS SDK v3 (Modular). docs.aws.amazon.com. https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/ ↑
  10. Lambda's Node.js runtimes include only SDK v3. docs.aws.amazon.com. https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html ↑
  11. Scan operations. docs.aws.amazon.com. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html ↑
  12. $0.125 since AWS halved on-demand prices in November 2024. aws.amazon.com. https://aws.amazon.com/about-aws/whats-new/2024/11/amazon-dynamo-db-reduces-prices-on-demand-throughput-global-tables/ ↑
  13. DynamoDB Pricing. aws.amazon.com. https://aws.amazon.com/dynamodb/pricing/ ↑
  14. Single Table Design. alexdebrie.com. https://www.alexdebrie.com/posts/dynamodb-single-table/ ↑
  15. AWS CDK Documentation. docs.aws.amazon.com. https://docs.aws.amazon.com/cdk/v2/guide/home.html ↑
  16. CDK Patterns. cdkpatterns.com. https://cdkpatterns.com/ ↑
  17. Lambda runtime deprecation dates. docs.aws.amazon.com. https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html ↑
  18. CloudWatch Alarms. docs.aws.amazon.com. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html ↑
  19. Dead Letter Queues. docs.aws.amazon.com. https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html ↑
  20. GB-seconds. aws.amazon.com. https://aws.amazon.com/lambda/pricing/ ↑
  21. Lambda Power Tuning. github.com. https://github.com/alexcasalboni/aws-lambda-power-tuning ↑
  22. Step Functions. aws.amazon.com. https://aws.amazon.com/step-functions/ ↑
  23. AWS Lambda Documentation. docs.aws.amazon.com. https://docs.aws.amazon.com/lambda/
  24. DynamoDB Best Practices. docs.aws.amazon.com. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html
  25. Serverless Patterns. serverlessland.com. https://serverlessland.com/patterns
Version www.pastelero.ph/projects/aws-product-scraper

© 2026 Cyrus David Pastelero