Navigating AWS Control Tower for Seamless Cloud Management

December 16, 2021 Leave a comment

In this article, we will dive deep into AWS Control Tower’s best practices, complete with real-world examples and code snippets to help you harness its full potential.

Setting Up AWS Control Tower

Setting up AWS Control Tower is the foundation for effectively managing AWS organization. Let’s get started.

Prerequisites

Before diving into Control Tower, make sure you’ve:

  • AWS Accounts: Ensure you have AWS accounts to set up Control Tower.
  • Permissions: You’ll need the necessary permissions to create and configure Control Tower.

Account Structure

One of the first things to consider is defining your account structure. You want to ensure your organization’s accounts are well-organized and follow a logical hierarchy. Here’s an example of how you can structure your accounts:

{
  "ou-1": {
    "dev": [
      "dev-account-1",
      "dev-account-2"
    ],
    "test": [
      "test-account-1",
      "test-account-2"
    ]
  },
  "ou-2": {
    "prod": [
      "prod-account-1",
      "prod-account-2"
    ]
  }
}

Choosing the Right Organizational Units (OUs)

Organizational Units (OUs) are critical for managing and organizing your accounts. For instance, you can create an OU named “Development” and place all your development accounts under it.

Enabling Guardrails

Guardrails are essential to ensure your accounts adhere to best practices. For example, enable the “Disallow Root Account Access” guardrail to enhance security.

User and Role Management

Managing users and roles is crucial for controlling access within your AWS organization.

Managing User Access

To grant user access, use AWS Identity and Access Management (IAM) to create and manage user accounts.

Defining Roles and Permissions

Roles are used to grant permissions to AWS resources. Here’s how you can create a role:

aws iam create-role --role-name CustomRole --assume-role-policy-document '{
  "Version": "2012-10-17",
  "Statement": {
    "Effect": "Allow",
    "Principal": {
      "Service": "ec2.amazonaws.com"
    },
    "Action": "sts:AssumeRole"
  }
}'

Role-Based Access Control

Implementing role-based access control ensures that users have the necessary permissions for their roles. You can set up IAM policies to define role permissions.

Compliance and Security

Ensuring compliance and security in your AWS organization is paramount.

Implementing Security Best Practices

Follow AWS security best practices for IAM, Multi-Factor Authentication (MFA), security groups, and Network Access Control Lists (NACLs).

Compliance with AWS Best Practices and Industry Standards

Compliance with standards like CIS benchmarks and the AWS Well-Architected Framework is essential for the security and integrity of your AWS organization.

Cost Management

Effective cost management is a crucial aspect of managing your AWS organization.

Cost Allocation and Tagging

Tagging resources and setting up cost allocation ensures you can track and manage costs effectively. For example, tag an EC2 instance:

aws ec2 create-tags --resources i-0123456789abcdef0 --tags 'Key=Environment,Value=Production'

Budgets and Cost Control Guardrails

Implement budgets to track your organization’s cost performance. You can also set up cost control guardrails to prevent overspending.

Implementing AWS Cost Explorer

AWS Cost Explorer is a powerful tool for analyzing your organization’s costs and usage. Use it to gain insights into your spending patterns.

Resource Management

Efficiently managing resources across your AWS accounts is crucial.

Managing Accounts and Resources

Effective resource management starts with managing AWS accounts and resources centrally. Use AWS Organizations for this purpose.

Centralized Resource Provisioning

Implement a centralized resource provisioning strategy to ensure consistency and reduce manual provisioning overhead.

Resource Sharing and Networking

Sharing resources and setting up networking configurations across accounts are essential for collaboration. Here’s an example of sharing an S3 bucket:

aws s3api put-bucket-acl --bucket my-shared-bucket --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers

Logging and Monitoring

Comprehensive logging and monitoring are essential for ensuring the security and performance of your AWS environment.

Centralized Logging

Centralize your logs using AWS services like Amazon CloudWatch and AWS CloudTrail to ensure visibility across your accounts.

CloudWatch and CloudTrail Best Practices

