Skip to main content

Posts

Showing posts with the label AWS

AWS view instance store volume - ephemeral storage

Instance store volume in AWS is not like the EBS Volume (ebs - elastic block storage). The main difference between EBS and instance store volume, is EBS data or its contents will persist after reboot or shutdown. And for EBS volume you can take snapshot, create image do a backup or simply attached the EBS volume to another instance. Where as for instance store volume, which is physically attached to the host. It can't be search or can't be found on the "Volume" navigation pane. Thus, snapshot or taking backup is not possible. Instance store volume is some sort of a RAMDisk, in which it is indeed process data quite fast. However, if the instance is rebooted or shutdown all data is gone. Ideal only for dynamic data processing, that once data is process on the fly; data can be discarded or not needed anymore. How to view or check whether the instance you have got instance store volume? In a Linux instance, type the command below on a Terminal window: lsblk -o +...

PowerShell Get Apache Tomcat application path

PowerShell code snippet to get the path of the Apache Tomcat folder. The PowerShell code snippet will get the Apache Tomcat folder based on the service path. So, if the Apache Tomcat is not installed on a specific folder or path. Code snippet below, will check where the folder is located. $varDirectory="" $apacheServiceName=((Get-WmiObject win32_service | ?{$_.Name -like '*tomcat*'} | select Name, State, PathName).Name) $apacheServicePath=((Get-WmiObject win32_service | ?{$_.Name -eq $apacheServiceName} | select Name, State, PathName).PathName) $apacheHome = $apacheServicePath.Substring(0, $apacheServicePath.IndexOf('\bin')) #set the folder path for the SSL cert #or set any path to teh Apache Home Folder $varDirectory = "$apacheHome\key\" #Check the Path if okay or not write-host $varDirectory #Force OverWrite and supress prompting #Copy files to the Apache Tomcat folder Copy-Item -Path "C:\Temp\star_007_com.jks" -Destination $varDirectory ...

Get EC2 Image used by the AWS Instance

PowerShell code snippet to get the image used by an specific instance. $accesskey = 'access-key' $secretkey = 'secret-key' $dregion =  'us-east-1' (Get-EC2Instance -AccessKey $accesskey -SecretKey $secretkey -Region $dregion -InstanceId i-055353ks53sd6n).Instances  | select ImageId | ft -HideTableHeaders | out-string  #i-055353ks53sd6n -- replace with the actual instance-id EC2 Image in AWS is quite important especially if you are deploying a fleet of AWS instances and it has to be in the same image.

Get Public and Private IP Address of an AWS instance

PowerShell code snippet below will get or display the Public and Private IP Address of all running instances that matches  the Tag Key and Value specified. #replace the access key, secret key and region with the actual value $accesskey = 'acces-key' $secretkey = 'secret-key' $dregion =  'us-east-1' #Display Public and Private IP Address of the Instance (Get-EC2Instance -AccessKey $accesskey -SecretKey $secretkey -Region $dregion) | Select -ExpandProperty RunningInstance | ? {$_.Tag.Key -eq "Server" -and $_.Tag.Value -eq "Web-Server"} | Select-Object PrivateIpAddress, PublicIpAddress  #Replace the Tag Key and Tag Value as required #$_.Tag.Key -eq "Server"   #$_.Tag.Value -eq "Web-Server"

AWS PowerShell check if tag exist

How to check if a Tag exist on an instance? How to change the value of the tag, if tag exist? Code below shows how to check tags on AWS instances using PowerShell.   The script will also check if the tag exists and change the value to a different value. Sample scenario where the script can be used: Example: the tag can be "Web_Server", Value "In Progress" Then once the instance is ready, the tag can be changed to "Web_Server", Value "Online"   $accesskey = 'AWS-Access-Key' $secretkey = 'AWS-Secret-Key' $dregion =   'eu-west-1' #change the region as required   #instances to be checked #repace the value with the actual instance-id $array_prefix_instanceID = @( "i-04e5er7ac566vc8", "i-0c3c3cerbc3165685vc", "i-0ecc355gf0aa5758g" )   #Assume value of the tag #Change as required / script will look for the value Yes $value="Yes"   #Tag to look...

Monitor disk drive space using PowerShell

