Skip to content

Instantly share code, notes, and snippets.

@HieronyM
HieronyM / docker-delete
Created September 29, 2020 09:39
Fancy docker command to clean up unused Image or container
#!/bin/bash
function delete_container_exited(){
docker rm -v $(docker ps -a -q -f status=exited)
}
function delete_container_all(){
docker rm -v $(docker ps -a -q)
}
@HieronyM
HieronyM / gist:a710d4c59044c797513403b8c0d7c65f
Created September 23, 2020 08:34
List s3 object that already moved to Glacier
aws s3api list-objects-v2 --bucket BUCKET_NAME --prefix folder1/folder2 --query "Contents[?StorageClass=='GLACIER']" --output text | awk '{print $2}' > glacier-objects.txt
@HieronyM
HieronyM / list-ec2instances
Created September 22, 2020 03:09
List ec2 instances information based on specific filter, and output them into .csv file
aws --profile sdsdevelmanager ec2 describe-instances --filters "Name=tag:Domain, Values=PRODUCTION-GOLD"\
--query 'Reservations[*].Instances[*].[ [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Domain`].Value] [0][0], InstanceId, PublicIpAddress, PrivateIpAddress, InstanceType, Placement.AvailabilityZone ]'\
--output text > instances.csv
@HieronyM
HieronyM / delete-existed-instance-profile
Created October 7, 2019 10:18
FIX ERROR – Terraform: Instance Profile already exists
aws --profile PROFILE_NAME iam list-instance-profiles // List all instance Profile
aws --profile PROFILE_NAME iam delete-instance-profile --instance-profile-name INSTANCE_PROFILE_NAME
@HieronyM
HieronyM / cwa_config.json.j2
Created May 8, 2019 07:56
Cloudwatch Agent configuration ansible template
{
"agent": {
"metrics_collection_interval": 15,
"logfile": "{{ aws_cwa_logfile_path }}"
},
"metrics": {
"namespace": "CWAgent2",
"metrics_collected": {
"cpu": {
@HieronyM
HieronyM / Cloudwatch-agent-metric.json
Last active May 7, 2019 08:25
Cloudwatch Agent configuration to push Metrics and logs to cloudwatch
{
"agent": {
"metrics_collection_interval": 15,
"logfile": "{{ aws_cwa_logfile_path }}"
},
"metrics": {
"namespace": "CWAgentNew",
"metrics_collected": {
"cpu": {
@HieronyM
HieronyM / aws-rds-describe-events-macOS
Created April 4, 2019 19:44
List all db-instance events for a given instance and for the last 14 days:
aws \
rds \
describe-events \
--source-identifier ab-postgres-01 \
--source-type db-instance \
--start-time $(date -u -v-13d -v-23H -v-59M -v-55S'+%FT%T') \
--end-time $(date -u '+%FT%T') \
--query 'Events[*].[Date,Message]' --output text
@HieronyM
HieronyM / aws-rds-describe-events
Last active April 5, 2019 19:08
List all db-instance events for a given instance and for the last 14 days:
aws \
rds \
describe-events \
--source-identifier db_identifier \
--source-type db-instance \
--start-time $(date -u -d "14 days ago + 5 seconds" '+%FT%T') \
--end-time $(date -u '+%FT%T') \
--query 'Events[*].[Date,Message]' --output text
@HieronyM
HieronyM / rds-postgres-specific-version.yml
Last active April 16, 2019 08:21
List Postgres RDS to be upgraded
policies:
- name: list_specific-postgres-rds
resource: rds
filters:
- type: value
key: "Engine"
op: equal
value: postgres
- type: value
key: "EngineVersion"
@HieronyM
HieronyM / cloud-custodian-rds-filter
Last active April 2, 2019 10:00
Cloud Custodian to Filter PendingModifiedValues
custodian report rds-postgres.yml -s . --field "DBInstanceIdentifier=DBInstanceIdentifier" --field "EngineVersion=EngineVersion" --field "MultiAZ=MultiAZ" --field "ProductDomain=tag:ProductDomain" --field "PendingUpdate=PendingModifiedValues" --field "AllocatedStorage=AllocatedStorage" --field "MaintenanceWindowTime=PreferredMaintenanceWindow" --no-default-fields > list_rds.xls