In this section, we will add the S3 bucket that hosts the web application to the SAM template, connect the FCAJ-Serverless-DMS application to the Cognito resources and the S3 bucket we just created, then test the sign-up and sign-in features.
# S3 bucket that hosts the web application (static website hosting)
FcajDMSWebStore:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "fcajdmswebstore-${AWS::AccountId}-${AWS::Region}-an"
BucketNamespace: account-regional
PublicAccessBlockConfiguration:
BlockPublicAcls: true
IgnorePublicAcls: true
BlockPublicPolicy: false
RestrictPublicBuckets: false
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html
FcajDMSWebStorePolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref FcajDMSWebStore
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: PublicReadGetObject
Effect: Allow
Principal: "*"
Action: s3:GetObject
Resource: !Sub "${FcajDMSWebStore.Arn}/*"
fcajdmswebstore-<ACCOUNT_ID>-ap-southeast-1-an, the same as the bucket you created in workshop 135.index.html as the Index document and the Error document. The application is a Single Page Application, so when you reload a page at a path such as /document or /profile, S3 returns index.html instead of a 404 error.
WebStoreBucket:
Description: S3 bucket that hosts the web application
Value: !Ref FcajDMSWebStore
WebsiteURL:
Description: S3 static website URL
Value: !GetAtt FcajDMSWebStore.WebsiteURL

sam build
sam deploy
y when asked Deploy this changeset?

aws cloudformation describe-stacks --stack-name fcajdms --query "Stacks[0].Outputs" --output table
If you do not have the FCAJ-Serverless-DMS folder on your computer, run the following commands:
git clone https://github.com/Hieu192/FCAJ-Serverless-DMS.git
cd FCAJ-Serverless-DMS
npm install
{
"version": "1.3",
"auth": {
"aws_region": "ap-southeast-1",
"user_pool_id": "USER_POOL_ID",
"user_pool_client_id": "USER_POOL_CLIENT_ID",
"identity_pool_id": "IDENTITY_POOL_ID",
"mfa_methods": [],
"standard_required_attributes": ["email"],
"username_attributes": ["email"],
"user_verification_types": ["email"],
"groups": [],
"mfa_configuration": "NONE",
"password_policy": {
"min_length": 8,
"require_lowercase": true,
"require_numbers": true,
"require_symbols": true,
"require_uppercase": true
},
"unauthenticated_identities_enabled": true
},
"storage": {
"aws_region": "ap-southeast-1",
"bucket_name": "DOCUMENT_STORE_BUCKET"
}
}
USER_POOL_ID with the UserPoolId valueUSER_POOL_CLIENT_ID with the UserPoolClientId valueIDENTITY_POOL_ID with the IdentityPoolId valueDOCUMENT_STORE_BUCKET with the DocumentStoreBucket value
The amplify_outputs.json file left from workshop 134 points to the Amplify sandbox that was deleted in the cleanup of workshop 135, so you must replace the whole content of the file. Do not run npx ampx sandbox again in this workshop; that command recreates an Amplify backend and overwrites amplify_outputs.json with the information of another User Pool. If the application shows a message asking you to run npx ampx sandbox, it means the application cannot find amplify_outputs.json; check the name and the location of the file.
The values in amplify_outputs.json are not secrets; they end up in the JavaScript code of the application after the build. The file is already listed in the .gitignore of the project, so it is not pushed to Git.
npm run build
aws s3 cp dist s3://WEB_STORE_BUCKET --recursive
WEB_STORE_BUCKET with the WebStoreBucket value, for example: aws s3 cp dist s3://fcajdmswebstore-111122223333-ap-southeast-1-an --recursivenpm run build command creates the dist folder that contains the application built with the information in amplify_outputs.json. If you change this file, build and upload again.

We have not created the API yet, so you will see errors in the browser Console when the application fetches the document list. This is expected; we will create the API in part 2.
adminAdmin@123
The password must have at least 8 characters with uppercase, lowercase, number and special characters, matching the password policy you declared for the User Pool in part 1.1.












You have hosted the web application on S3, authenticated users with Cognito and prepared the S3 bucket that stores documents with AWS SAM. In the next part, we will set up the DynamoDB table, the Lambda functions and the REST API of the application.