icer @ Neosperience a nd Neosperience He a lth, proud AWS Serverless Hero, p a ssion a te a bout softw a re a rchitectures, serverless, a nd m a chine le a rning. Serverless It a ly, [Gen]AI It a ly, a nd NextJS Meetup co-founder. ServerlessD a ys Mil a no a nd AWS Community D a y co-org a nizer. Big Daddy Little Elisa github.com/aletheia https://it.linkedin.com/in/lucabianchipavia https://speakerdeck.com/aletheia bianchiluca.com @bianchiluca
a se is d a t a b a se technology where the underlying d a t a b a se servers a nd IT infr a structure a re fully m a n a ged. • on-dem a nd con f igur a tion • custom endpoint a nd re a d replic a • sc a l a bility by design
automatically executed in response to certain database events (inserts, updates, or deletes) • Database, Authentication, and Scheduled triggers. • Real-Time Execution: eventually consistent immediate execution • Use Cases: task automating such as sending noti fi cations, updating related collections, logging changes, or initiating other work fl ows. Example When a new user document is inserted into the “users” collection, a trigger fi res and executes a function to send a welcome email or update a related “user_stats” collection.
Issue AWS Lambda creates new instances (cold starts) for each invocation, which can lead to overhead in creating new database connections for every request. Best Practice Reuse the MongoDB Atlas connection across Lambda invocations by creating the MongoDB client outside of the main Lambda function handler. This prevents opening a new connection every time the function is invoked, which helps reduce latency and overhead.
Practices 2 Issue Exposing your MongoDB Atlas cluster to the public internet could lead to security vulnerabilities. Best Practice Con fi gure VPC peering or Private Endpoints between your AWS Lambda’s VPC and MongoDB Atlas. This ensures that tra ff i c between Lambda and MongoDB is routed securely and privately, without traversing the public internet. • VPC Peering: Peers MongoDB Atlas with your AWS VPC. • Private Endpoint: Directly creates a private endpoint between MongoDB Atlas and AWS.
MongoDB credentials and con fi guration details inside your Lambda function can lead to security risks Best Practice Store MongoDB Atlas connection strings, database names, and other sensitive con fi guration details in AWS Lambda environment variables or AWS Secrets Manager to keep your Lambda code secure
add latency to your Lambda functions due to the initial overhead of creating new connections to MongoDB Atlas Best Practice Use Provisioned Concurrency to keep your Lambda functions warm, reducing the number of cold starts. This helps minimize latency and connection overhead. • Provisioned Concurrency pre-warms Lambda instances, ensuring they’re ready to handle requests instantly • Use Rust • Use LLRT
or temporary issues with MongoDB Atlas can lead to occasional timeouts Best Practice Set appropriate timeouts and use retry logic in your Lambda function to handle transient failures • Ensure MongoDB operations have a proper timeout to prevent Lambda executions from hanging • Implement retry logic, especially for reads and writes that can fail due to transient issues
it’s di ff i cult to understand performance bottlenecks or scaling issues Best Practice Use MongoDB Atlas Performance Advisor and AWS CloudWatch to monitor performance, identify slow queries, and get recommendations for improvements • Enable CloudWatch metrics for AWS Lambda to monitor invocation durations, errors, and resource utilization • Use MongoDB Atlas Performance Advisor to get insights into slow queries and recommendations on indexing
of preparing your environment to run the Atlas CDK by automating essential con fi gurations and resource provisioning • User Provisioning: creates a dedicated execution role • API Key Management: sets up an Amazon Secret Manager to securely store and manage API keys required for interacting with the Atlas services. • CloudFormation Extensions Activation: activation of CloudFormation public extensions essential for Atlas CDK.