How to attach instance profile on EC2 with AWS CLI

This is a quick note to remind me on how to attach or associate an instance profile (IAM role) to an EC2 instance using AWS CLI. There is a bonus section at the end to show how to replace one IAM role with another one directly. In this example, I already have a running EC2 instance i-0357ecc1111111111 running. I want to attach a new instance profile called SSMInstanceProfile to this instance. But as we all know, only one instance profile can be associated with an EC2 instance at one time. So, let’s check to see if our instance already has one attached: ...

March 5, 2024 · 3 min · 436 words · kenno

Transform SSL cert to inline format

We all know that the content of SSL CRT and KEY is a long string of characters broken by new line characters. If we want to use those SSL .crt and .key files with Kubernetes as a TLS secret, they required to be encoded as base64 and be in one-line. How to do this? Well, there are at least two ways. The first one is my favorite: $ base64 -w0 drone.example.com.crt LS0tLS1CRUdJTiBDRVJUSUXXX0FURS0tLS0tCk11SOQrekNDQXVPZ0F3SUJBZ0lVZW5BejFjb0ptakd4Q1dGVHRhOWVzeUM2WHZRd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2dZUXhDekFKQmdOVkJBWVRBa0ZWTVJnd0ZnWURWUVFJREE5T1pYY2dVMjkxZEdnZ1YyRnNaWE14RHpBTgpCZ05WQkFjTUJsTjVaRzVsZVRFUk1BOEdBMVVFQ2d3SVUyRnV0eUJKYm1NeEV6QVJCZ05WQkFNTUNsTmhibmtnClUyVjJaVzR4SWpBZ0Jna3Foa2lHOXcwQkNRRVdFMjV2Y21Wd2JIbEFjMkZ1TjJsdVl5NWpiMjB3SGhjTk1qTXcKTmpFNE1ETTFOVFV4V2hjTk1qVXdPVEl3TURNMU5UVXhXakNCalRFTE1Ba0dBMVVFQmhNQ1FWVXhHREFXQmdOVgpCQWdNRDA1bGR5QlRiM1Yw ... w0 : disable line wrapping Another way is to use the good old tr command: ...

February 27, 2024 · 1 min · 125 words · kenno

Set Alacritty default dimensions TOML version

I have previously posted a similar topic on how to set the default dimension for Alacritty at launch. However, recently, Alacritty switched to TOML for its configuration. Here is the setting needs to be added to ~/.config/alacritty/alacritty.toml: [window.dimensions] columns = 133 lines = 40 Reference: https://blog.khmersite.net/p/set-alacritty-default-dimensions/

February 14, 2024 · 1 min · 46 words · kenno

How to restore a VM to its previous state XCP-ng

This evening while I was running the system update on one of the guest VMs running on my XCP-ng host, I accidentally rebooted the XCP-ng host. Why? Accident! The guest VM is very important, it’s running Xen Orchestra for this XCP-ng server. Semi-fortunately, I remember I had a snapshot for this VM. The challenge for me was, how could I restore the VM using that previous snapshot without Xen Orchestra. ...

January 4, 2024 · 2 min · 216 words · kenno

Using df command showing size in megabytes

Happy New Year 2024! This is going to be a very short post on how to use ‘df’ command to display the disk space usage in megabytes. To display the output in MB (megabytes), we can use the -m flag with the df command as the following: ❯ df -m Filesystem 1M-blocks Used Available Use% Mounted on devtmpfs 4 0 4 0% /dev tmpfs 852 0 852 0% /dev/shm tmpfs 341 6 336 2% /run /dev/mapper/almalinux-root 7578 2068 5511 28% / /dev/vda2 1014 280 735 28% /boot /dev/vda1 599 8 592 2% /boot/efi tmpfs 171 0 171 0% /run/user/1000 It’s simple, isn’t it?

January 1, 2024 · 1 min · 103 words · kenno