Skip to content

Instantly share code, notes, and snippets.

View thalesvon's full-sized avatar

Thales Sperling thalesvon

View GitHub Profile
@thalesvon
thalesvon / get-sts
Last active December 10, 2022 19:12
Shell script to get STS credentials.
#!/bin/bash
# Make sure you have IAM non-temporary keys that have permission to sts:AssumeRole configured on a 'permanent' profile in aws cli.
# To configure such profile you can use: $ aws configure --profile permanent
# To configure a MFA device on IAM, refer to: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_enable_virtual.html#enable-virt-mfa-for-iam-user
#
#
# More info about sts and assume role command available at: https://aws.amazon.com/premiumsupport/knowledge-center/iam-assume-role-cli/
#
# Add this bash script to your $PATH to run system wide
# Example: if script is located on /usr/local/bin/, make export PATH=/usr/local/bin:$PATH
@thalesvon
thalesvon / metrics.sh
Created December 23, 2019 15:58
Send custom metrics to CloudWatch with crontab. The service running count can be used to on ECS SERVICE autoscaling as a normaliser coefficient.
#!/bin/bash
# This script send relevant metrics for autoscaling for cloudwatch
# Make this script executable
# Install as crontab on machine that is 24/7 and has IAM Role with:
# ecs:DescribeServices
# cloudwatch:PutMetricData
#
# To install crontab: $ crontab -u ec2-user -e
#
# */1 * * * * PATH=/home/ec2-user/.local/bin /home/ec2-user/metrics.sh
service: ec2-instance-manager
custom:
secrets: ${file(secrets.json)}
provider:
name: aws
runtime: python3.7
stage: dev
stackName: ec2-instance-manager-stack
@thalesvon
thalesvon / mailbox-guid.ps1
Created March 16, 2019 21:43
Connect to Office365, good approach for scripts. Credentials are set by environment variables and available sessions are checked before creating new session.
$user = "$($env:service_user)"
$pass = "$($env:service_pass)"
$securepass = $pass | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PsCredential -ArgumentList $user,$securepass
If($Session -eq $null or $Session.State -eq 'Broken'){
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credential -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber
}