Best Practices for Developing and Deploying Cloud Infrastructure with the AWS CDK and Functional Web App (FWA) Architecture
Hatched by tfc
Sep 07, 2023
3 min read
8 views
Best Practices for Developing and Deploying Cloud Infrastructure with the AWS CDK and Functional Web App (FWA) Architecture
Introduction:
Developing and deploying cloud infrastructure requires careful consideration of best practices to ensure efficiency, scalability, and maintainability. In this article, we will explore the best practices for using the AWS Cloud Development Kit (AWS CDK) and the emerging architecture known as Functional Web App (FWA). By combining these two approaches, developers can create robust and reproducible cloud applications. Let's dive in!
-
Model with Constructs, Deploy with Stacks:
The AWS CDK introduces the concept of constructs, which are reusable and composable modules that encapsulate resources. When building your application's logical units, it is recommended to represent each unit as a construct rather than a stack. Stacks should be used to describe how your constructs are composed and connected for different deployment scenarios. This approach improves the reuse potential of your infrastructure and provides flexibility in deployment. -
Configure with Properties and Methods, Not Environment Variables:
Avoid using environment variable lookups within constructs and stacks. Instead, utilize a properties object to allow for full configurability entirely in code. Relying on environment variables introduces dependencies on specific machines, increasing the complexity of configuration management. Limit the use of environment variables to the top level of your AWS CDK app and for passing development environment information. -
Unit Test Your Infrastructure:
To ensure consistent and reliable infrastructure, implement a comprehensive suite of unit tests for your AWS CDK app. Avoid network lookups during synthesis and model all production stages in code. By doing so, you can trust the unit tests to confirm that the generated templates align with your expectations. This approach enables early detection of any issues and provides confidence in the stability of your infrastructure. -
Avoid Changing the Logical ID of Stateful Resources:
Changing the logical ID of a resource can result in the resource being replaced during the next deployment. For stateful resources like databases and S3 buckets, this can lead to unintended consequences. It is crucial to be cautious when refactoring your AWS CDK code to prevent changes in logical IDs. Write unit tests that assert the stability of logical IDs for stateful resources, ensuring consistency and avoiding unnecessary replacements. -
Complement Constructs with Security Features:
While constructs provide reusable and best-practice-based modules, they might not cover all compliance requirements. Many enterprise customers create their wrappers for L2 constructs to enforce additional security best practices. However, relying solely on these wrappers is not recommended. Instead, utilize AWS features such as service control policies and permission boundaries to enforce security guardrails at the organization level. Aspects and tools like CloudFormation Guard can be used to make assertions about the security properties of infrastructure elements before deployment. -
Embrace the Functional Web App (FWA) Architecture:
The FWA architecture offers an alternative solution to the complexity of traditional server-centric MVC applications on the cloud. By authoring a cloud app as single-responsibility cloud functions, developers can achieve high availability and reproducibility. FWAs utilize infrastructure as code to deploy the entire app deterministically, incorporating managed databases within the same network. This approach eliminates many delivery and maintenance headaches, providing a logical architecture that aligns with the physical architecture.
Conclusion:
Developing and deploying cloud infrastructure requires adherence to best practices to ensure efficiency, scalability, and maintainability. By incorporating the AWS CDK and embracing the Functional Web App architecture, developers can create robust and reproducible cloud applications. Remember to model with constructs, configure with properties and methods, unit test your infrastructure, avoid changing logical IDs of stateful resources, complement constructs with security features, and consider the FWA architecture. By following these actionable advice, you can enhance your cloud development process and achieve optimal results.
Sources
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 🐣