Bird
Raised Fist0
AWScloud~20 mins

Static website hosting on S3 in AWS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
S3 Static Website Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
How does S3 handle website index documents?

You configure an S3 bucket for static website hosting and set index.html as the index document. What happens when a user visits the root URL of the website?

AS3 returns a 404 error because no specific file is requested.
BS3 returns the <code>index.html</code> file from the root of the bucket as the homepage.
CS3 returns a list of all files in the bucket as a directory listing.
DS3 redirects the user to the AWS Management Console.
Attempts:
2 left
💡 Hint

Think about what an index document means for a website.

security
intermediate
2:00remaining
What is required to make an S3 bucket publicly accessible for static website hosting?

You want to host a public static website on S3. Which configuration is necessary to allow anyone on the internet to access the website files?

ASet the bucket policy to allow public read access and disable Block Public Access settings.
BEnable versioning on the bucket and use IAM roles for access.
CCreate a VPC endpoint for the bucket and restrict access to the VPC.
DUse AWS KMS encryption and require MFA for access.
Attempts:
2 left
💡 Hint

Public website means anyone can read the files without signing in.

Configuration
advanced
2:30remaining
Which S3 bucket policy correctly allows public read access for static website hosting?

Choose the bucket policy JSON that correctly grants public read access to all objects in the bucket named example-bucket.

