Skip to content

Instantly share code, notes, and snippets.

View okochang's full-sized avatar
🏠
Working from home

okochang okochang

🏠
Working from home
View GitHub Profile
@okochang
okochang / iam_policy_for_evaluate_vpc_flow_logs_enabled.json
Created January 26, 2016 15:39
Sample AWS IAM policy for evaluate_vpc_flow_logs_enabled_for_aws_config.py
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"config:PutEvaluations",
@okochang
okochang / evaluate_vpc_flow_logs_enabled_for_aws_config.py
Last active March 31, 2018 01:52
Sample rule for AWS Config Rules that evaluate vpc flow logs enabled or disabled
import boto3
import datetime
import json
config = boto3.client("config")
ec2 = boto3.client("ec2")
def evaluate_flowlog(vpc_id):
response = ec2.describe_flow_logs(
Filter=[
@okochang
okochang / exit_test.rb
Created March 7, 2014 02:53
指定された引数(hoge,foo,bar)によってexit終了ステータスが変わる
# -*- coding: utf-8 -*-
option = ARGV[0]
def exit_test(option)
if option == "hoge"
puts "正常終了でほげ"
exit 0
elsif option == "foo"
puts "異常終了でふー"
@okochang
okochang / introduction_sqs.rb
Created August 4, 2013 09:17
AWS SDK for Rubyを使ってSQSを操作する手順の紹介
# -*- coding: utf-8 -*-
require 'aws-sdk'
access_key = 'set your access key'
secret_key = 'set your secret key'
sqs_region = 'sqs.ap-northeast-1.amazonaws.com'
queue_name = 'okochang_que'
sqs = AWS::SQS.new(
:access_key => access_key,
:secret_key => secret_key,
@okochang
okochang / aws.yml
Created August 4, 2013 03:36
AWS SDK for Rubyで各サービスのリージョンを指定する方法一覧
# -*- coding: utf-8 -*-
## AWS SDK for Rubyで各サービスのリージョンを指定する方法一覧
AWS.config(
:access_key_id => 'set_your_access_key_id',
:secret_access_key => 'set_your_secret_key',
:auto_scaling_endpoint => 'autoscaling.ap-northeast-1.amazonaws.com',
:cloud_formation_endpoint => 'cloudformation.ap-northeast-1.amazonaws.com',
:cloud_front_endpoint => 'cloudfront.amazonaws.com',
@okochang
okochang / create_and_rotate_image_of_myself.rb
Created June 16, 2013 13:37
EC2インスタンスから実行して自分自身のAMI取得とAMIの世代管理をするスクリプト。 実行する場合はEC2インスタンスのタグを指定した上で実行する事。
# -*- coding: utf-8 -*-
require 'net/http'
require 'aws-sdk'
instance_id = Net::HTTP.get('169.254.169.254', '/latest/meta-data/instance-id')
ec2_region = 'ec2.' + Net::HTTP.get('169.254.169.254', '/latest/meta-data/placement/availability-zone').chop + '.amazonaws.com'
image_name = instance_id + '-' + Time.now.strftime("%Y%m%d%H%M")
comment = "automatically generated image"
@ec2 = AWS::EC2.new(
@okochang
okochang / introduction_support.rb
Last active December 18, 2015 10:59
AWS SDK for Rubyを使ったサポートアクセスする手順の紹介
# -*- coding: utf-8 -*-
require 'aws-sdk'
ACCESS_KEY = 'set your access key'
SECRET_KEY = 'set your secret key'
support = AWS::Support.new(
:access_key_id => ACCESS_KEY,
:secret_access_key => SECRET_KEY,
).client
@okochang
okochang / introduction_iam.rb
Created May 30, 2013 00:43
AWS SDK for Rubyを使ってIAMを操作する手順の紹介
# -*- coding: utf-8 -*-
## AWSのIAM用APIを使ってみたログであり、スクリプトではありません。
require 'aws-sdk'
ACCESS_KEY = 'set your access key'
SECRET_KEY = 'set your secret key'
alias_name = 'okochang'
user_name = 'yanase'
user_policy_name = 'admin_user_policy'
user_policy = '{"Statement":[{"Effect":"Deny","Action":["support:*"],"Resource":"*"},{"Effect":"Allow","Action":"*","Resource":"*"}]}'
group_name = 'administrator'
@okochang
okochang / introduction_vpc.rb
Created May 28, 2013 16:24
AWS SDK for Rubyを使ってVPCを作成する手順の紹介
# -*- coding: utf-8 -*-
## VPCを作成して削除するまでの流れを記載したもので、スクリプトではないので注意して下さい
require 'aws-sdk'
ACCESS_KEY = 'set your access key'
SECRET_KEY = 'set your secret key'
EC2_REGION = 'ec2.ap-southeast-1.amazonaws.com'
ec2 = AWS::EC2.new(
:access_key_id => ACCESS_KEY,
:secret_access_key => SECRET_KEY,
@okochang
okochang / rotate_copy_db_snapshot.rb
Created April 14, 2013 06:56
RDSで取得される自動バックアップからコピーを行い、世代管理を行うスクリプト。
# -*- coding: utf-8 -*-
require 'aws-sdk'
## 設定
access_key = 'set your access key'
secret_key = 'set your secret key'
rds_region = 'rds.ap-northeast-1.amazonaws.com'
rds_db_identifier = 'set your db identifier'
script_identifier = 'rotate-script'
copied_snapshot_name = rds_db_identifier + '-' + script_identifier + Time.now.strftime("%Y-%m-%d")