Skip to main content

Posts

Showing posts from November, 2014

File merging in Linux

cat file1.out a b c cat file2.out 1 2 3 paste -d ' ' file1.out file2.out > final.out cat final.out a 1 b 2 c 3 paste -d '| ' file1.out file2.out > final.out cat final.out a|1 b|2 c|3 diff -y file1.out file2.out > final.out cat final.out a                                                             | 1 b                                                             | 2 c                                                             | 3

Extract TAGs associated with EC2 and EBS

Describe Tags associated with EC2 $aws ec2 describe-tags --filters "resource-type=instance" Describe Tags associated with EC2 $aws ec2 describe-tags --filters Name="resource-type",Values="instance" --filters Name="resource-id",Values="i-xxxxxxx" Describe Tags associated with EBS Volums  $aws ec2 describe-tags --filters Name="resource-type",Values="volume"

While loop

General While loop while command do    Statement(s) to be executed if command is true done #!/bin/sh a=0 while [ $a -lt 10 ] do    echo $a    a=`expr $a + 1` done While loop single liner  while true; do foo; sleep 2; done

How to Retrieving Security Credentials from Instance Metadata

Use Case:  Suppose you have external customers, vendors who needs to access some information of yours AWS environment. You want to give them read only access to s3 bucket. The external users are supposed to use Rest API calls to access your s3 bucket and will require AWS Access Key and Secure Access Key. If you provide external users and later forget to retrieve or change that one, they may have permanent access to your environment. You want to give them temporary access which can lasts upto 12 hours. Solution:  Create a IAM Role  Attach the IAM role to an EC2 instance Share the .pem / .ppk file to access the EC2 instance External user will login to EC2 user run the command   $curl http://169.254.169.254/latest/meta-data/iam/security-credentials/ iam-role Will get following AccessKeyId SecretAccessKey Token And now they can use Rest API call with above details.