Trong phần này, chúng ta sẽ thêm S3 bucket host ứng dụng web vào SAM template, kết nối ứng dụng FCAJ-Serverless-DMS với Cognito và S3 bucket vừa tạo, sau đó kiểm tra tính năng đăng ký, đăng nhập.
# 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, giống bucket bạn đã tạo ở workshop 135.index.html. Ứng dụng là một Single Page Application, nên khi tải lại trang ở các đường dẫn như /document hay /profile, S3 trả về index.html thay vì lỗi 404.
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 khi được hỏi Deploy this changeset?

aws cloudformation describe-stacks --stack-name fcajdms --query "Stacks[0].Outputs" --output table
Nếu chưa có thư mục FCAJ-Serverless-DMS trên máy, hãy chạy các câu lệnh sau:
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 bằng giá trị UserPoolIdUSER_POOL_CLIENT_ID bằng giá trị UserPoolClientIdIDENTITY_POOL_ID bằng giá trị IdentityPoolIdDOCUMENT_STORE_BUCKET bằng giá trị DocumentStoreBucket
Tệp amplify_outputs.json còn lại từ workshop 134 trỏ tới sandbox Amplify đã bị xoá ở phần dọn dẹp của workshop 135, vì vậy bạn phải thay toàn bộ nội dung của tệp. Không chạy lại npx ampx sandbox trong bài này, câu lệnh đó tạo lại backend Amplify và ghi đè tệp amplify_outputs.json bằng thông tin của một User Pool khác. Nếu ứng dụng hiển thị thông báo yêu cầu chạy npx ampx sandbox, nghĩa là ứng dụng không tìm thấy tệp amplify_outputs.json, hãy kiểm tra lại tên và vị trí của tệp.
Các giá trị trong tệp amplify_outputs.json không phải là thông tin bí mật, chúng được đưa vào mã JavaScript của ứng dụng sau khi build. Tệp này đã có trong .gitignore của project nên sẽ không được đẩy lên Git.
npm run build
aws s3 cp dist s3://WEB_STORE_BUCKET --recursive
WEB_STORE_BUCKET bằng giá trị WebStoreBucket, ví dụ: aws s3 cp dist s3://fcajdmswebstore-111122223333-ap-southeast-1-an --recursivenpm run build tạo thư mục dist chứa ứng dụng đã được build với thông tin trong tệp amplify_outputs.json. Nếu bạn sửa tệp này, hãy build và tải lên lại.

Chúng ta chưa tạo API nên bạn sẽ thấy lỗi trong Console của trình duyệt khi ứng dụng lấy danh sách tài liệu. Đây là điều bình thường, chúng ta sẽ tạo API ở phần 2.
adminAdmin@123
Mật khẩu phải có ít nhất 8 ký tự, gồm chữ hoa, chữ thường, chữ số và ký tự đặc biệt, đúng với chính sách mật khẩu mà bạn đã khai báo cho User Pool ở phần 1.1.












Bạn đã hoàn thành việc host ứng dụng web trên S3, xác thực người dùng với Cognito và chuẩn bị S3 bucket lưu tài liệu bằng AWS SAM. Sang phần tiếp theo, chúng ta sẽ thiết lập bảng DynamoDB, các hàm Lambda và REST API cho ứng dụng.