Building which (Linux) command in Go

One of the best ways to learn a language is via building equivalent Linux commands using the language of your choice. which is my all-time favourite command to see if the binary is present on the server or not. You can see which usage as shown below, $ which kubectl-eks /Users/surajnarwade/.krew/bin/kubectl-eks We simply pass the binary name to which command and it will give us the absolute path to the binary. ...

September 9, 2023 路 2 min 路 Suraj Narwade

Encrypting text with AWS KMS

Encrypting and decrypting strings using AWS Key Management Service (KMS) and the AWS Command Line Interface (CLI) is a crucial part of securing sensitive data in your AWS environment. In this blog post, we鈥檒l walk through the process of encrypting and decrypting a string using KMS and the AWS CLI. This is a fundamental skill for protecting your data in AWS services like S3, RDS, and Lambda. Requirement You will need AWS CLI, You can follow this doc to install it, https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html You can follow this guide to create the KMS key, https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html Encrypting String Let鈥檚 create a simple plaintext string for encryption purposes. echo "Hello World" > hello.txt Let鈥檚 run the following command to encrypt our string. If you notice we are outputting it to encrypted.base64 because AWS CLI will encrypt it and then encode it into base64. aws kms encrypt --key-id <KMS_ID> \ --plaintext fileb://hello.txt \ --output text --query CiphertextBlob > encrypted.bas64 Now this string is safe to store as only the KMS key can decrypt this. ...

September 3, 2023 路 2 min 路 Suraj Narwade

Making a wise choice with ec2-instance-selector

AWS has more than 200 instance types under EC2. It鈥檚 very tricky to select appropriate ec2-instance types and surely AWS docs can be daunting. You can check the official doc here: https://aws.amazon.com/ec2/instance-types/ ec2-instance-selector is an open-source project by AWS. It is a CLI tool to helps you select compatible instance types. Check out the repo here, https://github.com/aws/amazon-ec2-instance-selector Features You can filter AWS Instance types using criteria like vcpu, memory, network performance, etc. You can use this project as a Go library to embed this functionality into your Golang projects, I will surely embed this in awsctl. Installing ec2-instance-selector On Mac brew tap aws/tap brew install ec2-instance-selector On Linux & Windows, you can download the binary from the release page. verify installation ec2-instance-selector --version v2.4.1 Usage Lookup all the instance type details interactively ec2-instance-selector -o interactive ...

September 2, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #6 - Mux

Up until now, we鈥檝e been using the DefaultServeMux, but it鈥檚 time to wield more control and precision by explicitly using the http.ServeMux. Plus, we鈥檒l look at the powerful frameworks available, like Gorilla Mux and Echo, that take web server functionality to new heights. Check out previous posts: Part 1: https://surajincloud.com/understanding-http-server-in-go-basic Part 2: https://surajincloud.com/understanding-http-server-in-go-using-httpserver-struct Part 3: https://surajincloud.com/understanding-http-server-in-go-handlers Part 4: https://surajincloud.com/understanding-http-server-in-go-multiple-handlers Part 5: https://surajincloud.com/understanding-http-server-in-go-handlefunc Why do we need this? While the DefaultServeMux In Golang does a great job of handling basic routing, there will come a point where you鈥檒l want more control over your application鈥檚 routes. This is where the http.ServeMux steps in. It empowers you to explicitly define how your application responds to different routes, giving you fine-grained control over your server鈥檚 behaviour. ...

September 1, 2023 路 3 min 路 Suraj Narwade

Understanding HTTP Server in Go #5 - HandleFunc

Welcome back to the fifth instalment of our in-depth exploration of creating dynamic web servers using Golang! In this post, we鈥檙e diving into the fascinating world of HandlerFunc. As you鈥檝e come to expect, GoLang provides us with an elegant and powerful way to handle requests through this mechanism. Let鈥檚 embark on this journey of discovery. Check out previous posts: Part 1: https://surajincloud.com/understanding-http-server-in-go-basic Part 2: https://surajincloud.com/understanding-http-server-in-go-using-httpserver-struct Part 3: https://surajincloud.com/understanding-http-server-in-go-handlers Part 4: https://surajincloud.com/understanding-http-server-in-go-multiple-handlers Let鈥檚 dive into the code to uncover the magic behind HandleFunc: ...

August 31, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #4 - multiple handlers

In the previous blog post, we made our webserver useful for the first time where we printed Hello World instead of 404. Check out previous blog posts: Part 1: https://surajincloud.com/understanding-http-server-in-go-basic Part 2: https://surajincloud.com/understanding-http-server-in-go-using-httpserver-struct Part 3: https://surajincloud.com/understanding-http-server-in-go-handlers It was still useless as it was printing the same response on all the paths. Now in real real-world scenario, we won鈥檛 have just one URL right, We will need multiple paths and handlers and we still don鈥檛 have mux so now in this case we can still have multiple handlers ...

August 31, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #3 - Handlers

Welcome to the exciting third instalment of our journey into creating web servers using Golang. In our previous articles, we covered the basics of creating a web server and explored the concept of custom servers using the http.Server struct. Check out the previous blog posts: \ Part 1:* https://surajincloud.com/understanding-http-server-in-go-basic \ part 2:* https://surajincloud.com/understanding-http-server-in-go-using-httpserver-struct However, as you might have noticed, our server was, until now, simply returning a 404 error. Fear not, because in this article, we鈥檙e about to breathe life into our server by diving into the realm of handlers. ...

August 30, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #2 - using http.Server struct

Welcome back to the second part of our exploration into building web servers using GoLang! In the previous blog post, we discussed creating a basic web server using the http.ListenAndServe function. However, this does not give us more control over the server config and to gain more control and flexibility over the server鈥檚 behaviour, you鈥檙e in for a treat. In this article, we鈥檒l delve into the world of custom servers by utilizing the http.Server struct. ...

August 29, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #1 - Basic

The net/http package in Go offers a powerful set of tools for constructing HTTP servers to handle incoming requests and send responses. In this article, we鈥檒l dive into setting up a basic HTTP server. Before we delve into the specifics, let鈥檚 familiarize ourselves with a couple of key terms: Multiplexer (or Mux): This is an essential component of an HTTP server that routes incoming requests to the appropriate handlers based on the requested paths or URLs. we will see this in detail in upcoming posts. With this foundation in mind, let鈥檚 explore how the net/http package simplifies the process of creating an HTTP server. ...

August 29, 2023 路 3 min 路 Suraj Narwade

Types of DNS records

While working with route53, I came across a couple of DNS records which were new to me. There are several types of DNS (Domain Name System) records, each with a specific purpose. Here are some of the most common types: A record (Address record) Maps a hostname to an IPv4 address. example.com IN A 192.0.2.1 AAAA record (IPv6 Address record) Maps a hostname to an IPv6 address. example.com IN AAAA 2001:db8::1 CNAME record (Canonical Name record) Maps an alias hostname to the true hostname (canonical name). ...

August 23, 2023 路 2 min 路 Suraj Narwade