Automating Concert Ticket Alerts with AWS Lambda: Scrape Websites and Get Notified in Real-Time

Vinayak Pandey
2 min readSep 24, 2024

--

Recently I saw one post on my Facebook timeline (https://www.facebook.com/advaitawow/photos/get-ready-singapore-the-incredible-sunidhi-chauhan-is-coming-to-town-for-an-unfo/1046074227222005/) about Sunidhi Chauhan coming to Singapore on 23rd November 2024. Instead of checking for tickets availabily manually on a daily basis, I thought of automating the process.

Now as per the post, SISTIC is the official ticketing partner but I thought scraping SISTIC can be a bit challening so I focused on scraping the event venue site.

Step 1: Go to the URL https://www.thestar.sg/events/ and inspect the DOM elements. You see event details are listed under <h4 class=”entry-title summary”>

Step 2: Follow https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-create-dependencies to create a Lambda package with all the required dependencies. Use following command to install required packages

pip3 install --target ./package boto3 requests bs4
pip3 install --target ./package urllib3==1.26.6 --upgrade

Step 3: Create a Python lambda with 1 minute timeout. Use following Lambda code and upload the zipped package. You need to verify your Email address and Mobile number and then replace those values in the code.

import boto3
import re
import requests
from bs4 import BeautifulSoup

sns_client = boto3.client('sns')

def lambda_handler(event, context):
response = requests.get("https://www.thestar.sg/events/")
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
titles = soup.find_all('h4', class_='entry-title summary')
for title in titles:
a_tag = title.find('a') # Find the <a> tag inside <h4>
if a_tag and re.search('Sunidhi', a_tag.get_text(strip=True), re.IGNORECASE):
print(a_tag.get_text(strip=True))
sns_client.publish(TopicArn='<SNS_ARN>',Message='Sunidhi concert is listed on Star theatre website.Check SISTIC for ticket',Subject='Sunidhi concert is listed on Star theatre website')
sns_client.publish(PhoneNumber='<MOBILE_NUMBER>',Message='Sunidhi concert is listed on Star theatre website')

Step 4: Add “sns:Publish” permission to Lambda role and create an eventbridge rule to trigger this lambda every 10 minutes. That’s all we need to do for now and let’s wait for tickets to be available.

--

--

Vinayak Pandey
Vinayak Pandey

Written by Vinayak Pandey

Experienced Cloud Engineer with a knack of automation. Linkedin profile: https://www.linkedin.com/in/vinayakpandeyit/

No responses yet