Skip to content

Instantly share code, notes, and snippets.

View johnny-t2's full-sized avatar

Johnny-t2 johnny-t2

View GitHub Profile
@johnny-t2
johnny-t2 / helloworld-app.js
Last active February 15, 2020 23:27
Simple Hello WorldReact App.js
// src/App.js
import React, { Component } from 'react';
import { Header } from 'semantic-ui-react';
class App extends Component {
render() {
return (
<div>
<Header as='h1'>Hello World!</Header>
@johnny-t2
johnny-t2 / GetCredentialAndSetEnv.sh
Last active February 15, 2020 23:29
Get temporary credentials from sts with mfa and set environment
#!/bin/bash -eu
CLI_PROFILE=<your_cli_profile>
credentials=$(aws sts get-session-token \
--serial-number <your-mfa-device-arn> \
--token-code $1 \
--profile $CLI_PROFILE \
--query "Credentials.[AccessKeyId, SecretAccessKey,SessionToken]" \
--output text)
@johnny-t2
johnny-t2 / GetAndSetCredentialsToCLIConfigureFile.sh
Last active February 15, 2020 23:28
Get Temporary credentials from sts with mfa and set credentials to cli configure.
#!/bin/bash -eu
CLI_PROFILE=<your_cli_profile>
DEV_PROFILE=<you_dev_proffile>
credentials=$(aws sts get-session-token \
--serial-number <your-mfa-device-arn> \
--token-code $1 \
--profile $CLI_PROFILE \
--query "Credentials.[AccessKeyId, SecretAccessKey,SessionToken]" \
@johnny-t2
johnny-t2 / deny_all_http_s3_bucketpolicy.json
Created June 4, 2019 13:06
Bucket policy that blocks all non-secure request
{
"Version": "2012-10-17",
"Id": "Policy1559651007473",
"Statement": [
{
"Sid": "Stmt1559650947054",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::<your_bucket_name>/*",
@johnny-t2
johnny-t2 / create_stackset_adminrole.sh
Created February 11, 2020 07:14
Create Cloudformation StackSet Admin Role Command
#!/bin/bash
STACK_NAME=<your_stack_name>
aws cloudformation create-stack \
--stack-name $STACK_NAME \
--template-url https://s3.amazonaws.com/cloudformation-stackset-sample-templates-us-east-1/AWSCloudFormationStackSetAdministrationRole.yml \
--capabilities CAPABILITY_NAMED_IAM \
--region us-east-1
aws cloudformation wait stack-create-complete --stack-name $STACK_NAME --region us-east-1
@johnny-t2
johnny-t2 / create_stackset_executionrole.sh
Created February 11, 2020 07:15
Create Cloudformation StackSets Execution Role
#!/bin/bash
TARGET_ACCOUNT_ID=<target_account_id>
MASTER_ACCOUNT_ID=<master_account_id>
ROLE_NAME=OrganizationAccountAccessRole
STACK_NAME=<your_stack_name>
credentials=$(aws sts assume-role --role-session-name devdemo --role-arn arn:aws:iam::$TARGET_ACCOUNT_ID:role/$ROLE_NAME \
--query "Credentials.[AccessKeyId, SecretAccessKey,SessionToken]" \
--output text)
@johnny-t2
johnny-t2 / 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:
@johnny-t2
johnny-t2 / 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:
@johnny-t2
johnny-t2 / 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
@johnny-t2
johnny-t2 / 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