DougieWougie

Supporting the third sector with their technology challenges

A passion for solving problems

  • Setup a Multipass CDK Environment

    I want to be able to connect to the environment using Visual Studio Code, so first we need to create a SSH key:

    ssh-keygen -t rsa

    We need a configuration YAML, replace <generated ssh-rsa key> with the above key, saved as cloud-init.yaml:

    groups:
      - vscode
    runcmd:
      - adduser ubuntu vscode
    ssh_authorized_keys:
      - ssh-rsa <generated ssh-rsa key>

    Assuming you’ve got Multipass installed (if not sudo snap install multipass) then:

    multipass launch mantic --name ubuntu-cdk --cloud-init 

    We’ll come back to Visual Studio Code later but first lets set everything up in the VM. We need to install aws-cli which I want to use with SSO (hence why we installed Mantic).

    multipass shell ubuntu-cdk
    sudo apt install awscli
    aws configure sso

    Follow the prompts and sign in to AWS as usual. Then install CDK:

    sudo apt install nodejs npm
    sudo npm install -g aws-cdk

    Almost there, lets bootstrap1 (provisioning resources needed to make deployments) substituting the relevant values:

    cdk bootstrap aws://<account>/<region> --profile <profile>

    You should see a screen like this:

    Create a new CDK application by creating a new folder, changing into it and initialising CDK:

    cdk init app --language python
    source .venv/bin/activate
    python -m pip install -r requirements.txt

    And that’s about it, except for Visual Studio Code. You’ll need to install Microsoft’s Remote-SSH extension:

    You can get the IP address from multipass list, then in Code add a new SSH connection using ubuntu@<ip>:

    Accept the various options presented and you’re there!

    VSCode
    1. Bootstrapping provisions resources in your environment such as an Amazon Simple Storage Service (Amazon S3) bucket for storing files and AWS Identity and Access Management (IAM) roles that grant permissions needed to perform deployments. These resources get provisioned in an AWS CloudFormation stack, called the bootstrap stack. It is usually named CDKToolkit. Like any AWS CloudFormation stack, it will appear in the AWS CloudFormation console of your environment once it has been deployed. ↩︎

  • Rust

    Picked up a book, Programming Rust (2nd Edition) by Jim Blandy, and have been working through it over the holidays (non-stop party here).

    Published in late 2021, it’s surprising how much of the code doesn’t work and it isn’t encouraging to spend half an hour searching for solutions to an early worked example. Nothing in the book’s errata.

    So if you’re stuck with the early “serving pages to the web” example on page 15, it was caused by a breaking change in actix-web crate‘s chrono dependency. I ended up setting the version before the change.

    [package]
    name = "actix-gcd"
    version = "0.1.0"
    edition = "2021"
    
    # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    
    [dependencies]
    chrono = { version = "= 0.4.29" }
    actix-web = "1.0.8"
    serde = { version = "1.0", features = ["derive"] }

    Funnily the author wrote “One of Rust’s strengths is the collection of freely available library packages […]” and “[…] by naming the specific versions we tested this code against, we can ensure the code will continue to compile even as new versions of the packages are published.“. True, as long as every dependency behaves itself and it reminded me of this XKCD:

    XKCD

    Anyway it’s a great read and these things happen. There’s updated version of the completed exercise code on Github.


  • Resettling: Location

    Army Aviation can be very stable. With three major units in one location, many settle in Mid Suffolk. Indeed it gave my children enough stability that they settled there but I wanted to come back to Scotland.

    There were some practical reasons (better facilities, public transport, and less need to drive everywhere) and some personal (friends and family).

    Read More