Skip to content

Instantly share code, notes, and snippets.

View epankur's full-sized avatar
🎯
Focusing

epankur

🎯
Focusing
View GitHub Profile
@epankur
epankur / gist:574665755c6c208309b65a159f5b6e05
Created January 17, 2024 19:07 — forked from rshettynj/gist:7731cc37d88446eda570d0669899549f
How to add new tags and remove unwanted tag from AWS ECR Image?
//Get the current manifest of the ECR image ecrimage-800
MANIFEST=$(aws ecr batch-get-image --repository-name ecrimage-800 --image-ids imageTag=latest --query 'images[].imageManifest' --output text)
echo $MANIFEST | jq '.'
//Push the tag called newtag along with image manifest.
aws ecr put-image --repository-name ecrimage-800 --image-tag newtag --image-manifest "$MANIFEST"
//Now ecrimage-800 will have two tags, "latest" and "newtag". You are ready to remove "latest" tag if you like.
aws ecr batch-delete-image --repository-name ecrimage-800 --image-ids imageTag=latest
@epankur
epankur / logger.ps1
Created December 18, 2022 11:37 — forked from barsv/logger.ps1
Logging in powershell with log rotation
# all logging settins are here on top
$logFile = "log-$(gc env:computername).log"
$logLevel = "DEBUG" # ("DEBUG","INFO","WARN","ERROR","FATAL")
$logSize = 1mb # 30kb
$logCount = 10
# end of settings
function Write-Log-Line ($line) {
Add-Content $logFile -Value $Line
Write-Host $Line
@epankur
epankur / ec2_info_retriever.py
Created December 14, 2022 13:58 — forked from dastergon/ec2_info_retriever.py
A basic boto3 based tool for retrieving information from running EC2 instances.
from collections import defaultdict
import boto3
"""
A tool for retrieving basic information from the running EC2 instances.
"""
# Connect to EC2
ec2 = boto3.resource('ec2')
@epankur
epankur / export.py
Created December 1, 2022 13:13 — forked from aldomatic/export.py
Export dynamodb data to csv, upload backup to S3 and delete items from table.
import csv
import boto3
from boto3.dynamodb.conditions import Key, Attr
from datetime import datetime
from pytz import timezone
import os
import json
# Here we assign our aws clients/resources to use
ses_client = boto3.client('ses')
@epankur
epankur / set-hostname-windows-ssm.yaml
Created October 31, 2022 19:55 — forked from sherzodinaev/set-hostname-windows-ssm.yaml
Set Windows hostname via SSM
---
schemaVersion: '2.2'
description: Sets computer name for computer(s) that is(are) part of the domain, using the value of Name tag for the selected resource(s).
mainSteps:
- action: aws:runPowerShellScript
name: setComputerNameFromTag
precondition:
StringEquals:
- platformType
- Windows
@epankur
epankur / tag-ebs.py
Created October 14, 2022 07:52 — forked from hermes-pimentel/tag-ebs.py
Copy tags from EC2 to EBS
# set variable AWS_PROFILE= to credentials
import boto3
# CHANGE REGION HERE-
ec2 = boto3.resource('ec2', 'sa-east-1')
#check your own tags before run this script
#loop for tag Name
def tag_name():
print "Loop for TAG Name"
for volume in ec2.volumes.all():
@epankur
epankur / EC2-Tag-Assets-Lambda.py
Created October 14, 2022 07:51 — forked from dictcp/EC2-Tag-Assets-Lambda.py
A lambda function that will copy EC2 tags to all related Volumes and Network Interfaces. A full writeup can be found on my site http://mlapida.com/thoughts/tagging-and-snapshotting-with-lambda
import boto3
def lambda_handler(event, context):
is_test = context.function_name == 'test' # this value is injected by SAM local
instances = boto3.resource('ec2').instances.all()
copyable_tag_keys = ["Team", "Billing", "BillingTag", "Env", "Project"]
for instance in instances:
copyable_tags = [t for t in instance.tags
@epankur
epankur / tag-vols-snaps.py
Created October 14, 2022 07:50 — forked from danpritts/tag-vols-snaps.py
Automatically tag EC2 snapshots and volumes based on their attached AMIs/instances
# most credit to the original: https://gist.github.com/brandond/6b4d22eaefbd66895f230f68f27ee586
# Tag snapshots based on their associated AMI and volumes based on attached instance.
# format:
# (AMI:db5|db5) /dev/sda1 (1/4)
# (AMI:db5|db5) /dev/sdb (2/4)
# Best practice: create IAM user
# Simplest privilege to get it to work with reasonable security: use predefined policy "ReadOnlyAccess"
@epankur
epankur / function.py
Created October 14, 2022 07:50 — forked from brandond/function.py
Python script to auto-tag AWS EBS Snapshots and Volumes using AMI and Instance tags
import copy
import logging
import os
import boto3
logging.basicConfig(level=os.environ.get('LOG_LEVEL', 'INFO'))
ec2 = boto3.client('ec2')
logger = logging.getLogger(__name__)
@epankur
epankur / send_pdf_with_boto_ses.py
Created September 9, 2022 09:00 — forked from jniva/send_pdf_with_boto_ses.py
send PDF attachment with boto and SES
''' quick example showing how to attach a pdf to multipart messages
and then send them from SES via boto
'''
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import boto