Front-end Deployment

As the first step of this workshop, we will host the web application (front-end) with S3 Static website hosting:

  1. Open the Amazon S3 console

S3Console

  1. Click Create bucket

CreateBucket

  1. Configure the bucket as follows:
  • Keep the default General purpose for Bucket type
  • For Bucket namespace, select Account Regional namespace (recommended)
  • Enter a name for the bucket, for example: fcajdmswebstore

CreateBucket

In this workshop, we select Account Regional namespace (recommended) so that the bucket name only needs to be unique within your AWS account and Region, instead of globally unique. Amazon S3 automatically appends a suffix containing the account ID and Region to the bucket name, so you can use the name fcajdmswebstore without worrying about conflicts with other users. Be sure to note down the full bucket name (including the suffix) after it is created, because we will use it again in later steps.

If you select Global namespace, the bucket name must be globally unique. If the name fcajdmswebstore is already taken, add a suffix, for example: fcajdmswebstore-<your-name>.

  1. Uncheck Block all public access
  • Check I acknowledge that the current settings might result in this bucket and the objects within becoming public

CreateBucket

  1. Click the Create bucket button

CreateBucket

  1. In the bucket you just created, go to the Properties tab

SettingBucket

  1. Scroll down to the bottom of the page, click Edit in the Static website hosting section

SettingBucket

  1. Configure static website hosting as follows:
  • Select Enable to enable static website hosting on S3
  • Select Host a static website for Hosting type
  • Enter index.html for Index document
  • Enter index.html for Error document

SettingBucket

The web application is a Single Page Application. Paths such as /document or /profile are handled by the application; they are not files on S3. Setting the Error document to index.html lets you reload the page at these paths without a 404 error.

  1. Click the Save changes button

SettingBucket

  • After it is enabled successfully, note down the web URL in the Bucket website endpoint section

SettingBucket

  1. Next, we need to add a policy to the S3 bucket so that the website can be accessed:
  • Select the Permissions tab
  • Click the Edit button in the Bucket policy section

SettingBucket

  1. Copy the following into the Policy section
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::BUCKET_NAME/*"
        }
    ]
}
  • Replace BUCKET_NAME with the name of your bucket, then click the Save changes button

SettingBucket

  1. Next, run the following commands in the root folder of the FCAJ-Serverless-DMS project that you used in workshop 134 to build the application and upload it to the S3 bucket:
npm run build
aws s3 cp dist s3://BUCKET_NAME --recursive

SettingBucket

  • Replace BUCKET_NAME with the name of your bucket
  • The npm run build command creates the dist folder that contains the built application. The application uses the amplify_outputs.json file created in workshop 134 to connect to Amazon Cognito and S3, so you do not need to run npx ampx sandbox again.

If the upload fails, configure the access key ID, secret access key, region ap-southeast-1 and output format with the aws configure command

The result after uploading:

SettingBucket

  1. Paste the web URL you just noted down into your web browser. You can sign in with the email and password you registered in workshop 134.

SettingBucket

We have not created the API yet, so you will see errors in the browser Console when the application gets the document list. This is expected; we will create the API in the next section.

You have finished hosting your website on S3. In the next section, we will update the Lambda function of workshop 133 and create API Gateway.