Follow best practices when configuring CloudWatch and CloudTrail to monitor your AWS environment effectively. Here’s an example of setting up an S3 bucket for CloudTrail logs:

aws s3api create-bucket --bucket my-cloudtrail-logs

Setting Up Alarms and Notifications

Create CloudWatch alarms to notify you when specific conditions occur, ensuring you can respond promptly to issues.

Disaster Recovery and High Availability

Disaster recovery and high availability are vital for ensuring the continuity of your AWS services.

Implementing AWS Backup and Recovery Solutions

Utilize AWS Backup to create backups of your resources and ensure you can recover them when needed.

Ensuring High Availability of Critical Services

Design your architecture for high availability by distributing resources across multiple Availability Zones.

Updating and Evolving Control Tower

AWS Control Tower is continually evolving, so staying up to date is crucial.

Handling Updates and Changes

Stay informed about the latest Control Tower updates and changes by running:

aws controltower get-latest-updates

Troubleshooting and Tips

Troubleshooting is an inevitable part of managing your AWS organization. Here are some common issues and solutions.

Common Issues and Their Solutions

If you encounter issues, consult the AWS Control Tower Troubleshooting Guide for solutions to common problems.


In this blog, we’ve briefly explored the world of AWS Control Tower and covered few best practices for setting up, managing users and roles, ensuring compliance and security, cost management, resource management, logging, disaster recovery, and more. AWS Control Tower is a powerful tool to manage your AWS environment efficiently, and by following these best practices, you’re well on your way to success. Happy cloud computing!

Categories: Uncategorized

some more git commands

December 19, 2014 Leave a comment

1. Git log with short SHA
$ git log –oneline
$ git log –abbrev-commit –pretty=oneline
or
$ git log –abbrev-commit –oneline

## Git oneline log with complete SHA-1 hash
git log –format=oneline

2. Show which is the HEAD revision on a branch in local repo :
$ git show topic1

3. List the SHA for HEAD commit in the local repo:
$ git rev-parse topic1

4. Log of changes to the current branch tip (reflog)
$ git reflog

5. Show which was the HEAD (tip) for master branch yesterday:
$ git show master@{yesterday}

6. Nth(where N is a number) prior revision of the repo:
$ git show HEAD@{5}

7. Parent of the HEAD of the current branch:
$ git show HEAD^

8. Nth (say second) parent (includes lateral parent, i.e. parent from another branch too) of a given revision:
$ git show HEAD^2
$ git shoa <SHA>^2

9. Nth(Say third) parent of parent (span only on that particular branch):
$ git show HEAD~3
$ git show <SHA>~3
$ git show <SHA>^^^
$$ git show –format=oneline <SHA-1>  ## details in 1 line

10. Changelog b/n two branches:
$ git log  branch1..branch2  (Branch 2 commits which are not merged into branch1)

Another way without using double dots
$ git log ^refA refB (Another way)
$ git log refB –not refA

$ git log branch2..branch1 ##(Branch1 commits which are not merged into branch2)

11. Changes or revision which will be pushed to remote branch:
$ git log origin/master..HEAD

12. commits present in refB & refC, but not in refA
$ git log refB refC –not refA
$ git log refB refC ^refA

13. All commits that are reachable by either of two references but not by both of them.
$ git log master…topic1
$ git log –left-right master…topic1

14. Interactive and selective Patch commits:
$ git add i
> then choose 1 or s for status
> then option 5 or p
> then ‘yes’ for the hunk to be staged

15.Stashing unstaged and uncommited changes:
$ git stash              ##[Takes into account unstaged and uncommited(but staged) files only]
or
$ git stash save “Message”
$ git stash -u           ## For including untracked files
$ git stash –keep-index ##Include only unstaged changes in the stash
$ git stash –patch      ##Prompts interactively for every change to be be added to the stash

Listing and seeing the content of the stash
$ git stash list ## lists all the stash
$ git stash show stash@{N} ## show the Nth stash content
$ git stash show -p  stash@{N}   ## Show the content of the stash in the form of a edit patch

