Search
×
press ESC to close

A quick fix to improve your debugging of remote commands in AWS is to install cw.

With a quick install, you can run a command like: cw tail -f --profile=qa --region=eu-west-1 ssm/custom-automation-docs/my-custom-doc. This will give you a real-time stream of what’s running.

You can also use the AWS Visual Studio Code extension, but I prefer having a terminal open streaming this as I don’t have to go in and refresh any further tools to see what’s happening. I tend to always start with a single instance/resource for debugging so this is a great way to remove the barrier to visibility a bit more.

tech development microblog cool-tools aws golang 

Checkout delta for a much-improved git diff experience. I typically use VSCode or a GUI based editor because I find the diff view pretty messy by default.

This new diff view is a perfect example of a simple CLI tool that improves a development workflow by just fixing something I didn’t know could easily be fixed. ๐Ÿ˜€

delta diff viewer

tech development microblog git cool-tools 

Day 10 of 100

progress

  • Experimented with CLI tool using go-prompt
  • Customized initial options
  • OS independent call to get user home directory.
  • Iterated through a directory listing
  • Used path join to initialize path for directory search.
  • One challenge in working with structs being returned was figuring out how to print the values of the struct. Initially, I only had pointers to the values coming back. This made sense, though, as I watched a tutorial this weekend on slices, and better understand that a slice is actually a small data structure being described by: pointer to the location in memory, length, and the capacity of the slice. Without this tutorial, I think seeing the pointer addresses coming through would have been pretty confusing.
  • In reading StackOverflow, I realized it’s a “slice of interfaces”.
  • Worked with apex logger and moved some of the log output to debug level logging.
  • Final result

source

tech development 100-days-of-code 100DaysOfCode golang 

Day 8 of 100

progress

  • Worked through Algorithms in Go: Determine if a number is in a list
  • Passed the tests without needing to find the solution, so that’s a win.
  • Had to remember to grab the second value from the range operator like for _, i := range items instead of using foreach($i in $items) like PowerShell would do. It’s more similar to using hashtables with GetEnumerator().
  • Used codespaces with Docker and also experimented with WSL2 and Visual Studio Code mounting the directory from inside WSL2.
tech development 100-days-of-code 100DaysOfCode golang 

Migrated a forked copy of a module over to a new module with similar schema. There were some additional properties that were removed. In rerunning the plan I was expecting to see some issues with resources being broken down and rebuilt. Instead, Terraform elegantly handled the module change.

I imagine this has to do with the resource name mapping being the same, but regardless it’s another great example of how agile Terraform can be.

tech development microblog terraform 

I use Dash for improved doc access. Terraform updated recently to 0.13.x and I began having odd issues with AWS provider results coming through. If you need to rollback, just go to the preferences and pick an older docset, in my case 0.13.0 worked correctly. Make sure to remove the problematic version (the uninstall refers to just the most recent, not any additional versions you selected under the dropdown)

If the index doesn’t rebuild, you can close the app, manually remove the index, and it will rebuild on open. I’m pretty sure you don’t need to do this if you use the uninstall option in the dialogue.

On macOS 10.15, you can find the index at ~/Library/Application Support/Dash/Data/manIndex.dsidx and delete this. Reopen Dash and it will rebuild the index.

tech development microblog aws terraform cool-tools 

What a polished setup experience from gitpod. Super impressed as I’ve never seen an interactive terraform setup asking for user input.

This basically generated an entire setup for GitPod, and persisted the Terraform plan for the entire stack it created in a directory for management and adjustments as desired.

I’m seriously impressed.

Check this out at: Install on AWS

# Setup Gitpod with self-setup docker installer
# https://www.gitpod.io/docs/self-hosted/latest/install/install-on-aws-script/
# Set-Location ./terraform/gitpod

Import-Module aws.tools.common, aws.tools.SecurityToken

Set-AWSCredential -ProfileName 'MyProfileName' -Scope Global

$ENV:AWS_ACCESS_KEY_ID = $cred.GetCredentials().AccessKey
$ENV:AWS_SECRET_ACCESS_KEY = $cred.GetCredentials().SecretKey
$ENV:AWS_DEFAULT_REGION = 'eu-west-1'

