ash-ec2info 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/ec2info +36 -0
  2. package/package.json +10 -0
package/ec2info ADDED
@@ -0,0 +1,36 @@
1
+
2
+ #!/usr/bin/env bash
3
+
4
+ # Fetch IMDSv2 Token
5
+ TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60" 2>/dev/null)
6
+
7
+ if [ -z "$TOKEN" ]; then
8
+ echo "Error: Unable to retrieve IMDSv2 token."
9
+ exit 1
10
+ fi
11
+
12
+ # Function to fetch metadata without displaying HTML errors
13
+ get_meta() {
14
+ local val
15
+ val=$(curl -s -f -H "X-aws-ec2-metadata-token: $TOKEN" "http://169.254.169.254/latest/meta-data/$1" 2>/dev/null)
16
+ if [ -z "$val" ] || [[ "$val" == *"<html>"* ]]; then
17
+ echo "N/A"
18
+ else
19
+ echo "$val"
20
+ fi
21
+ }
22
+
23
+ echo "=========================================="
24
+ echo " EC2 INSTANCE DETAILS "
25
+ echo "=========================================="
26
+ echo "Instance ID : $(get_meta instance-id)"
27
+ echo "Instance Name : $(get_meta tags/instance/Name)"
28
+ echo "Instance Type : $(get_meta instance-type)"
29
+ echo "AMI ID : $(get_meta ami-id)"
30
+ echo "Architecture : $(uname -m)"
31
+ echo "Public IPv4 : $(get_meta public-ipv4)"
32
+ echo "Local IPv4 : $(get_meta local-ipv4)"
33
+ echo "Security Groups : $(get_meta security-groups | tr '\n' ' ')"
34
+ echo "IAM Role : $(get_meta iam/security-credentials/)"
35
+ echo "Availability Zone: $(get_meta placement/availability-zone)"
36
+ echo "=========================================="
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "ash-ec2info",
3
+ "version": "1.0.0",
4
+ "description": "Quickly fetch EC2 instance metadata from internal SSH session",
5
+ "bin": {
6
+ "ec2info": "./ec2info.sh"
7
+ },
8
+ "keywords": ["aws", "ec2", "metadata", "cli"],
9
+ "license": "MIT"
10
+ }