Automate Everything

March 8, 2020

<< >>

I started creating my site using AWS Console as quite many of the services I am using were new to me. It is easy to start with console, but things get difficult when you want to move your application to another environment. I originally had only one environment but as I wanted to move the whole solution to CloudFormation, it became quite tricky to keep that environment running in “production” while moving the implementations to CloudFormation templates. I decided to fire up another “development” environment where I could develop my templates without bringing the actual site down. This was a good opportunity to learn about AWS Organizations also.

So I had empty environment where I started rebuilding the solution, but this time with CloudFormation templates. While using AWS Console, I hadn’t even noticed how complex my solution had become. There are no servers and only couple of lines of Node.js code in the Lambda functions, but there are over 1000 lines of CloudFormation YAML. Long templates are quite horrible to read, so I tried to split the templates based on services I am using.

Template Lines
codepipeline-low-cost.yaml 258
iam-roles.yaml 214
codepipeline-website.yaml 146
cloudfront-distribution.yaml 92
parameterstore-parameters.yaml 62
s3-codepipeline-artifact-store-bucket.yaml 54
template.yaml 49
s3-codepipeline-artifact-store-bucket-us-east-1.yaml 43
cloudwatch-alarm.yaml 25
codebuild-low-cost.yaml 15
codebuild-website.yaml 15
codecommit-repository.yaml 21
sns-topics-us-east-1.yaml 9
parameterstore-parameters-us-east-1.yaml 6
Total 1009

CodePipeline requires a lot of YAML compared to the actual web site content as I wanted to automate everything. Unfortunately I did not quite yet manage to do that though. My solution is based on CloudFront and even though this is a global service, it actually makes the solution quite heavily dependent on us-east-1 region in addition to eu-north-1 region where I want to run my site. I did not yet find a way of passing parameters for the CloudFormation stacks that would work between two regions. This makes the initial installation of solution much more complicated than I would like to have. It doesn’t take much more than 30 minutes, but does require that you manage to execute all the manual steps correctly.

If I find a way of passing parameters between stacks in different regions, I would be able to automate everything. My ultimate goal is to have this self updating pipeline that mimics the manual steps that are currently needed. Pipeline would initially be created with single CloudFormation stack and after stack is successfully created, pipeline will trigger itself and start updating itself. Getting the pipeline to status where it can deploy all the stacks and start automatically updating the web site most probably requires multiple incremental updates to the pipeline, but still it would require only one manual creation of a stack that would start a chain on events that ends with first version a Hugo based web site being live.

<< >>

comments powered by Disqus