Skip to content

Instantly share code, notes, and snippets.

@joselfonseca
Created October 8, 2025 15:00
Show Gist options
  • Select an option

  • Save joselfonseca/1edc7b02b68afb3750b8e72302ffe782 to your computer and use it in GitHub Desktop.

Select an option

Save joselfonseca/1edc7b02b68afb3750b8e72302ffe782 to your computer and use it in GitHub Desktop.
DevOps Code for Eventim challenge
// file: lambda/handler.ts
import { MongoClient } from "mongodb";
const MONGO_URI = process.env.MONGO_URI;
if (!MONGO_URI) {
throw new Error("MONGO_URI environment variable is not set");
}
let client: MongoClient;
export const handler = async (): Promise<void> => {
try {
if (!client) {
client = new MongoClient(MONGO_URI);
await client.connect();
}
const db = client.db("analytics");
const clicks = Math.floor(Math.random() * 100);
const doc = {
timestamp: new Date().toISOString(),
clicks,
};
await db.collection("clicks").insertOne(doc);
console.log(`Inserted document: ${JSON.stringify(doc)}`);
} catch (err) {
console.error("Error inserting document:", err);
throw err;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment