Amazon Simple Storage Service (Amazon S3) is an object storage service built to store and retrieve any amount of data from anywhere on the web.
In this workshop, S3 will be used to:
In this section, we will create an S3 bucket to store static resources for the website. Follow these steps:
S3 bucket names must be globally unique. If your chosen name is already taken, try another name.



{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::optimization-website/*"
}
]
}

Ensure to only allow public access for files necessary for the website. Don’t make the entire bucket public if it contains sensitive data.
npm install aws-sdk
const AWS = require('aws-sdk');
// Configure AWS
AWS.config.update({
accessKeyId: 'YOUR_ACCESS_KEY',
secretAccessKey: 'YOUR_SECRET_KEY',
region: 'ap-southeast-1'
});
const s3 = new AWS.S3();
// Upload file
async function uploadFile(file, bucket, key) {
const params = {
Bucket: bucket,
Key: key,
Body: file
};
try {
const data = await s3.upload(params).promise();
console.log('File uploaded successfully:', data.Location);
return data.Location;
} catch (err) {
console.error('Error uploading file:', err);
throw err;
}
}
// Download file
async function getFile(bucket, key) {
const params = {
Bucket: bucket,
Key: key
};
try {
const data = await s3.getObject(params).promise();
return data.Body;
} catch (err) {
console.error('Error getting file:', err);
throw err;
}
}
Best Practices when using S3: