Skip to content

Instantly share code, notes, and snippets.

@subudear
subudear / delete_all_leaving_specific_log_group.ps1
Last active November 21, 2022 12:59
Delete all log group leaving specific AWS cloudwatch log groups
# Replace the AWS cloudwatch log group name
$log_group_name_to_search = "/aws/lambda/"
# Replace the name of log group or groups which should NOT be DELETED
$log_group_name_not_to_delete = "/aws/lambda/DEV*"
# The below command gets all the log group name matching $log_group_name_to_search. Then display the output is passed script where
# if the log groupname matches $log_group_name_not_to_delete then it is not deleted otherwise deleted.
aws logs describe-log-groups --log-group-name-prefix $log_group_name_to_search --query logGroups --output json | ConvertFrom-json |
@subudear
subudear / Show_log_groups_output_different_format.ps1
Created October 2, 2018 04:20
Show all AWS Cloudwatch log groups in json, text or table format
# Replace the AWS cloudwatch log group name
$log_group_name_to_search = "/aws/lambda/s"
#the below command shows all the log groups in TEXT format output
aws logs describe-log-groups --log-group-name-prefix $log_group_name_to_search --query logGroups --output text
#the below command shows all the log groups in JSON format output
aws logs describe-log-groups --log-group-name-prefix $log_group_name_to_search --query logGroups --output json
#the below command shows all the log groups in TABLE format output
@subudear
subudear / delete_log_stream_in_log_group_based_on_date.ps1
Created October 4, 2018 02:56
delete log stream in log group (lambda function logs) based on date
# Using below command you can delete log streams based on the date. The logStreamName is appended with date. Using this date you can search the
# log streams which are not required any more. The below example searches all the log streams within a log group for year 2018. In the
# name prefix for log stream it searches for all streams starting with "2". Then based on $log_stream_name_not_to_delete value, it deletes
# all log stream except for the date defined in $log_stream_name_not_to_delete.
#set the log group name
$log_group_name = "/aws/lambda/getlocationbyid"
$log_stream_name_not_to_delete = "2018/10*"
aws logs describe-log-streams --log-group-name $log_group_name --log-stream-name-prefix "2" --query logStreams --output json | ConvertFrom-json |ForEach-Object {$_.logStreamName} | ForEach-Object {
@subudear
subudear / start.sh
Last active November 21, 2022 12:57
install vsts build agent on ubuntu (requires env.sh as well)
#!/bin/bash
set -e
. env.sh
#export VSO_AGENT_IGNORE=_,MAIL,OLDPWD,PATH,PWD,VSTS_AGENT,VSTS_ACCOUNT,VSTS_TOKEN_FILE,VSTS_TOKEN,VSTS_POOL,VSTS_WORK,VSO_AGENT_IGNORE
if [ ! -e $VSTS_HOME/.configure ]; then
touch $VSTS_HOME/.configure
fi
if [ ! -e $VSTS_HOME/.token ]; then
@subudear
subudear / env.sh
Created March 27, 2019 21:38
export the parameters for ubuntu vsts build agent
#!/bin/bash
#Provide VSTS account name NOT the FULL URL
export VSTS_ACCOUNT=abc-example-dev
#Provide the PAT value
export VSTS_TOKEN=izpcivnfdfgdgd7gawylkjllw255yvgmoe4qtc4fxqg2mtprx4oyutretjxdpcgp5nvq
#The build agent will be ubuntu hostname appended with word agent
export VSTS_AGENT='$(hostname)-agent'
#Provide the POOL name for agent
export VSTS_POOL="Self-Hosted Linux Agent"
#provide the path where the agent will install and run, home for the agent
@subudear
subudear / ubuntu-16.04-docker-17.12.0-ce with dotnetSDK 2.2
Last active November 21, 2022 12:57
Dockerfile to create image with vsts agent for dotnet SDK 2.2
FROM microsoft/vsts-agent:ubuntu-16.04-docker-17.12.0-ce
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN apt-get update
RUN apt-get install -y wget
RUN wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
@subudear
subudear / ubuntu_build_agent.sh
Last active November 21, 2022 12:56
Build agent file
#!/bin/bash
set -e
export DEBIAN_FRONTEND=noninteractive
echo $1, $2, $3, $4, $5, $6
if [ ! -e $6/.configure ]; then
touch $6/.configure
fi
if [ ! -e $6/.token ]; then
touch $6/.token
@subudear
subudear / Start_Stop_Azure_VM
Created May 14, 2019 07:47
Custom runbook to start/stop Azure VM
<#
.SYNOPSIS
Wrapper script for get all the VM's in all RG's or subscription level and then Start or Stop all valid required VMs in loop
.DESCRIPTION
This runbook is intended to start/stop VMs (ARM based VMs) that resides in a given list of Azure resource group(s).If the resource group list is empty, then the script gets all the VMs in the current subscription.
Upon completion of the runbook, an option to email results of the started VM can be sent via SendGrid account.
This runbook requires the Azure Automation Run-As (Service Principle) account, which must be added when creating the Azure Automation account.
.EXAMPLE
.\start_stop_VM.ps1 -Action "Value1" -WhatIf "False"
@subudear
subudear / Installvsts.ps1
Created May 22, 2019 02:02
VSTS install script
# Downloads the Visual Studio Team Services Build Agent and installs on the new machine
# and registers with the Visual Studio Team Services account and build agent pool
# Enable -Verbose option
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]$VSTSAccount,
[Parameter(Mandatory = $true)]$PersonalAccessToken,
[Parameter(Mandatory = $true)]$AgentName,
[Parameter(Mandatory = $true)]$PoolName,
# Downloads the Visual Studio Team Services Build Agent and installs on the new machine
# and registers with the Visual Studio Team Services account and build agent pool
# Enable -Verbose option
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]$VSTSAccount,
[Parameter(Mandatory=$true)]$PersonalAccessToken,
[Parameter(Mandatory=$true)]$AgentName,
[Parameter(Mandatory=$true)]$PoolName