Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
## More information about this process can be found at
## https://docs.aws.amazon.com/cloud9/latest/user-guide/move-environment.html#move-environment-resize
# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
@tomofuminijo
tomofuminijo / inclese-disk-size.sh
Last active January 4, 2022 06:47
Increase the disk size on Cloud9 instance
pip3 install --user --upgrade boto3
export instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
python -c "import boto3
import os
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2')
volume_info = ec2.describe_volumes(
Filters=[
{
'Name': 'attachment.instance-id',
@tomofuminijo
tomofuminijo / ulam_spiral.py
Last active April 9, 2021 08:31
Sample code to output Ulam spiral image in Python
from PIL import Image
from sympy import isprime
import math
def ulam_spiral(length: int, start_num: int = 1) -> list[list[int]]:
"""
ulam_spiral plots the spiral of Ulam on a square with a side length of
the inputed length.
The result is returned in the coordinates of a two-dimensional array.
@tomofuminijo
tomofuminijo / assume-role.sh
Created April 4, 2020 02:33
A sample script that executes GetSessionToken and then AssumeRole
#!/bin/bash -eu
# Auth アカウントのIAM ユーザ アクセスキーにより、get-session-token を実行して、MFA 認証済みの一時的認証情報を入手する
credentials=$(aws sts get-session-token \
--serial-number arn:aws:iam::<auth_account_id>:mfa/<iam_username> \
--token-code $1 \
--query "Credentials.[AccessKeyId, SecretAccessKey,SessionToken]" \
--output text)
# 一旦環境変数にMFA 認証済み一時的認証情報をセット
export AWS_ACCESS_KEY_ID=$(echo $credentials | cut -d ' ' -f 1)
@tomofuminijo
tomofuminijo / asyncproc.js
Created March 31, 2020 14:02
Samples to understand the asynchronous processing of JavaScript.
// JavaScript の非同期処理を理解するためのサンプル
const getThisYear = (callback) => {
setTimeout(() => callback(null, new Date().getFullYear()), 100);
}
const getNextYear = (year, callback) => {
setTimeout(() => callback(null, ++year), 100);
}
@tomofuminijo
tomofuminijo / restricted-instance type.json
Created March 10, 2020 01:43
Policy that restrict instance types
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPolicy",
"Effect": "Allow",
"Action": [
"ec2:*",
"autoscaling:*"
],
@tomofuminijo
tomofuminijo / guardduty-disabled-all-region.sh
Last active February 14, 2020 23:38
Sample script to delete a GuardDuty master and some members configuration in all regions
#!/bin/bash
OPERATION_REGION=us-east-1
ROLE_NAME=OrganizationAccountAccessRole
#Change your master account id
MASTAR_ACCOUNT_ID=<YOUR_MASTER_ACCOUNT_ID>
regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --region $OPERATION_REGION --output text)
function delete_detector () {
region=$1
@tomofuminijo
tomofuminijo / guardduty-enabled-all-region.sh
Last active February 14, 2020 23:38
Sample script to create a GuardDuty master and some members configuration in all regions
#!/bin/bash
OPERATION_REGION=us-east-1
ROLE_NAME=OrganizationAccountAccessRole
#Change your master account id
MASTAR_ACCOUNT_ID=<YOUR_MASTER_ACCOUNT_ID>
regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --region $OPERATION_REGION --output text)
function switch_role () {
account_id=$1
@tomofuminijo
tomofuminijo / config-recorder-enabled.yaml
Last active February 18, 2024 21:58
Enabled Config Recorder for Any Accounts, all regions
AWSTemplateFormatVersion: 2010-09-09
Description: Enable AWS Config
Parameters:
AuditS3BucketName:
Type: String
OrganizationId:
Type: String
Resources:
ServiceLinkedRoleForConfig:
@tomofuminijo
tomofuminijo / config-s3-bucket.yaml
Created February 11, 2020 07:18
Create S3 Bucket for aggregating AWS Config records
WSTemplateFormatVersion: 2010-09-09
Description: Create S3 Bucket for Config
Parameters:
AuditS3BucketName:
Type: String
OrganizationId:
Type: String
Resources: