In the previous post, What Good Looks Like? Starting a Well Architected AWS Project , we discussed & solved "the Chicken & Egg bootstrapping a cloud application problem" by using AWS CodeStar to start & manage our cloud infra project, and in this post we will continue to build on that foundation.
In this chapter, we will review the anatomy of an AWS CodeStar project and all the plumbing that comes with it, including the structure & scaffolding of the included IaC - infrastructure as code and how it is connected to the tooling and actually executed within the 100% native AWS CI/CD code pipeline.
Reminder, that this article is part of a wider Series: The Anatomy of a Well Architected AWS project - please check that out as well if you haven't done so already, as we build upon knowledge & know-how accumulated in previous chapters .
In previous chapters, we selected AWS CodeStar as our provisioning tool, and we provisioned several example stacks, one of which we will review now here;
Now to start, please Open the example repo here: https://github.com/d-e-v-com/lambda-python
Project Resources:
Here is a visual architecture diagram of all the project resources that we have in our example blue print codestar project:
On the CodeStar project screen, click on the Overview tab and scroll down to Project Resources and you will see all AWS services and the corresponding arn's of the resource associated in the project.
Notice the resource types we have, and take a look at the description & explanation i added to each one:
Now the code...
Now let's look at the code in the repo that get's provisioned when the project is created / extracted;
Below is the README description of the files that come OOB, and what they do;
=========
What's Here
This sample includes:
README.md
buildspec.yml - this file is used by AWS CodeBuild to package your application for deployment to AWS Lambda
index.py - this file contains the sample Python code for the web service
template.yml - this file contains the AWS Serverless Application Model (AWS SAM) used by AWS CloudFormation to deploy your application to AWS Lambda and Amazon API Gateway.
tests/ - this directory contains unit tests for your application
template-configuration.json - this file contains the project ARN with placeholders used for tagging resources with the project ID
=========
That's great, but...
How is it all connected?
To answer this, let's take a look at it from an AWS CodePipeline perspective - remember CodePipeline is a core part of our CodeStar project and plays a critical role in connecting all the parts, so let's click on CodePipeline tab in the lambda-proxy codestar project and discuss the stages we see here and which files control which stage:
You can see how this is connected by clicking the [ Edit ] pipeline button there and drilling down into each stage and clicking on each stage's pencil / edit button to go all the way till you see the files referenced in each stage. Go for it!
And now here below is the annotated CodeBuild buildspec.yml so you can see the same files referenced from the previous CodePipeline / CloudFormation stage.
As you can see by drilling down into each pipeline stage & action section - each stage in the pipeline is connected to the different code repo files, components, and services within the CodeStar project and the ancillary AWS services and codestar gift wraps it all and puts it all together for us with just a couple of clicks!
WARNING!!! However it is important to understand & notice how the filenames are referenced & "hard coded" in the buildspec.yml and in the CodePipeline stages, meaning you cannot just rename the files in the repo without ensuring that you updated these references in code & config because you will break the build & pipeline! It can be done, just be careful, understand it, and modify accordingly.
Furthermore, we learn to modify, change & extend the build & pipeline in the following posts:
You can also click on each of the ancillary services within the CodeStar Project Resources, and find the related services sub-project. For example, navigate separately and independently to AWS CodePipeline, CodeBuild & CodeDeploy and you will find the related lambda-python project there under the respective service.
There is much more to dissect, however, if you made it thus far, you should have a good understanding of how things are connected, and this is a great spot to pat yourself on the back with a good job, be proud, you are on your way to building well architected stacks the right way!
=========
Summary:
In previous chapters, we explained some of the components that make Cloud Application Architecture Well Architected and in this chapter we dove deeper into AWS CodeStar and the additional ancillary services it wraps, such as CodeBuild, CodeDeploy, CloudFormation and IAM and we explained how things are connected and executed, from the files in the code base to how & where they are actually executed within AWS CodePipeline - in a 100% native CI/CD aws code pipeline way.
We discussed the;
* IaC project scaffolding, and the highlighted files;
* The Files, the project organization;
* Then the codestar project stack itself (the chicken) vs the infrastructure stack (the egg)
We dove another level deeper as we journey through The Anatomy of a Well Architected AWS project and we showed again, why The CodeStar approach is the way to go.
** NEXT RECOMMENDED ADVANCED TOPICS **
For further depth on CodePipeline, including tips & tricks on how to backup, modify and enhance the default pipeline, please visit Breaking Apart AWS CodePipeline and assembling enterprise pipelines
For further depth on CodeBuild and buildspec.yml file please visit this post Understanding The AWS CodeBuild buildspec.yml File
Comments