-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
38 lines (37 loc) · 1.63 KB
/
index.html
File metadata and controls
38 lines (37 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>EC2 Instance Metadata</title>
</head>
<body>
<h1>EC2 Instance Details</h1>
<p>Instance ID: <span id="instance-id">Loading...</span></p>
<p>Instance Type: <span id="instance-type">Loading...</span></p>
<p>Availability Zone: <span id="availability-zone">Loading...</span></p>
<p>Public IP: <span id="public-ip">Loading...</span></p>
<!-- Add more metadata fields as needed -->
<a href="hello.html" target="_blank">Hello</a>
</body>
<script>
async function fetchMetadata(path) {
try {
const response = await fetch(`http://169.254.169.254/latest/meta-data/${path}`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.text();
} catch (error) {
console.error(`Error fetching metadata for ${path}:`, error);
return 'N/A';
}
}
document.addEventListener('DOMContentLoaded', async () => {
document.getElementById('instance-id').innerText = await fetchMetadata('instance-id');
document.getElementById('instance-type').innerText = await fetchMetadata('instance-type');
const az = await fetchMetadata('placement/availability-zone');
document.getElementById('availability-zone').innerText = az;
document.getElementById('public-ip').innerText = await fetchMetadata('public-ipv4');
});
</script>
</html>