Skip to content

Instantly share code, notes, and snippets.

View duttonw's full-sized avatar

William Dutton duttonw

  • Queensland Government
  • Brisbane, Australia
View GitHub Profile
@duttonw
duttonw / #embedSvg.js
Last active October 29, 2024 23:13
Embed Svg's for Handlebars (with build embed as well as dynamic on template compile) for us in (Vite or esbuild) build systems.
import Handlebars from "handlebars";
/**
* Embeds an SVG file into the template
*
* Do note: rendering when inside handlebars will not be relative to a imported template file.
*
* It has two modes, browser mode and node mode.
* When in browser mode, it will place a random id to be filled in when the file is successfully collected
*
@duttonw
duttonw / imdbv2.sh
Created September 5, 2024 22:49
Ability to set instances IMDS secret key access on servers which have software not ready for V2 security. (Tagged- Environment: PROD)
#!/bin/bash
# Default settings
IMDSV2_SETTING="required" # Change to "optional" if you want to revert back
DRYRUN=false
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--setting) IMDSV2_SETTING="$2"; shift ;;
@duttonw
duttonw / AwsParamStoreBatchLoadSecrets.sh
Created June 6, 2024 23:11
AWs Param Store batch lost secrets with helper function (with example)
#!/bin/bash
# Function to set or update a parameter in AWS Parameter Store
set_parameter() {
local PARAM_NAME=$1
local PARAM_VALUE=$2
local IS_SECRET=${3:-false} # Default false, set to true for secret (encrypted) parameters
# Determine the parameter type
if [ "$IS_SECRET" = true ]; then
@duttonw
duttonw / GetInternalNLBIp4List.cfn.yml
Created February 1, 2023 22:55
CFN Template for collecting private ip4 address of a ELBv2 (network)
#In this example we want to get the private ip4 address of a ELBv2 (network)
#Full stack located here: https://github.com/qld-gov-au/quickstart-atlassian-bitbucket/blob/d6ebe59b5ccdd204a7edc72ab6f0f89d575ac6f8/templates/quickstart-bitbucket-dc.template.yaml
#Network Load Balancer health checks, need internal ip to approve connectivity
InternalNLBIp4List:
DependsOn: NetworkLoadBalancerELB2
Type: Custom::InternalNLBIp4ListCollector
Version: 1.0
Properties:
@duttonw
duttonw / Hoxton.SR8 local testing outside aws exception log
Created October 7, 2020 05:21
Spring cloud param store Hoxton.SR6 to Hoxton.SR8 how to run locally
[INFO]
[INFO] --- spring-boot-maven-plugin:2.3.4.RELEASE:run (default-cli) @ sec-application ---
[WARNING] Fork mode disabled, devtools will be disabled
Fork mode disabled, devtools will be disabled
Spring Boot: 2.3.4.RELEASE
2020-10-07 15:19:26.759 INFO 27180 --- [ main] a.g.q.s.sample.SampleSpringEntry : The following profiles are active: default,testResources
2020-10-07 15:19:34.439 WARN 27180 --- [ main] c.a.a.p.i.BasicProfileConfigLoader : Your profile name includes a 'profile ' prefix. This is considered part of the profile name in the Java SDK, so you will need to include this prefix in your profile name when you reference this profile from your Java code.
2020-10-07 15:19:34.447 WARN 27180 --- [ main] i.InstanceMetadataServiceResourceFetcher : Fail to retrieve token
com.amazonaws.SdkClientException: Failed to connect to service endpoint:
@duttonw
duttonw / SsmParamUtil.java
Created May 29, 2019 00:32
SSM Parameter Store as properties for Lambda
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult;
import com.amazonaws.services.simplesystemsmanagement.model.Parameter;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@duttonw
duttonw / asgToRoute53Update.cfn.yml
Last active March 31, 2019 00:25
AutoScaling Group to update Route53 hostedZoneID by tag, asgUpdateRoute53.js is the un-minified code in the tamplte
---
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: AutoScaling Group to Route 53 record update
#ensure you have the Tag DomainMeta set which a value of <HostedZoneId>:<Domain> on the ASG i.e. DomainMeta: Z10MWC8V7JDDU1:www.mydomain.com
Parameters:
Service:
Type: String
Default: 'asgToRoute53'
Description: Service name for this product
@duttonw
duttonw / SmtpSecretsManagerWithRotation.yml
Created December 14, 2018 05:22
Cloudformation template for Secrets Manager rotating a user access key
---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
BuildVersion:
Description: Build number
Type: String
Environment:
Description: Environment
Type: String
@duttonw
duttonw / aws-key-rotation-lambda.py
Created December 14, 2018 05:15
lambda python module
import boto3
import json
import logging
import os
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
@duttonw
duttonw / key-rotation-lambda.yml
Created December 14, 2018 05:14
cloudformation template for lambda user access key rotation which secret manager will use
---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
BuildVersion:
Description: Build number
Type: String
Environment:
Description: Deploy Target
Type: String