In this step, we will create an S3 bucket with Static website hosting enabled and publicly accessible using AWS SAM.
Open the template.yaml file in the fcaj-book-shop folder that we created in Part 1.

Delete the unnecessary parts (highlighted in the image above), including:
HelloWorldFunction and its related Events.Add the Parameters section after Globals to define the bucket name:
Parameters:
FCAJBookShopBucketName:
Type: String
Default: fcaj-book-shop-by-myself

Add the Resources section to create the S3 Bucket and Bucket Policy:
Resources:
FCAJBookShop:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref FCAJBookShopBucketName
WebsiteConfiguration:
IndexDocument: index.html
PublicAccessBlockConfiguration:
BlockPublicAcls: false
BlockPublicPolicy: false
IgnorePublicAcls: false
RestrictPublicBuckets: false
FCAJBookShopPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref FCAJBookShop
PolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- "s3:GetObject"
Effect: Allow
Principal: "*"
Resource: !Join
- ""
- - "arn:aws:s3:::"
- !Ref FCAJBookShop
- /*
The script above defines:
Principal: "*") to read (s3:GetObject) all objects in the bucket.
Run the sam build command at the SAM project directory (fcaj-book-shop) to build the application:
sam build

Validate the SAM template:
sam validate

Deploy SAM in guided mode (step-by-step):
sam deploy --guided
Enter the following information when prompted:
fcaj-book-shopap-southeast-1 (or your preferred deployment region).YYNY
S3 bucket names must be globally unique. If the name fcaj-book-shop-by-myself is already taken, change it to something unique (e.g., fcaj-book-shop-by-yourname).
While waiting for the deployment, you can open the CloudFormation console to monitor the stack creation progress.

Wait for the changeset creation to complete. When prompted Deploy this changeset?, enter y to confirm the deployment.

Open Amazon S3 console.

At the bucket detail page:

Scroll down to the Static website hosting section:

Make sure to save the Bucket website endpoint as you will need this URL to access the front-end application after uploading.
Click on the Permissions tab:
s3:GetObject with Principal: "*", meaning everyone can read the files in the bucket.
Open the CloudFormation console to check the stacks:

Click on the fcaj-book-shop stack, switch to the Resources tab:

Click on the aws-sam-cli-managed-default stack to view the resources automatically created by SAM CLI:

Download the fcj-serverless-frontend source code to your device:
git clone https://github.com/tranvix0910/FCAJ_Workshop-Serverless.git
cd FCAJ_Workshop-Serverless
Make sure you have Node.js and npm installed on your machine before running the commands above. If not, please refer to: https://nodejs.org/
Install dependencies. Since some packages in the project may be outdated, use the --force flag:
npm install --force


If npm install (without --force) fails due to dependency conflicts such as ERESOLVE overriding peer dependency, use npm install --force to force the installation despite outdated packages.
Build the front-end application:
npm run build
The build may show some warnings — these can be safely ignored.

After the build completes, a build folder will be created. Upload it to the S3 bucket:
aws s3 cp build s3://fcaj-book-shop-by-myself --recursive

Replace fcaj-book-shop-by-myself with the actual bucket name you created in the previous step.
Open the Amazon S3 console, navigate to your bucket and check the Objects tab to confirm all files have been uploaded successfully.

Go to the Properties tab, scroll down to Static website hosting and copy the Bucket website endpoint.

Open the endpoint URL in your browser. You should see the FCJ Book Store website loaded successfully.

The website currently shows an empty page because we haven’t set up the backend (API Gateway + Lambda + DynamoDB) yet. We will complete this in the next sections.