Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

View GitHub Profile
import boto3
ecs = boto3.client('ecs')
ssm = boto3.client('ssm')
cluster_name = “sample-cluster”
service_name = “sample-service”
# To stop the tasks
response = ecs.describe_services(
cluster=cluster_name,
@filipeandre
filipeandre / AWSFargate_SSM.yml
Created October 11, 2022 10:13 — forked from kavinarvind/AWSFargate_SSM.yml
AWS Fargate SSM Document
description: Triggers AWS Lambda Fargate Function
schemaVersion: '0.3'
parameters:
Region:
description: (Required) Name of the Region
type: String
default: us-east-1
Cluster:
description: (Required) Name of the ECS cluster
type: String
@filipeandre
filipeandre / check_tag_exists.py
Created August 5, 2022 12:47 — forked from nathanieltalbot/check_tag_exists.py
A simple Python function to check if an image tag exists in an ECR repo using boto3
# Checks if an image tag exists in the repo
def check_tag_exists(tag, repo):
ecr_client = boto3.client('ecr', region_name='us-east-1')
response = ecr_client.describe_images(repositoryName=repo, filter={'tagStatus': 'TAGGED'})
for i in response['imageDetails']:
if tag in i['imageTags']:
return True
return False
@filipeandre
filipeandre / crypto.go
Created June 22, 2022 08:13 — forked from miguelmota/crypto.go
Golang SHA256 hash example
package crypto
import (
"crypto/sha256"
)
// NewSHA256 ...
func NewSHA256(data []byte) []byte {
hash := sha256.Sum256(data)
return hash[:]
@filipeandre
filipeandre / KeepDbStopped.yml
Created November 26, 2021 15:44 — forked from kichik/KeepDbStopped.yml
CloudFormation template that stops RDS from automatically starting back up
# aws cloudformation deploy --template-file KeepDbStopped.yml --stack-name stop-db --capabilities CAPABILITY_IAM --parameter-overrides DB=arn:aws:rds:us-east-1:XXX:db:XXX
Description: Automatically stop RDS instance every time it turns on due to exceeding the maximum allowed time being stopped
Parameters:
DB:
Description: ARN of database that needs to be stopped
Type: String
AllowedPattern: arn:aws:rds:[a-z0-9\-]+:[0-9]+:db:[^:]*
MaxStartupTime:
Description: Maximum number of minutes to wait between database is automatically started and the time it's ready to be shut down. Extend this limit if your database takes a long time to boot up.
Type: Number
@filipeandre
filipeandre / copy_sm_secrets.py
Created May 6, 2021 11:13 — forked from sgtoj/copy_sm_secrets.py
Python script to copy AWS SecretsManager Secrets
#!/usr/bin/env python3
import os
import sys
import boto3
from botocore.exceptions import ClientError
# -------------------------------------------------------------------- main ---
Resources:
RateLimitACL:
Type: AWS::WAFv2::WebACL
Properties:
Name: rate-limit-acl
Scope: REGIONAL
Description: Auto-generated rate-limiting ACL.
DefaultAction:
Allow: {}
VisibilityConfig:
@filipeandre
filipeandre / mongodb-s3-backup.sh
Created March 23, 2020 09:39 — forked from eladnava/mongodb-s3-backup.sh
Automatically backup a MongoDB database to S3 using mongodump, tar, and awscli (Ubuntu 14.04 LTS)
#!/bin/sh
# Make sure to:
# 1) Name this file `backup.sh` and place it in /home/ubuntu
# 2) Run sudo apt-get install awscli to install the AWSCLI
# 3) Run aws configure (enter s3-authorized IAM user and specify region)
# 4) Fill in DB host + name
# 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket)
# 6) Run chmod +x backup.sh
# 7) Test it out via ./backup.sh
@filipeandre
filipeandre / create_and_attach_volume.yaml
Created March 19, 2020 00:45 — forked from ssummer3/create_and_attach_volume.yaml
AWS: Create and Attach a Volume to an EC2 Instance
AWSTemplateFormatVersion: '2010-09-09'
Description: Create a Volume from scratch and attach it to an instance.
Metadata:
AWS::CloudFormation::Interface:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Single node MongoDB deployment with a RAID10 storage configuration",
"Parameters" : {
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access",
"Type" : "String"
},