Skip to content

Instantly share code, notes, and snippets.

View magnetikonline's full-sized avatar
💡
I have an idea!

Peter Mescalchin magnetikonline

💡
I have an idea!
View GitHub Profile
@magnetikonline
magnetikonline / workflow.yaml
Last active April 27, 2021 23:50
Simple flow for passing artefacts between GitHub Actions workflow jobs.
name: Workflow
on:
push:
branches:
- main
jobs:
first:
runs-on: ubuntu-latest
@magnetikonline
magnetikonline / README.md
Last active February 16, 2025 22:44
Remove existing AWS CloudFormation stack, but retain all managed resources.

Delete CloudFormation stack - retaining resources

A guide for removing an existing CloudFormation stack - but retaining all managed resources.

First step - we need to get the CloudFormation stack into a state of DELETE_FAILED. This can be achieved by attempting stack delete with an IAM role that only has IAM action rights to cloudformation:DeleteStack and cloudformation:DescribeStackResources.

Create a new temporary IAM role with only the following allowed policy actions - for the rest of this guide that will be IAM role TEMP_CLOUDFORMATION_ROLE:

{
@magnetikonline
magnetikonline / README.md
Last active September 20, 2023 13:01
Remove AWS created network interfaces for VPC Lambda functions from given security group ID.

Remove AWS network interfaces from security group ID

Script has been handy to clean up security groups which have been used with VPC honed AWS Lambda functions and maintain an ENI association.

Why this is a problem:

  • Lambda function is created within the given VPC subnet(s) and assigned security group.
  • During deployment, AWS on your behalf creates ENIs assigned to the security group and placed into the instructed subnet(s).
  • Next, change is made to Lambda involving new security group association. AWS now creates new ENIs - as ENI reuse between Lambdas is only for the same security group/subnet combination.
  • Finally, user wishes to clean up legacy security group - but can't as existing ENIs still use security group.
@magnetikonline
magnetikonline / README.md
Last active December 16, 2024 03:16
List AWS Lambda@Edge log groups across regions.

List AWS Lambda@Edge log groups across regions

AWS Lambda@Edge functions, which run under CloudFront at multiple edge locations require associated Lambda functions to exist within each AWS region.

By design, this means CloudWatch Log groups produced by Lambda@Edge functions will exist across these regions.

This Bash script will query for all log groups associated to Lambda@Edge functions for each enabled region of the current AWS account to hopefully help determine where logs are going to and/or exist.

@magnetikonline
magnetikonline / README.md
Last active October 5, 2021 22:57
Delete AWS S3 bucket versioned objects and delete markers.

Delete S3 versioned objects and delete markers

Quick and dirty Bash script to iterate an S3 bucket and remove all object versions and delete markers.

Probably only usable on buckets with a few hundred version objects maximum, otherwise it might be more efficient and time effective to use a lifecycle rule to age out and remove objects in bulk.

Reference

@magnetikonline
magnetikonline / README.md
Last active May 12, 2023 21:59
macOS - Install The Silver Searcher (`ag`) from source.

Install The Silver Searcher (ag) on macOS from source

A quick n' dirty bash script to install the following:

  • automake, pkg-config, PCRE, xz - all needed by ag configure.
  • ag - from source.

Requires as a minimum Xcode CLI tools (don't need a full Xcode install). Can be done via the following:

$ xcode-select --install
@magnetikonline
magnetikonline / README.md
Last active November 28, 2020 04:06
Golang net/http middleware flow.

Golang net/http middleware flow

$ go run main.go
Called middleware03()
Called middleware02()
Called middleware01()
Called initial()
@magnetikonline
magnetikonline / README.md
Created November 24, 2020 00:32
Access Golang private modules within a GitHub organization.

Golang private modules within a GitHub organization

You've got Golang modules within a private repository or an organization and would like to go get them.

For this example the GitHub organization will be spacely-sprockets.

Howto

Set GOPRIVATE (ideally placed in your .bashrc / dotfiles):

@magnetikonline
magnetikonline / README.md
Last active December 10, 2023 10:54
Find latest non beta/RC release for Docker CLI

Find latest non beta/RC release for Docker CLI

Using curl and jq to:

  • Pull list of GitHub release tags.
  • Filter out all that don't match vX.Y.Z (stripping beta/rc).
  • Finally return just the first entry (latest tag).
$ curl --silent \
@magnetikonline
magnetikonline / README.md
Last active December 4, 2024 01:22
Creating a 'run once' systemd unit.

Creating a 'run once' systemd unit

Systemd unit template which calls a script exactly once upon startup and keeps unit status active after script finishes.

Unit file placed in /etc/systemd/system and enabled with:

$ sudo systemctl enable runonce.service
$ sudo systemctl start runonce.service