Reapply the most recent stash without staging the changes which were staged before stashing:
$ git stash apply
$ git status

Reapply a previous stash(say 3rd latest) without staging the changes which were staged before stashing:
$ git stash apply stash@{2} (The stash numbering starts with 0)

15. Reapply stash with staged changes.
$ git stash apply –index

16 Apply the recent stash and drop the stash
$ git stash pop

17. Creating a new branch from stash.
$ git stash branch testchanges  ## Applies stash after creating a branch called ‘testchanges’ from the revision where stash was saved

## Droping all stashes
$ git stash clear

18. Create signed tags and commit:
git config –global user.signingkey <gpg pub key>
git tag -s <tag_name> -m “Comment”
git show <tag_name> # Show the GPG pub key as part of commit log
git tag -v <tag_name>  | grep ‘gpg: Good signature’

19. Searching for Text Patterns in Git repo
$ git grep <pattern>
$ git grep  -n <pattern> ## Prints line # of the file containing pattern
$ git grep -p <pattern> *.c ## Prints functions and methods in which the Pattern exists along with the line containing the pattern
$ git log -S<pattern> –oneline  ## The revision in which a PATTERN was either introduced or related.
$ git log -G<regex_pattern> –oneline ## The revision in which REGEX_PATTERN was either introduced or related.
$ git log -L<pattern>:<file_name>

20. Rewriting commit history:
$ git commit –amend
or
$ git rebase -i HEAD~N   ## Where N is a number upto which the history need to be modified, deleted squashed, etc
$

21. configuring global gitignore:
$ git config –global core.excludesfile ~/.gitignore_global

# This will be added to user’s global .gitconfig file
$ cat ~/.gitconfig
[filter “media”]
required = true
clean = git media clean %f
smudge = git media smudge %f
[core]
excludesfile = $HOME/.gitignore_global

22. Ignoring tracked file:
Add <filename> entry into .gitignore and then
$ git rm –cached <filename>  ## this removes the file from staging area.
$ git commit -m  <filename>

25. Tracking empty directories:
Create(touch) .gitkeep file into empty directory and then
$ git add <empty_directry_path>
$ git commit -m “Message”
$ git status

26. Listing or seeing the contents of a tree-ish object:
$ git ls-tree HEAD|<SHA-1>|<Branch Name>
$ git ls-free master
$ git ls-tree a1b2c3d
$ git ls-tree HEAD
$ git ls-tree HEAD^
$ git ls-tree a1b2c3d^
$ git ls-tree master^
$ git ls-tree HEAD~3

27.Git commit log
git log –since=”2014-10-30″
or
git log –after=”2014-10-30″

28. Git log between 2 dates:
git log –since=”YYYY1-MM1-DD1″ –until=”YYYY2-MM2-DD2″
git log –since=”4.weeks” –until=”2.days”

29. Git commit log for an author:
git log –author=”Yogesh S”

30. Search git log for a particular file or pattern
git log –grep=”configfile”

31.All logs which affect the particular file:
git log <initial SHA-1>..  filename

32. Log with code diff
Git log -p

33 Log with statistics
git log –stats –summary

34. GIt log with Grapth
git log –oneline –graph  –all –decorate

35. Diff b/n 2 tree-ish

$ git diff <AN-OLD-SHA> <filename>
$ git diff SHA_1..SHA_2  ## Diff of repo for 2 snapshots
$ git diff SHA_1..SHA_2 <filename>  ## Diff b/n 2 snapshots for the filename
$ git diff SHA..HEAD
$ git diff SHA..HEAD^^
$ git diff –stat –summary SHA..HEAD  ## This is the summary of changed files
$ git diff -b  SHA_1..SHA_2  ## Ignore space while diffing
$ git diff -w   SHA_1..SHA_2  ## Ignore all white spaces while diffing

36. Comparing or diffing 2 branches:
$ git diff branch1..branch2
$ git diff –color-words branch1..branch2  ## Shows diff on the same line

37. Find if a branch has all the changes merged from other branches:
$ git branch –merged

