Categories
Dev

Deploying a virtual machine using AWS CloudFormation

Recently I started using Amazon AWS and quickly realized that provisioning virtual machines, security policies and other network configurations is done one by one, which is tedious and needs to be automated. I had two options: either create a custom script to provision every single service or learn how to use CloudFormation.

CloudFormation is a provisioning tool for AWS resources that requires a YAML/JSON formatted file inside which cloud infrastructure is described. This definitely seems like the better option, but being completely new to AWS the learning curve is steep and it is difficult to understand the terminology, the various components and how to combine them. Even the graphical user interface, the “CloudFormation Designer” is not that easy to use for new users.

Screenshot of the CloudFormation visual designer software. It allows to drag and drop components or modify JSON/YAML format.
Screenshot of CloudFormation Designer

What did I do? First I learned how to provision all the components manually one by one, which took more time than I would like to admit, but was essential for me to understand the components and which ones depend on another. Eventually manually provisioning resources became easier and all the different services became familiar, that allowed me to transition my set up to CloudFormation. It was a long process. Hopefully this article will allow others to use CloudFormation much sooner.

Categories
Dev

Git: How to replace the master branch

It happens to all of us, we accidentally commit something into a git repo that we didn’t mean to, even worse we also pushed it to the main repository on GitLab or GitHub.

TL;DR — too long; didn’t read

Replace the current “master” branch with another “backup” branch.

Local: git branch -f master backup

Remote: git push origin +backup:master

via: StackOverflow
Categories
Dev

How to quickly replace environment variables in a file

We know storing credentials or other sensitive values in a configuration file (e.g. Kubernetes yaml file) is bad, but how can we get values easily replaced without having to do a complicated string substitution or writing a custom Python script?

I often have personal environment variable files for projects that I use to store credentials and configurations in. Before working on a project I would the corresponding configuration file into the shell session. However, these files cannot be stored in git repositories or shared with coworkers or bots. Even worse, sometimes the repositories have files in them that need to be changed, which is dangerous, because it’s easy to accidentally commit these files.

Well as it turns out, there already is a good solution and it is called envsubst. We can use envsubst to substitute environment variable placeholders inside configuration files and we can even pipe it into other commands like Kubernetes’ kubectl.

envsubst < config.txt
Categories
Dev

Prefix CLI output

When interacting with the command line or writing automated scripts it’d be useful to prefix the output with the date or something equivalently useful. If you are a Linux or Terminal user you’ve probably come across the pipe symbol | , which for example allows you to apply grep filters, but it is not entirely clear how to prefix constant strings or dynamically evaluated commands like the date.