- 📅 2024-09-19T11:13:25.179Z
- 👁️ 62 katselukertaa
- 🔓 Julkinen
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>List S3 Buckets</title>
<!-- AWS SDK from the CDN -->
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.877.0.min.js"></script>
</head>
<body>
<h1>List S3 Buckets</h1>
<button id="listBucketsBtn">List Buckets</button>
<ul id="bucketsList"></ul>
<script>
// Configure the AWS SDK with hardcoded credentials (NOT recommended for production)
AWS.config.update({
region: 'us-east-2', // Your AWS region
accessKeyId: 'AKIA6ODUSDHT3IV3RA46', // Your Access Key ID (example)
secretAccessKey: 'nzeqIaYFFGNGvpIl4Xotf9eMqVrAOrcyfGQVE' // Your Secret Access Key (example)
});
// Function to list S3 buckets when the button is clicked
document.getElementById('listBucketsBtn').addEventListener('click', function () {
var s3 = new AWS.S3();
s3.listBuckets(function (err, data) {
if (err) {
console.log("Error:", err);
} else {
var buckets = data.Buckets;
var bucketsList = document.getElementById('bucketsList');
bucketsList.innerHTML = ''; // Clear the previous list
// Loop through the bucket data and create list items
buckets.forEach(function (bucket) {
var li = document.createElement('li');
li.textContent = bucket.Name;
bucketsList.appendChild(li);
});
}
});
});
</script>
</body>
</html>