{"id":6371,"date":"2021-06-26T19:29:01","date_gmt":"2021-06-26T13:59:01","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=6371"},"modified":"2021-06-28T09:24:27","modified_gmt":"2021-06-28T03:54:27","slug":"bash-script-to-get-the-information-related-to-instances-of-all-regions-in-aws","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/bash-script-to-get-the-information-related-to-instances-of-all-regions-in-aws\/","title":{"rendered":"Bash Script to get the information related to instances of all regions in AWS."},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In this script you will get information like AZ, instance ID, IP, keyname, etc&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please find the script below. Create a file with name getawsinstance.sh. Copy and paste the below content.<br><span class=\"has-inline-color has-vivid-green-cyan-color\">nano getawsinstances.sh<\/span><br><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><span class=\"has-inline-color has-vivid-green-cyan-color\">!\/bin\/bash<br><br>echo &#8220;Grabbing instances in all regions, please wait..&#8221;<br>for region in <code>aws ec2 describe-regions --output text | cut -f4<\/code>;<br>do<br>echo &#8220;Listing Instances in region:&#8217;$region&#8217;\u2026&#8221;<br>aws ec2 describe-instances &#8211;region $region \\<br>&#8211;output table \\<br>&#8211;query &#8220;Reservations[<em>].Instances[<\/em>].{<br>InstanceId:InstanceId,<br>Type:InstanceType,<br>AZ:Placement.AvailabilityZone,<br>KeyName:KeyName,<br>Name:Tags[?Key==`Name`]|[0].Value,<br>Project:Tags[?Key==`project`]|[0].Value,<br>IP:PublicIpAddress,<br>State:State.Name,<br>CPUcores:CpuOptions.CoreCount,<br>CPUThreads:CpuOptions.ThreadsPerCore<br>}&#8221;<br>done<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now create a IAM user. After creating you will get the credentials. Download them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next run aws configure and give the credentials.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now execute the script. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span class=\"has-inline-color has-vivid-green-cyan-color\">.\/getawsinstances.sh<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You will get the output which is in the screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-26-19-27-021.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"336\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-26-19-27-021-1024x336.png\" alt=\"\" class=\"wp-image-6379\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-26-19-27-021-1024x336.png 1024w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-26-19-27-021-300x98.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-26-19-27-021-768x252.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-26-19-27-021-850x279.png 850w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-26-19-27-021.png 1425w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this script you will get information like AZ, instance ID, IP, keyname, etc&#8230; Please find the script below. Create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1020],"tags":[878,877,879],"class_list":["post-6371","post","type-post","status-publish","format-standard","hentry","category-containers-kubernetes","tag-awsinstances","tag-bashscript","tag-script-to-get-details-of-aws-instances","psol-cat-containers-kubernetes"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1EL","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=6371"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6371\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=6371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=6371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=6371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}