Architecting Functional Web Apps with JAMstack and AWS CDK

tfc

Hatched by tfc

Aug 18, 2023

4 min read

0

Architecting Functional Web Apps with JAMstack and AWS CDK

Introduction:
In today's digital landscape, the architecture of web applications plays a crucial role in their performance, scalability, and maintainability. Two popular architectural approaches that have gained traction are JAMstack and AWS CDK. While JAMstack focuses on simplifying the architecture by adopting a two-tier approach, AWS CDK enables seamless integration between AWS Chalice and CDK, providing resource mapping and cross-referencing capabilities. This article explores the benefits and challenges of these architectures and how they can be combined to create functional web apps with high availability and reproducibility.

Understanding Logical and Physical Architecture:
When discussing web application architecture, it's important to differentiate between logical architecture and physical architecture. Logical architecture refers to the structure of the system's source code, while physical architecture refers to the cloud infrastructure on which the source code runs. The distinction between authortime and runtime is key here. In traditional server-centric MVC applications on the cloud, the logical architecture runs on multiple physical web servers behind a load balancer and a CDN, communicating with one or more database servers. However, when the physical infrastructure definition lives separately from the code, the system's reproducibility and bug resolution suffer.

The Rise of JAMstack Architecture:
To address the complexity of three-tier architectures, some developers have turned to JAMstack, a modern version of the two-tier architecture. JAMstack leverages pre-rendered markup for the presentation layer and browser JavaScript for business logic, with APIs acting as the server. This approach simplifies the architecture and improves performance. However, JAMstack implementations often fall into the same trap as early MVC architectures on the cloud, relying on third-party API providers for dynamic functionality. This decentralization of infrastructure makes deployment and governance error-prone.

Introducing Functional Web App (FWA) Architecture:
An alternative solution to complex architectures is to move up the cloud vendor stack and adopt a Functional Web App (FWA) approach. In FWA, the entire application is authored as single-responsibility cloud functions, which can dynamically render HTML-first and incorporate the full-stack, including a managed database. The backend models the presentation and application logic using pure cloud functions that communicate with a managed database in the same network. Infrastructure as Code (IaC) is used to deterministically deploy the application, ensuring reproducibility. FWA eliminates the discrepancies between logical and physical architecture, simplifying delivery and maintenance.

Leveraging AWS CDK with Chalice:
When deploying applications with AWS CDK and Chalice, developers can leverage the Chalice construct from the chalice.cdk package in their CDK stack. This integration offers two significant benefits: resource mapping and cross-referencing. Resource mapping allows developers to generate AWS resources through CDK and seamlessly integrate them into the Chalice application via environment variable mapping. This simplifies resource management, such as databases or storage buckets. Cross-referencing enables the use of resources created within the Chalice app in other parts of the infrastructure managed through CDK, providing flexibility and scalability.

Example: DynamoDB Table Integration:
To illustrate the benefits of using AWS CDK with Chalice, let's consider an example where we want to create a DynamoDB table and integrate it into our Chalice application. Using the Chalice construct from the chalice.cdk package, we can generate the DynamoDB table within the self._create_ddb_table() method and map it into our Chalice application through a stage_config override. This mapping is achieved by merging the stage_config dictionary with the existing Chalice configuration located in ./.chalice/config.json. By updating the environment_variables dictionary in stage_config, we can pass additional values into our Chalice application.

Achieving High Availability and Reproducibility:
In addition to resource integration, AWS CDK with Chalice enables us to grant the IAM role associated with our Lambda function access to the DynamoDB table. This is achieved by using the grant_read_write_data method on the table resource and referencing the default role that Chalice creates using the self.chalice.get_role() method. By combining the benefits of JAMstack and FWA, we can architect web apps that achieve high availability with perfect 100% utilization while guaranteeing reproducibility through Infrastructure as Code.

Actionable Advice:

  1. Embrace the JAMstack architecture: Consider adopting a two-tier approach using pre-rendered markup, browser JavaScript, and APIs as the server. This simplifies the architecture and improves performance.
  2. Leverage AWS CDK with Chalice: Take advantage of the Chalice construct from the chalice.cdk package in your CDK stack to seamlessly integrate resources and cross-reference them with other parts of your infrastructure.
  3. Prioritize reproducibility with FWA: Move up the cloud vendor stack and adopt a Functional Web App approach to eliminate inconsistencies between logical and physical architecture. Use Infrastructure as Code to ensure reproducibility and simplify delivery and maintenance.

Conclusion:
Building and deploying web applications require careful consideration of the architecture to ensure performance, scalability, and maintainability. By combining the benefits of JAMstack and AWS CDK with Chalice, developers can simplify their architectures while achieving high availability and reproducibility. Embracing the two-tier JAMstack approach, leveraging the resource mapping and cross-referencing capabilities of AWS CDK with Chalice, and adopting FWA can lead to more efficient and reliable web apps.

Sources

← Back to Library

Hatch New Ideas with Glasp AI 🐣

Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)

Start Hatching 🐣