Skip to content

Instantly share code, notes, and snippets.

takakabe takakabe

Block or report user

Report or block takakabe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View delete_iroiro.py
import boto3, argparse
class iam():
def __init__(self):
self.session = boto3.Session(profile_name=args.profile)
self.iam = self.session.resource('iam')
def detach_all_policies(self): # iam_resource is group or role
policies = list(self.iam_resource.attached_policies.all())
for policy in policies:
View delete_group.py
import boto3
import argparse
parser = argparse.ArgumentParser(prog=__file__)
parser._action_groups.pop() # Edited this line
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
required.add_argument('--group-name',required=True,help='The name of the IAM group to delete.')
optional.add_argument('--profile',nargs='?',default='default',help='Use a specific profile from your credential file.')
View delete_group.py
import boto3
import argparse
parser = argparse.ArgumentParser(prog=__file__)
parser._action_groups.pop() # Edited this line
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
required.add_argument('--group-name',required=True,help='The name of the IAM group to delete.')
optional.add_argument('--profile',nargs='?',default='default',help='Use a specific profile from your credential file.')
View delete_role.py
import boto3
import argparse
parser = argparse.ArgumentParser(prog=__file__)
parser._action_groups.pop() # Edited this line
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
required.add_argument('--role-name',required=True,help='The name of the role to delete.')
optional.add_argument('--profile',nargs='?',default='default',help='Use a specific profile from your credential file.')
View kabegiwa_scraping.py
import requests
import lxml.html
html = requests.get('https://www.kabegiwablog.com').text
root = lxml.html.fromstring(html)
max_blog_post_count = 15
for i in range(1,max_blog_post_count):
blog_post = root.xpath('/html/body/div[3]/div/div[2]/div/div/div/div/div[1]/section['+str(i)+']/div[1]/h1/a')
print(blog_post[0].text+'\n'+blog_post[0].attrib['href']+'\n')
View scraping_whats_new.py
import re, requests, sys, io
from bs4 import BeautifulSoup
from datetime import datetime
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
def whats_new_current_month():
current_year = "{0:02d}".format(datetime.now().year)
current_month = "{0:02d}".format(datetime.now().month)
whats_new_url = 'aws.amazon.com/jp/about-aws/whats-new/'+current_year+'/'+current_month+'/'
View profile.py
import boto3
import argparse
parser = argparse.ArgumentParser(prog='profile.py')
parser.add_argument('--profile',nargs='?',default='default',help='Use a specific profile from your credential file.')
args = parser.parse_args()
profile = args.profile
session = boto3.Session(profile_name=profile)
@takakabe
takakabe / scraping.py
Last active Sep 18, 2019
BeautifulSoup
View scraping.py
import requests
from bs4 import BeautifulSoup
from datetime import datetime
current_year = datetime.now().year
current_month = datetime.now().month
url = 'https://aws.amazon.com/jp/about-aws/whats-new/'+"{0:02d}".format(current_year)+'/'+"{0:02d}".format(current_month)+'/'
request = requests.get(url)
soup = BeautifulSoup(request.text, 'lxml')
View assume_role_config.py
import boto3
session = boto3.Session(profile_name='wawawa_test_role')
sts = session.client('sts')
print(sts.get_caller_identity())
View assume_role.py
import boto3
sts = boto3.client('sts')
iam_role_arn = 'arn:aws:iam::123456789012:role/wawawa_role'
response = sts.assume_role(
RoleArn=iam_role_arn,
RoleSessionName='wawawa'
)
You can’t perform that action at this time.