Monitoring space is quite crucial in a critical system, or basically checking the disk space whether there is enough free space for continual operation is a good thing to consider in a production environment. A simple PowerShell script can save the day by monitoring the drive space of a specific drive that needs to be checked or monitored. It doesn’t need a complex tool to do this kind of task. Here’s a one-liner PowerShell script to check free space on C drive. Get-WmiObject Win32_LogicalDisk -filter "DeviceID = 'c:' " | Select-Object   { $_ . FreeSpace / 1GB }   "DeviceID = 'c:' " = this can be changed to any drive letter Output of the above command: $_.FreeSpace /1GB -----------------   293.042289733887   Or to include the existing size of the drive, the command can be tweaked like this: Get-WmiObject Win32_LogicalDisk -filter "DeviceID = 'c:' " | Select-Object   { $_ . FreeSpace / 1GB } , { $...

Nano editor shortcut keys

Nano editor in Linux is quite handy when working with text files in terminal window. Here's some keystroke that is quite useful when using Nano or editing text file with Nano. Ctrl + i  is like pressing the "Tab" key Ctrl + y will   go to top of the current displayed window or the top of the current nano screen Ctrl + v will go to the end of the current displayed window or the end of the current nano screen Ctrl + m  will move current line below the current cursor position Ctrl  + d will delete empty line                or will delete tab spaces                or will delete a single character if the line has text on it Ctrl + k   will cut the current line or current line will be cut and copied to clipboard (like Ctrl + x in word document if the text is highlighted) Ctrl + u   will paste the line that was cut or whatever is on the clipboard (like Ctrl /+ v in word doc...

Bash slice string in Linux Shell

Strings are quite basic in any scripting or programming languages. If a journey to a thousand miles starts with a single step, in the programming world the journey starts with a string called “Hello World” and beyond “Hello World” pseudocode and algorithm will keep the journey going.   Strings in scripting or programming are just group of characters. So, if string is a group of characters then it can be slice by character or a sub-string can be taken from the string. To slice a string in Bash, a syntax which is part of the Bash library can be used. Syntax is: ${string_to_be_sliced:slice_start_position:slice_end_position} Example string: slicethestring=“Hello Algorithm World” The string is stored in a variable: slicethestring To get the sub-string “Algorithm World”. Code will be:   echo ${slicethestring:6:23} #start the slice at position 6 till position 23 Another way to slice the string from a specified start position till the end; is to tell Bash the star...

Read or get the list of contents on S3 bucket

S3 or Simple Storage Service bucket is quite handy to store files or any data on AWS cloud. As with any storage, online or offline organizing the data is quite an issue. When there are a lot of files of data on the storage; finding the data that you will need will be difficult. Especially, if the data or bucket is not organized properly. And even if the data has been organized by folders with proper time stamp but no specific data catalog to classify which one is which one it is quite a challenge to find or get the data on time. S3 is ideal for backup, since backup is often accessed only when it is needed. So, familiarization of the backup folder structure is necessary. In order to find or get easily the data, listing the contents of the S3 bucket is a good option when unable to find the files or data needed. Once the list is ready, opening the list via editor such as notepad and searching or finding thru the editor will provide an option to find things quickly and easily. ...

How to upload to S3 using PowerShell

Uploading to S3 using PowerShell is quite easy. Here’s the code: $accesskey = '123' $secretkey = '456' $dregion =   'us-east-1'   Write-S3Object -AccessKey $accesskey -SecretKey $secretkey -Region $dregion -BucketName   -File C:\Temp\test-file.txt #Replace NameofthebucketinS3 with the folder name found in S3 # test-file.txt is the file that will be uploaded to S3 and is located on c:\Temp #Change the folder location c:\Temp and the file to be uploaded #Above code will upload the file to the root of the S3 Bucket     #If need to upload a file to a specific subfolder in S3 bucket used the code below   $accesskey = '123' $secretkey = '456' $dregion =   'us-east-1'   Write-S3Object -AccessKey $accesskey -SecretKey $secretkey -Region $dregion -BucketName NameofthebucketinS3/SubFolderBucket -File C:\Temp\test-file.txt   Use forward slash to indicate the sub folder path. So the syntax would be...

Create a new text file with content in Linux

Touch command in Linux will create an empty file in Linux command line. If no other parameters is specified whether a line will be inserted to the newly created file. Cat command is for reading files via command line but it can also be used to create a file in Linux terminal window command line. Cat command below will create a file called “test_comment.txt” and with the content or the line of “Hello World of Touch and Create File” on the file created. Here’s the shell command: cat  <( echo “Hello World of Touch and Create File”)  >  test_comment.txt Note that there is no space between “<(“, if there is a space then the command will not work as expected. Touch command to create a new file and also insert a new line or insert a string on the newly created file. Here’s the shell command: touch touch_file_comment.txt; echo “Hello World of Touch, insert this line.” >  touch_file_comment.txt Basically, the command exec...

How to check or find unattached snapshot in AWS

Checking unattached snapshot is a good technique to save some storage cost; of course, you need to do what’s the best thing after checking unattached snapshots. If you are confident that the snapshot won’t be needed anymore, then it has to be deleted or else you will be incurring costs for nothing. Every space on the cloud is not free, any space usage is an added cost to your pocket. But then how do you check for unattached snapshot in AWS? There are quite a lot of ways you can do, if you love PowerShell it can be done in PowerShell; if you want to do it in Python with Boto3 it can be done as well. Of course, in PowerShell and Python if this is the preferred method then you need to create some code. It won’t just spit out for you what are the unattached snapshots in your AWS account. Enough said, the easiest way to search or look for unattached snapshot is just to search using the AWS EC2 console. Open your browser, login to your EC2 console and search for: vol-ffff See image be...