Created
October 8, 2025 15:00
-
-
Save joselfonseca/1edc7b02b68afb3750b8e72302ffe782 to your computer and use it in GitHub Desktop.
DevOps Code for Eventim challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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