This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Rotate AWS access keys for each profile in the users ${HOME}/.aws/credentials file. | |
Note: the default profile is not altered | |
Author: John Auld | |
''' | |
import configparser | |
import os | |
import boto3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# バケットにファイルを作成する | |
import boto | |
from boto.s3.connection import S3Connection | |
from boto.s3.key import Key | |
AWS_KEY_ID = 'aws_key_id' | |
AWS_SECRET_KEY = 'aws_secret_key' | |
BUCKET_NAME = 'bucket_name' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Cloudwatch Events ### | |
# Event rule: Runs at 8pm during working days | |
resource "aws_cloudwatch_event_rule" "start_instances_event_rule" { | |
name = "start_instances_event_rule" | |
description = "Starts stopped EC2 instances" | |
schedule_expression = "cron(0 8 ? * MON-FRI *)" | |
depends_on = ["aws_lambda_function.ec2_start_scheduler_lambda"] | |
} | |
# Runs at 8am during working days |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def handler(event, context): | |
return { | |
"statusCode": 200, | |
'headers': {'Content-Type': 'application/json'}, | |
"body": json.dumps('Hi!') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Step 1: Get a list of all alarms in INSUFFICIENT_DATA status | |
#Step 2: Get a list of all instances (stopped and started) | |
#Step 3: Find all alarms on instances that don't exist, and delete them | |
################################################### | |
#Step 1: Get alarms in INSUFFICENT_DATA state | |
################################################### | |
#The max that we can get per loop is 100; all alarms for nonexistent instances will be in | |
#INSUFFICIENT_DATA state so let's just go through those. | |
insuff_alarms = [] | |
loops = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from openpyxl import Workbook | |
from string import Template | |
ri_url = Template('https://a0.p.awsstatic.com/pricing/1.0/ec2/region/$region/reserved-instance/$os/index.json') | |
ebs_url = Template('https://a0.p.awsstatic.com/pricing/1.0/ec2/region/$region/ebs/index.json') | |
regions = ['us-east-1','us-east-2', 'us-west-1', 'us-west-2', 'ap-east-1', 'ap-south-1', 'ap-northeast-2', 'ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'ca-central-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'eu-north-1', 'sa-east-1', 'us-gov-east-1', 'us-gov-west-1'] | |
oses = ['linux', 'rhel', 'suse', 'windows', 'windows-std', 'windows-web', 'windows-enterprise'] | |
wb = Workbook() | |
dest_filename = 'AWS_Pricing.xlsx' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#in order to run the code above, install the python packages above: | |
#pip install ec2-metadata | |
#pip install boto3 | |
#!/usr/bin/python | |
import time | |
import boto3 | |
from ec2_metadata import ec2_metadata | |
#constants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
""" | |
S3 bucket CRUD operations core module | |
""" | |
import logging | |
import time | |
import boto3 | |
import botocore | |
from botocore.client import Config |