A
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:ListBucket",
    "Resource": "arn:aws:s3:::example-bucket"
  }]
}
B
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Deny",
    "Principal": "*",
    "Action": "s3:PutObject",
    "Resource": "arn:aws:s3:::example-bucket/*"
  }]
}
C
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": {"AWS": "arn:aws:iam::123456789012:user/admin"},
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::example-bucket/*"
  }]
}
D
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::example-bucket/*"
  }]
}
Attempts:
2 left
💡 Hint

Public read means allowing everyone to get objects, not just listing the bucket.

Architecture
advanced
2:30remaining
How to configure custom domain with HTTPS for S3 static website hosting?

You want to serve your S3 static website using your own domain with HTTPS. Which AWS service combination is the best practice to achieve this?

ADirectly point your domain's DNS to the S3 website endpoint and enable HTTPS on S3.
BUse Route 53 alias record pointing to the S3 bucket and enable HTTPS in the bucket properties.
CUse Amazon CloudFront with an SSL certificate from AWS Certificate Manager and point your domain to CloudFront distribution.
DCreate an EC2 instance with a web server to proxy requests to the S3 bucket and install SSL there.
Attempts:
2 left
💡 Hint

S3 website endpoints do not support HTTPS directly.

Best Practice
expert
3:00remaining
What is the recommended way to handle 404 errors on an S3 static website?

You want to show a custom error page when users visit a non-existent page on your S3 static website. How should you configure this?

ASet the <code>error document</code> property in the S3 static website hosting configuration to the custom error page file name.
BCreate a Lambda function to intercept 404 errors and redirect to the custom error page.
CEnable versioning on the bucket and upload the error page as the latest version.
DConfigure the bucket policy to redirect 404 errors to the custom error page.
Attempts:
2 left
💡 Hint

S3 static website hosting has a built-in setting for error documents.

Practice

(1/5)
1. What is the first step to host a static website on AWS S3?
easy
A. Set up a database
B. Upload files to EC2
C. Configure a Lambda function
D. Create an S3 bucket

Solution

  1. Step 1: Understand the hosting process

    Hosting a static website on S3 starts by creating a storage space called a bucket.
  2. Step 2: Identify the correct initial action

    Before uploading files or configuring anything else, you must create the bucket to hold your website files.
  3. Final Answer:

    Create an S3 bucket -> Option D
  4. Quick Check:

    First step = Create bucket [OK]
Hint: Start by making a bucket to hold your website files [OK]
Common Mistakes:
  • Trying to upload files before creating a bucket
  • Confusing S3 with EC2 for hosting
  • Setting up Lambda or database unnecessarily
2. Which of the following is the correct way to enable static website hosting on an S3 bucket?
easy
A. Enable 'Static website hosting' in bucket properties and specify index document
B. Set bucket policy to private and upload files
C. Create an IAM user with full access to the bucket
D. Attach an EC2 instance to the bucket

Solution

  1. Step 1: Locate the static website hosting setting

    In the S3 bucket properties, there is an option to enable static website hosting where you specify the index document.
  2. Step 2: Understand the correct configuration

    Enabling static website hosting and setting the index document allows the bucket to serve web pages correctly.
  3. Final Answer:

    Enable 'Static website hosting' in bucket properties and specify index document -> Option A
  4. Quick Check:

    Enable hosting + index document = correct setup [OK]
Hint: Enable hosting in properties and set index file name [OK]
Common Mistakes:
  • Leaving bucket policy private without public read
  • Confusing IAM user creation with hosting setup
  • Trying to attach EC2 to S3 bucket
3. Given this bucket policy snippet for an S3 static website:
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::example-bucket/*"
  }]
}
What is the effect of this policy?
medium
A. Allows only authenticated users to write to the bucket
B. Blocks all access to the bucket
C. Allows anyone to read objects in the bucket
D. Allows anyone to delete objects in the bucket

Solution

  1. Step 1: Analyze the policy statements

    The policy allows "Effect": "Allow" for "Principal": "*" which means everyone, on the action "s3:GetObject" for all objects in the bucket.
  2. Step 2: Understand the permission granted

    This means anyone can read (get) objects from the bucket, which is needed for public website hosting.
  3. Final Answer:

    Allows anyone to read objects in the bucket -> Option C
  4. Quick Check:

    Principal * + GetObject = public read [OK]
Hint: Principal * with GetObject means public read access [OK]
Common Mistakes:
  • Thinking it blocks access instead of allowing
  • Confusing GetObject with write or delete permissions
  • Assuming only authenticated users have access
4. You enabled static website hosting on your S3 bucket but get a 403 Forbidden error when accessing the site. What is the most likely cause?
medium
A. Index document is missing from the bucket
B. Bucket policy does not allow public read access
C. Bucket name contains uppercase letters
D. You did not upload any files

Solution

  1. Step 1: Understand 403 Forbidden error context

    A 403 error usually means permission denied, so the website cannot read files from the bucket.
  2. Step 2: Check bucket policy and permissions

    If the bucket policy does not allow public read access, the website cannot serve files, causing 403 errors.
  3. Final Answer:

    Bucket policy does not allow public read access -> Option B
  4. Quick Check:

    403 error = permission denied = fix bucket policy [OK]
Hint: 403 means permission denied; check bucket policy [OK]
Common Mistakes:
  • Assuming missing index document causes 403 (usually 404)
  • Thinking bucket name case causes errors
  • Ignoring permissions and blaming missing files
5. You want to host a static website on S3 with a custom domain and HTTPS. Which combination of AWS services should you use?
hard
A. S3 static website hosting + Route 53 for domain + CloudFront with SSL certificate
B. S3 static website hosting + EC2 instance + Elastic Load Balancer
C. S3 static website hosting + Lambda functions + API Gateway
D. S3 static website hosting + DynamoDB + IAM roles

Solution

  1. Step 1: Identify services for custom domain and HTTPS

    Route 53 manages domain names, CloudFront provides HTTPS with SSL certificates, and S3 hosts the static files.
  2. Step 2: Understand the integration

    Use Route 53 to point your domain to CloudFront distribution, which serves content securely from S3 with HTTPS.
  3. Final Answer:

    S3 static website hosting + Route 53 for domain + CloudFront with SSL certificate -> Option A
  4. Quick Check:

    Custom domain + HTTPS = Route 53 + CloudFront + S3 [OK]
Hint: Use CloudFront for HTTPS and Route 53 for domain [OK]
Common Mistakes:
  • Using EC2 or Lambda unnecessarily for static hosting
  • Ignoring CloudFront for HTTPS support
  • Confusing database or IAM roles with hosting setup