DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • AWS CDK: Infrastructure as Abstract Data Types, Part 3
  • AWS CDK: Infrastructure as Abstract Data Types, Part 2
  • AWS CDK: Infrastructure as Abstract Data Types
  • AWS CDK Deep Dive: Advanced Infrastructure as Code Techniques With TypeScript and Python

Trending

  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Simplifying Multi-LLM Integration With KubeMQ
  • Hyperparameter Tuning: An Overview and a Real-World Example
  • ACID vs BASE: Transaction Models Explained
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. AWS CDK Project Blueprint - Modeling and Organizing (Part 2/2)

AWS CDK Project Blueprint - Modeling and Organizing (Part 2/2)

The second part of how to model, structure, and organize your Infrastructure-as-Code AWS CDK Project. Building from scratch until a CI/CD pipeline composition, all the cloud component resources, and services at AWS Cloud.

By 
Ualter Junior user avatar
Ualter Junior
DZone Core CORE ·
Aug. 15, 22 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
5.5K Views

Join the DZone community and get the full member experience.

Join For Free

Welcome back! This is the second part of a two-part article series. With this article, my goal is to build a blueprint to show a way how to model, organize and structure our Infrastructure-as-Code Projects using the AWS-CDK framework. Check here to access the first part of this article.

Now, in this second part, as promised, comes the fun part, we get into the hands-on. Let's run our AWS CDK IaC Project, deploying all the services and resources, and then see the AngularJS Application up and running. Let's get started.

Before Start - Previous Steps

We are using the language Python for our AWS CDK Project, so before starting, we need to perform some previous steps, things like create and activate Python Virtual Environment, downloading the Project's AWS-CDK library dependencies, and also making sure you have already installed the AWS CDK Toolkit. AWS CDK Toolkit is installed using Node Package Manager (npm), for more info check here.

Here's them:

python

After (and if you) run ./scripts/run-checks.sh,  you see this error:

Shell
 
error: Library stubs not installed for "yaml" (or incompatible with Python 3.8)  [import]

To fix this, run the following command: 

Shell
 
python -m pip install types-PyYAML

Now, before going any further, in this same Terminal session, don't forget to open a valid AWS CLI Session for the AWS Account you want to deploy the solution.

The AWS CDK Project comes with a Makefile with several rules that try to help in some repeatable tasks/scripts, mainly those we usually forget, after a period of inactivity over the project. To check all of them, just run make with no parameters. Bear in mind that some of those rules/scripts may need Environment Variables set, like AWS Account and Region (check ./scripts/set-env-template.sh). Later on, we are going to use some of these Makefile rules in an attempt to make our life easier.

Let's try out, to be presented with a list of all Stacks in this CDK App, and choose one (or all of them) to synthesize (AWS CloudFormation template translation), execute this command:

Shell
 
make synth

console

Bootstrapping

Before deploying anything with AWS CDK, we need to prepare the environment (combination of an AWS account and region). For that, we have to provide the resources the AWS CDK needs to perform the deployments. Things like Amazon S3 Bucket for storing files, and IAM Roles that grant permissions to perform deployments. The process of provisioning these initial resources is called bootstrapping.

Using the command make check-bootstrap we can check the bootstrap status for all of our environments if they were or are not bootstrapped yet.

console

More on this, check here.

Deploying

Now, let's deploy the solution. Remember, the configuration YAML files we have seen in the first part of this article, have the AWS Account and AWS Region that are going to be used to deploy each distinct stage.

In the app.py we instantiate our IaC modeled application (defined at deployment.py) twice, each one for the two distinct stages (Dev and Pre prod), loading them with their respective specific configuration. We add both to the cdk.App, the root construct of an AWS CDK application.

python code

We can, of course, deploy each stage separately and isolated. For instance, deploy only the Dev stage (AwsSkillsMapping-DEV/Stateful and AwsSkillsMapping-DEV/Stateless). In the case of performing specific Stacks deployment, bear in mind the dependencies mentioned in the first part of this article. For that same reason, to deploy all the solution (all Stacks, including the Pipeline), let's use a Makefile rule/script called deploy-all. It will deploy them in the proper sequence, first and all together Dev/* and Preprod/*, and then, the Pipeline. Below, the sequence is shown before starting:

Shell
 
make deploy-all

console

Now would be a good time for some coffee...

After some time, in the middle of the Pipeline deployment, the e-mails configured in ./configuration/pipeline.yml (for sre-team and application-team) will receive a notification requesting them to confirm their subscription, like this:

AWS notification confirmation

We wait until...

command prompt

Checking the Results

When the deployment is finalized, we will find a file named deploy-outputs-dev-preprod.json, there we can find in the AwsSkillsMapping-DEV-Stateful, and in the AwsSkillsMapping-PREPROD-Stateful section, the S3 Website URLs. But before opening them in our navigator, we have to run our Pipeline once, at least (deploying the AngularJS in the S3 Bucket).

Notice! The Pipeline application, still during its deployment by AWS CDK, before everything is finished, will trigger a CodePipeline Release, that might fail with something like: "is not authorized to perform: codebuild:StartBuild on resource". It happens because the Pipeline deployment is still on course. After the Pipeline deployment has really finalized, you could, either in the CodePipeline hit the "Retry" button at the Build-DEV stage that failed, or simply start a new CodePipeline Release.

If we confirm the subscription mentioned before, we're going to receive a notification e-mail saying that de CodePipeline needs our approval. At this point, the Dev stage of our AngularJS application is already deployed, and the CodePipeline is stopped waiting for the Approvals to go ahead for Pre prod deployment.

AWS confirmation mail

AWS

There you are! After the CodePipeline release has finished successfully, we can open both S3 Website URLs. To visually and easily differentiate between the Dev and Pre prod, the AngularJS application has different toolbar colors for each one of them. Don't forget (to save some money), remember to clean all resources, you can use the command make destroy-all for that.

blog

What's Next?

As a next step "in the evolution", we could extract some of the Logical Units (e.g.  API) we have used in this AWS CDK Project and transform them into reusable components for other projects, i.e. create our own "generic" reusable Constructs. Then, we can compose our own library of AWS CDK Cloud Components (with some technical or business semantics embedded already), making our own common building blocks useful for all other IaC AWS CDK Projects. That way, for instance, a team could create a DynamoDB Table component that encapsulates the company's best practices and policies, already embedded (e.g. backup, monitoring, scaling, etc.). In the case of Python, handling those libraries with the Python Package Installer (pip, PyPI).

But this would be a story for another future article. :-) 

Conclusion (Part 2/2)

In the second part of this two-part article, we went through all the steps to deploy our IaC AWS CDK Application, as well the AngularJS Application sample using CodePipeline. We tested whether the implemented design model, structure, and organization fulfill our needs (at the moment), and help us to achieve our objectives in building IaC projects with the AWS CDK framework. And mostly, this project is intended to be a sandbox, a "living" blueprint model, that we are continuously analyzing, checking, thinking, and modifying, seeking improvements that make us do a better job.

The source code of this IaC AWS CDK Project and all of the artifacts used in this blueprint solution are available in the two Github repositories provided below:

AWS Skills Mapping IaC 


AWS CDK (programming library)

Published at DZone with permission of Ualter Junior, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • AWS CDK: Infrastructure as Abstract Data Types, Part 3
  • AWS CDK: Infrastructure as Abstract Data Types, Part 2
  • AWS CDK: Infrastructure as Abstract Data Types
  • AWS CDK Deep Dive: Advanced Infrastructure as Code Techniques With TypeScript and Python

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!