Skip to content

Instantly share code, notes, and snippets.

View gabrielferreira's full-sized avatar

Gabriel Ferreira gabrielferreira

View GitHub Profile

Connect Cross Account using AWS CLI

First you need to configure the access to the origin account

$ export AWS_ACCESS_KEY_ID="<AWS_ACCESS_KEY_ID>"
$ export AWS_SECRET_ACCESS_KEY="<AWS_SECRET_ACCESS_KEY>"

execute the command bellow to connect to the account

If you don't have a MFA configured

$ aws sts assume-role --role-arn arn:aws:iam::<ACCOUNT_ID>:role/<ROLE_NAME> --role-session-name "<SESSION_NAME>"
@gabrielferreira
gabrielferreira / delete-snapshot.py
Created March 22, 2016 20:28
Script to delete EBS Snapshots identified by Tags
import boto3
import re
import datetime
ec = boto3.client('ec2',region_name='us-east-1')
iam = boto3.client('iam')
def lambda_handler(event, context):
account_ids = list()
@gabrielferreira
gabrielferreira / ebs-snapshot-retention.py
Created March 22, 2016 20:21
Script to create EBS Snapshots from Instances identified by Tags with Retention
import boto3
import collections
import datetime
ec = boto3.client('ec2',region_name='us-east-1')
def lambda_handler(event, context):
reservations = ec.describe_instances(
Filters=[
{'Name': 'tag-key', 'Values': ['Identification']},
@gabrielferreira
gabrielferreira / ebs-snapshot.py
Created March 22, 2016 19:32
Script to create EBS Snapshots from Instances identified by Tags
import boto3
import collections
import datetime
ec = boto3.client('ec2',region_name='us-east-1')
def lambda_handler(event, context):
reservations = ec.describe_instances(
Filters=[
{'Name': 'tag-key', 'Values': ['Identification']},