38. Renaming branch

$ git branch -m <branch_name> <new_branch_name>

39. Deleting Branch
$ git checkout <master|any_other_branch> && git branch -d|–delete <branch_to_delete>
$ git checkout <master|any_other_branch> && git branch -D <branch_to_delete>  ##Deleting a branch without merging changes in branch_to_delete to master or parent branch

40. Merging a branch into another
$ git checkout master
$ git status
$ git merge <new_nranch>

41. Aborting the merge
$ git merge –abort

42. Choosing a mergetool for conflict resolution
$ git mergetool –tool=<merge_tool>

43. Stratergies to reduce merge conflicts:
(i) Keep the code lines short
(ii) Keep the changes small and focused and commits
(iii) Avoid stray edits to whitespaces like tabs, spaces, line retuns unnecessarily
(iV) Try merging often
(v) Track changes to master and bring them to your branch often by mering master into your branch, before doing a final merge of
your branch into master when all your changes are complete and satisfactory.

44. Deleting a remote branch
$ git push origin :branch_name
$ git push origin –delete branch_name

Categories: Uncategorized

cURL cheatsheet

November 19, 2014 1 comment

cURL cheatsheet

Working with HTTP from the command-line is a valuable skill for HTTP architects and API designers to have. The cURL library and curl command give you the ability to design a Request, put it on the pipe, and explore the Response. The downside to the power of curl is how much breadth its options cover. Running curl –help spits out 150 different flags and options. This article demonstrates nine basic, real-world applications of curl.

Make a simple get request

curl http://echo.httpkit.com

Make a get request on insecure SSL /connection

curl -k “https://localhost/foo?bar=baz&amp;abc=def&#8221;

Get response header information

curl -i http://www.google.com

Json POST request using cURL (data and header is optional)

curl -k -H “Content-Type: application/json” -X POST -d ‘{“accountName”:”test”,”value”:”hello”}’ https://localhost/foo

http DELETE request using cURL

curl -X DELETE echo.httpkit.com

Mutiple headers in request

curl -H “Accept: application/json” -H “Authorization: OAuth 2c3455d1aeffc” http://echo.httpkit.com

Send request body (JSON data with request)

curl -X PUT -H ‘Content-Type: application/json’ -d ‘{“firstName”:”Kris”, “lastName”:”Jordan”}’ echo.httpkit.com

http PUT request to send a file as request body data

curl -X PUT -H ‘Content-Type: application/json’ -d @example.json echo.httpkit.com

http POST html Form data

curl -d “firstName=Kris” -d “lastName=Jordan” echo.httpkit.com

POST HTML Multipart / File Forms

curl -F “firstName=Kris” -F “publicKey=@idrsa.pub;type=text/plain” echo.httpkit.com

Test Virtual Hosts, Avoid DNS

curl -H “Host: google.com” 50.112.251.120

Fake a /etc/hosts entry and a Host: header with curl (-vvv for verbose)

curl -vvv –resolve ‘www.google.com:80:50.112.251.120’ http://www.google.com/

Make a request with basic auth enabled

curl -vvv -u name@foo.com:password http://www.example.com
or
curl –user name:password http://www.example.com

Set cookies in cURL request

curl -b “name=test” http://www.example.com
or
curl –cookie “name=test” http://www.example.com

Downloading a file instead of putting on console

curl -O https://raw.github.com/username/reponame/master/filename

Write output to <file> instead of stdout (using regex/variables in curl request)

curl http://{site1,site2}.host[1-5].com -o “#1_#2”

Time a request (connect time + total time) – Get some additional information about request

curl -o /dev/null -w “Connect: %{time_connect} Total-time: %{time_total} \n” http://google.com

Categories: Uncategorized

Github Cheatsheet

November 19, 2014 Leave a comment

github_keyboard_shortcuts

Categories: Git Tags:

Git CheatSheet

November 19, 2014 Leave a comment

git_cheatsheet

Categories: Git Tags:
Create your own website, free on WordPress.com.Create your own website.
Start free