Serverless Concert Ticket App Setup
Serverless Concert Ticket App Setup
The serverless architecture for the concert ticket sales web application includes several key components: AWS Lambda functions, API Gateway, DynamoDB, S3, SQS, and RDS. AWS Lambda handles backend operations without provisioning any servers, enabling cost efficiency. API Gateway provides entry points, ensuring secure communication between the frontend and backend through custom authorization . DynamoDB stores authorization tokens and device IDs, with autoscaling provisions to ensure performance . S3 acts as an object storage solution for storing payment proofs, which are shifted to Glacier after six months, ensuring cost efficiency of storage . SQS manages decoupling through two queues: one for handling orders from API Gateway and another for processing payment metadata, improving reliability by managing requests asynchronously . Finally, RDS stores relational data in a secure environment, only accessible through necessary Lambda functions, enhancing security . All services interconnect to prioritize security, performance, and cost-efficiency in alignment with project goals .
The security of the API Gateway must ensure it's only accessible by the frontend application. This can be achieved by configuring the API Gateway with custom authorizers, like 'lks-auth,' which uses a Lambda function to validate incoming requests using authorization headers . Additionally, CORS settings must be enabled to allow specific domains or all with careful consideration . For the RDS, security requirements dictate that the database should only be accessible via necessary Lambda functions, with public access strictly prohibited . IAM roles should be applied to regulate permissions rigorously. The database configuration should be stored securely using the SSM Parameter Store as SecureStrings, which helps manage sensitive information such as credentials . Overall, these measures protect against unauthorized data access and potential threats, aligning with the project's high-level security emphasis .
The WebSocket API in this application is used to manage asynchronous communication with the frontend, addressing the need for real-time, bidirectional communication. The WebSocket API includes six key routes: $connect, $disconnect, $default, sendMessage, getConnectionId, and broadcastMessage, with route selection based on $request.body.action . Each route is mapped to a Lambda function defined in 'websocket.js,' which handles the specific operations relevant to that route . For instance, $connect and $disconnect manage client connection lifecycles, while routes like sendMessage and broadcastMessage handle communication processes. This setup enables messages on SQS, once processed by the lambda consumer, to trigger responses back to the client, thus achieving real-time communication . Utilizing WebSocket API in this manner provides a seamless and efficient method for updating clients asynchronously without needing persistent HTTP requests, significantly enhancing user experience in dynamic applications like ticket sales .
To configure the RDS database for high availability, scalability, and security, several considerations are necessary. First, ensure the RDS runs on a highly available configuration like Multi-AZ deployment, which replicates the database across different availability zones . Scalability is achieved by configuring automatic storage growing, allowing the RDS to dynamically scale based on application demand. Security considerations include using IAM policies to restrict access rights only to necessary Lambda functions, ensuring no public access . For additional security, sensitive database configurations such as credentials must be stored and retrieved securely from the SSM Parameter Store using SecureString . These setups help meet performance demands while protecting against downtime and unauthorized access, aligning with key project goals of securing the backend infrastructure robustly. .
API endpoints in the API Gateway are configured with specific routes and method authorizations to ensure secure and seamless interactions with the serverless backend. REST API configuration includes endpoints such as '/token,' which uses AWS IAM authorization, while others like '/event' and '/ticket' use a custom authorizer 'lks-auth' that involves invoking a Lambda function to handle authentication through headers . Considerations include providing support for CORS, allowing HTTP methods such as GET, POST, PUT, and DELETE with CORS enabled for specified endpoints . The endpoints also involve integration with corresponding Lambda functions to execute specific application logic . The configuration must handle different types of requests, including base64 formatted file uploads, and implement specific production stage names and caching for optimizing performance . Such comprehensive endpoint configurations ensure high security and reliability while catering to varied client requests. .
The AWS SSM Parameter Store provides secure storage and management of configuration data required by the application, especially for database operations. It stores critical configuration such as database credentials and endpoints in a manner that supports high security operations. Specifically, it utilizes a set path /lks/database/{{KEY}}, where keys such as 'dbname,' 'username,' and 'password' (stored as SecureString) are defined . This setup ensures that configuration details remain secure and accessible to Lambda functions, which need to perform CRUD operations on the RDS database . By centralizing and securing sensitive configuration data, the SSM Parameter Store plays a crucial role in maintaining the security and manageability of the application's serverless architecture, facilitating seamless updates and access control .
In the project's architecture, S3 provides object storage specifically for handling payment transaction data. The bucket set up for this purpose includes a specific folder named "proofOfPayment" to store transaction evidence. Files in this folder that go unaccessed for six months automatically move to Glacier Deep Archive, optimizing storage costs while providing long-term storage solutions . Additionally, the S3 bucket sends an event notification to an SQS queue "lks-queue-payment" whenever new metadata is uploaded. This queue then triggers a Lambda function designed to process these incoming transactions, facilitating efficient and automated data handling workflows . Such integration between S3, SQS, and Lambda within the AWS ecosystem contributes to building a seamless, robust architecture capable of managing high transaction volumes effectively, enhancing both performance and operational cost efficiency .
Configuring a custom authorizer in the API Gateway involves several critical steps that ensure enhanced security for the application. First, the custom authorizer, such as 'lks-auth,' must be implemented through a Lambda function intended to validate incoming requests using specific headers, like the Authorization header and deviceid . The Lambda function required for this is typically written in JavaScript and must effectively parse and authenticate the token provided by users, potentially against standards like OAuth or JWT. Once configured, this authorizer works as a gatekeeper, permitting access only to requests that pass the authentication checks . Ensuring a robust custom authorizer is crucial because it provides an added layer of security that protects backend services from unauthorized access, reducing the risk of data breaches and ensuring that interactions are secure, which is of paramount importance in applications dealing with sensitive customer data .
The implementation of SQS enhances the application's architecture by facilitating a decoupled architecture that improves scalability and resilience. SQS queues are used to handle different operational tasks; "lks-queue-order" stores data from API Gateway when creating orders, ensuring that order requests are processed in sequence and with high throughput . This architecture effectively isolates failures and hiccups to specific segments without affecting the entire operation, thus enhancing overall reliability. "Lks-queue-payment" stores metadata received from S3 related to payment transactions, and processed sequentially by Lambda functions to manage these events, allowing for asynchronous and thus more flexible processing models . Additionally, dead letter queues are used to handle messages that cannot be processed successfully, preventing message loss and improving error handling . Through these mechanisms, SQS contributes to the robustness, performance, and cost-efficiency of the serverless solution .
The VPC for the concert ticket application should be created in the specified region with a CIDR block of 15.32.0.0/16. Two public subnets and four private subnets need to be established across two Availability Zones, each subnet having 200 IP addresses . Public subnets are typically for resources that need to be accessed over the internet, like the frontend application, while private subnets are for internal resources, such as databases, ensuring that they are not exposed directly to the internet, thus protecting sensitive data . Linking a private subnet to other AWS services should use the most cost-effective options available, such as interface endpoints, reducing data transfer costs and maintaining security .