# can't use STS temporary credentials to create iam resources, so use normal iam credentials
docker run --rm -it -e AWS_ACCESS_KEY_ID=$ENV:AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$ENV:AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION=$ENV:AWS_DEFAULT_REGION `
-v ${PWD}/awsinstall:/workspace eu.gcr.io/gitpod-io/self-hosted/installer:latest aws
tech development microblog docker kubernetes terraform 

Day 5 of 100

progress

  • I created my first unit test for go
  • It’s a bit interesting coming from a background with PowerShell and Pester as my primary unit test framework. For instance, in Pester you’d declare the anything, but autodiscovery works with *.tests.ps1, being the normal convention.
  • There is no pointer value providing the test package, it’s just other PowerShell calling PowerShell.
  • I’m biased I know, but the first test condition being like below seems clunky. I was hoping for something that was more like Pester with test.Equals(got, want,"Error message") as the syntax is more inline to what I’d expect. I haven’t dived in further so this is just a thought, hoping this is just the newbie 101 test case example and there are more succinct comparison and test methods available.
package main

import "testing"

func TestHello(t *testing.T) {
	got := Hello()
	want := "Hello, world"
	if got != want {
		t.Errorf("got %q want %q", got, want)
	}
}

  • Update: Good article explaining the opinionated approach with testing and reasoning not to use assertions located at: Golang basics - Writing Units Tests. This is helpful to someone wanting to learn. I don’t want to force my prior paradigms on the language, because basically the whole reason I decided on Go over python or other language was wanting to learn something that helped me think in a fundamentally different way than using dotnet/Powershell. Python is very similar to PowerShell syntax wise for example, while Go is forcing me to look at things from a completely different view.
  • I’ll stick with the default package while I’m learning. However, there is a package called Testify that is worth exploring if I find I still want assertions later on.
tech development 100-days-of-code go 100DaysOfCode 

Day 4 of 100

progress

  • In the last week some more Pluralsight Go (Nigel’s courses are always stellar)
  • I’ve done some odd work as had time in between last update, but nothing structured. Might continue with learn-go-with-tests but also came across exercism and might tackle that soon as well.
  • Setup new project in Visual Studio Codespaces
  • Used Serverless Framework to generate aws-go template project
  • Imported aws-go-sdk resources for AWS SSM Secrets Manager
  • Grabbed SSM Secrets manager output and used to create a POST request for authorization token
  • Used DumpRequest to pretty print output for debugging purpose
  • Hung my head in shame at my copy pasta project ๐Ÿ˜€
  • Realized half of the battle is just getting my lambda debugging effort running locally. Not exactly the easiest starter project.
  • Need to master different request types. PowerShell makes this easy with Invoke-RestMethod and object construction. I found that the Post method wasn’t appropriate as I wanted to control custom headers. This required me to use a different approach, which I ended up doing with http.Client{}.
  • Not sure in a Go Playground sample to test and echo a post request. Thinking if no service that does this might try creating a Go routine to accept the request locally and echo for the purpose of a demo. Any suggestions welcome.
  • Identified i really need better understanding of the godoc libraries as would help a lot. Vscode intellisense even in codespaces isn’t performing great, so I’m not getting that help that would really expedite discovery as a beginner. I might give my EAP Goland install a try and see if it helps.
  • Successfully included zap logging library
  • Successfully submitted request for authorization token and got response back into a struct, something that as a newbie I found a major win ๐ŸŽ‰ using json.Unmarshal([]byte(body), ar) with ar referring to a pointer another win for me as new to pointers) being passed in like below:
// AuthResponse the authorization object returned by taco service when doing fancy things
type AuthResponse struct {
	MagicalToken string `json:"magical_token"`
	ExpiresIn    int    `json:"expires_in"`
}

func main() { 
	var ar AuthResponse
	getToken(&ar) // pointer for the win โšก๏ธ 
}
func getToken(ar *AuthResponse) {
	json.Unmarshal([]byte(body), ar) // โ“ using bytes for json is new to me. gotta learn more
	sugar.Infow("Logging library with zap used to generate structured logs",
	"authResponse", ar,  // trailing quotes is the norm, also a new pattern for me
)
}
tech development 100-days-of-code go 100DaysOfCode api 

Day 3 of 100

progress

  • Learned about GOROOT, GOPATH and how to configure
  • Ran into problems with Visual Studio code reporting:
Failed to find the "go" binary in either GOROOT() or PATH(/usr/bin:/bin:/usr/sbin:/sbin. Check PATH, or Install Go and reload the window.
  • After attempting solution with various profile files, I tried setting the setting: "go.goroot": "/usr/local/opt/go/libexec/", in settings.json and this resolved the issue.
  • After it recognized this, I ran the Go: Current GOPATH from the command palette and it found it.
  • Finally, after this it reporting back some feedback showing it was recognizing the latest version I was running.
  • Initialized a new serverless framework project for aws-go-mod template using the following command: serverless create --template aws-go-mod --path ./sqlserver and the initial project layout was created.
  • I’m sure this will need to be improved as I go along, but since macOS failed on the go path setup, this resolved my problems for now.

# GO: Make tools work in console sessions
$ENV:GOPATH = "$ENV:HOME$($ENV:USERPROFILE)/go"

if ($PSVersionTable.OS -match 'Darwin') {
    $ENV:GOROOT = "/usr/local/opt/go/libexec"
    $ENV:PATH += "$ENV:PATH:$(go env GOPATH)/bin"
    $ENV:GOBIN = "$(go env GOPATH)/bin"
}

tech development 100-days-of-code go 100DaysOfCode golang 

Sometimes, you just need a very simple flag for enabled or disabled, or perhaps just a resource to deploy if var.stage == "qa". This works well for a single resource as well as collections if you provide the splat syntax.


resource "aws_ssm_association" "something_i_need_in_testing_only" {
   count = var.stage == "qa" ? 1 : 0
   name = var.name
}
tech development microblog terraform 

It should be easy to pick a default program to open a file. On macOS, I was surprised at how poor the design was. Seriously, how is this intuitive? Open With > Set this as default. Apparently this only set it for an individual file. This means, every different csv file required me to do this again.

Instead, I had to Get Info > Unlock settings and then choose the default Open With setting, and further select Use this application to open all documents like this.

I enjoy most of my development experience with macOS.

Don’t try and tell me that it is the pinnacle of usability though, some of this stuff is just quirky and over complicated. In what world, should my default behavior be set on a specific file and not the the file type?

tech development macOS 

Day 1 of 100

progress

  • Cloned learning-go-with-tests to ensure a nice structured start, even though I’ve already done hello-world
  • Setup fresh gotools updates - Ran golangci-lint through docker to ensure improved linting options ready for further tests
  • Fixed default debug template in vscode to use workspacefolder instead of file directory. Strange that it defaulted to the wrong path.
tech development 100-days-of-code go 

PowerShell has some functionality that can help in pre-processing data by grouping and aggregating. If you are using ImportExcel this might be useful to pre-aggregate the results prior to an Excel workbook. If you are working with PowerShell and needing to do some quick measurement of objects, maybe this will be useful.

tech development powershell