Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Hooke kevinhooke

View GitHub Profile
@kevinhooke
kevinhooke / gist:9c84601f7e42a7d9666d35b76ac3e1f0
Created May 17, 2022
CloudWatch Insights query examples
View gist:9c84601f7e42a7d9666d35b76ac3e1f0
fields @timestamp, @message
| filter @message like /string pattern to match/
| sort @timestamp asc
fields @timestamp
| filter @message like /string pattern to match/
#parse line, match a pattern, capture pattern match in this case * as named value userId
| parse "\"userId\": \"*\"" as userId
#only include where this has a value
@kevinhooke
kevinhooke / gist:f2b59f5e3240f99852c806d3451728f7
Created Mar 1, 2022
aws cli list lambdas by name using query
View gist:f2b59f5e3240f99852c806d3451728f7
#list-functions is paginated by default so need to set page-size, no-paginate or simiilar to get complete list
# see https://docs.aws.amazon.com/cli/latest/reference/lambda/list-functions.html
# https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-pagination.html
aws lambda list-functions --region us-west-2
--query 'Functions[?starts_with(FunctionName, `name-pattern-here`) == `true`].FunctionName'
--page-size 300 >> output.txt
@kevinhooke
kevinhooke / gist:fe4bbcdfdb3080c56bd79637bb37f09f
Created Jan 20, 2022
AWS API Gateway 403 "MIssing authentication token"
View gist:fe4bbcdfdb3080c56bd79637bb37f09f
Calling an api that doesn't exist in your API Gateway will return a 403 with the rather misleading response:
{
"message": "Missing Authentication Token"
}
@kevinhooke
kevinhooke / gist:e4c80cdada0ca1cc866ce5948fe8de78
Created Oct 7, 2021
MacOS zsh prompt customization for displaying git branch
View gist:e4c80cdada0ca1cc866ce5948fe8de78
#zsh git prompt customizations
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF=$'\e[0m'
COLOR_USR=$'\e[38;5;243m'
COLOR_DIR=$'\e[38;5;197m'
COLOR_GIT=$'\e[38;5;39m'
NEWLINE=$'\n'
setopt PROMPT_SUBST
@kevinhooke
kevinhooke / gist:cb9244221334e30a0760f59c6b1dc099
Created Oct 6, 2021
AWS CloudFormation example for ECS Service
View gist:cb9244221334e30a0760f59c6b1dc099
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Example ECS Service",
"Parameters": {
"VPCSecurityGroupId": {
"Type": "String"
},
"VPCSubnetId": {
"Type": "String"
}
@kevinhooke
kevinhooke / gist:51c028c7e7f464bb678f77b62bb93768
Created Oct 6, 2021
AWS CloudFormation example for ECS TaskDef
View gist:51c028c7e7f464bb678f77b62bb93768
{
"Description": "Example ECS TaskDef",
"Parameters": {
"Param1": {
"Description": "Example param 1",
"Type": "String"
}
},
"Resources": {
"ECSTaskExampleExecutionRole": {
@kevinhooke
kevinhooke / gist:30ddf444e5fdbd24e283ab71e690f241
Created Oct 6, 2021
AWS CloudFormation template for ECS Cluster
View gist:30ddf444e5fdbd24e283ab71e690f241
{
"Description" : "Example ECS Cluster",
"Resources" : {
"ECSClusterExample1" : {
"Type" : "AWS::ECS::Cluster",
"Properties" : {
"ClusterName" : "ecs-cluster-example1"
}
}
}
@kevinhooke
kevinhooke / gist:28986702107be921974134e707b23baf
Created Sep 22, 2021
JavaScript sort array: strings vs integers
View gist:28986702107be921974134e707b23baf
let arrayOfStrings = [ "bbb", "ccc", "aaa"];
arrayOfStrings.sort(); //sorts as strings in alphabetical ascending order by default
//arrayOfStrings = ["aaa", "bbb", "ccc"]
let arrayOfInts = [3, 4, 1];
//function passed to sort() returns > 0 if b comes after a, or if < 0 then a comes before b
arrayOfInts.sort( (a,b) => a - b );
//arrayOfInts = [1, 3, 4];
@kevinhooke
kevinhooke / gist:20a26c9ea1de04c4dd9767245b86d41d
Created Sep 22, 2021
JavaScript flatten an array of arrays
View gist:20a26c9ea1de04c4dd9767245b86d41d
let arrays = [ [1,2], [2,3], [3,4] ];
let singleArray = [].concat.apply([], arrays);
//singleArray = [1, 2, 2, 3, 3, 4];
@kevinhooke
kevinhooke / gist:068302c33e029435f21b6af6f6da4439
Last active Sep 15, 2021
Filter aws cli resource lists for a specific single attribute value
View gist:068302c33e029435f21b6af6f6da4439
# Lambda ARNs
aws lambda list-functions | jq '.Functions[].FunctionArn'
# multiple properies: outputs on separate lines
aws lambda list-functions | jq -r '.Functions[] | .FunctionArn, .FunctionName'
# multiple properties as arrays
aws lambda list-functions | jq -r '.Functions[] | [.FunctionArn, .FunctionName]'
# multiple properties as arrays, converted to csv