0% found this document useful (0 votes)
21 views20 pages

LABS

aws labs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views20 pages

LABS

aws labs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Guided Lab: Amazon SageMaker

and Importing Data


Lab overview
In this lab, you will learn how to launch an Amazon SageMaker notebook
instance. From that instance, you will learn how to create a Jupyter notebook.
You will learn how to create code and Markdown cells within the notebook. You
will download data from an external source, then learn how to save your
notebook locally so you can continue working on labs across sessions.

Amazon SageMaker is a fully managed service that provides every developer


and data scientist with the ability to build, train, and deploy machine learning
(ML) models quickly. Amazon SageMaker removes the heavy lifting from each
step of the machine learning (ML) process to make it easier to develop high
quality models.

Objectives
After completing this lab, you will be able to:

 Launch an Amazon SageMaker notebook instance


 Launch a Jupyter notebook
 Run code in a notebook
 Download data from an external source
 Upload and download a Jupyter notebook to your local machine

Prerequisites
This lab requires:

 Access to a notebook computer with Wi-Fi and Microsoft Windows,


macOS, or Linux (Ubuntu, SUSE, or Red Hat)
 For Microsoft Windows users: Administrator access to the computer
 An internet browser such as Chrome, Firefox, or IE9 (previous versions of
Internet Explorer are not supported)

Duration
This lab takes approximately 30 minutes. The lab will remain active for 180
minutes

AWS services not used in this lab


In the lab environment, AWS services that are not used in this lab are disabled.
In addition, the capabilities of the services that are used in this lab are limited to
what the lab requires. Expect errors when you access other services or perform
actions beyond those provided in this lab.

Accessing the AWS Management Console


1. At the top of these instructions, choose Start Lab to launch your lab.

A Start Lab panel opens, which displays the lab status.

2. Wait until you see the message Lab status: ready, then close the Start Lab
panel by choosing the X.
3. At the top of these instructions, choose AWS

This will open the AWS Management Console in a new browser tab. The
system will automatically log you in.

Tip: If a new browser tab does not open, there will typically be a banner or
icon at the top of your browser that indicates that your browser is
preventing the website from opening pop-up windows. Select the banner
or icon and then choose Allow pop ups.

4. Arrange the AWS Management Console browser tab so that it displays


next to these instructions. Ideally, you should be able to see both browser
tabs at the same time, which can make it easier to follow the lab steps.

Task 1: Creating a Jupyter notebook with


Amazon SageMaker
In this task, you will access Amazon SageMaker in the AWS Management Console
and create a Jupyter notebook.

To create a Jupyter notebook with Amazon SageMaker:


5. On the AWS Management Console, on the Services menu, choose
Amazon SageMaker.
6. From the navigation menu on the left, expand the Notebook section and
choose Notebook instances.
7. Choose Create notebook instance.
8. In the Notebook instance name box, enter Mynotebook
9. From the Notebook instance type dropdown list, choose ml.m4.xlarge.
10.Now set the Platform identifier type to notebook-al2-v1, this ensures you
are using Amazon Linux 2 as operating system type for the notebook
instance. To learn more about notebook instances and the operating
system type options, please refer to Amazon Linux 2 vs Amazon Linux
notebook instances.
11.Under Additional configuration, choose the dropdown menu for
Lifecycle configuration and choose the lifecycle configuration that
contains ml-pipeline. This will automatically add the correct Jupyter
Notebooks to your Amazon SageMaker Notebook instance.
12.Leave the remaining settings at their default values.
13.Choose Create notebook instance.

Your new notebook is in the Notebook instances list with a status of


Pending. When the status changes to InService, you can continue to the
next step. While you are waiting for the status to change, you can read
more about Jupyter notebooks in either of the following references:

o Jupyter.org
o Jupyter Notebook Tutorial

It will take 2-5 minutes for the Notebook instance to start.

14.At the end of the row, choose Open JupyterLab to open the Jupyter
notebook instance.

Task 2: Introducing JupyterLab


In this task, you will explore the JupyterLab GUI on Amazon SageMaker and work
through a sample Jupyter notebook. Jupyter notebooks enable you to create and
share documents that contain both code and rich text elements, such as
equations.

15.In the JupyterLab GUI, open the folder for your desired language, then
open the PythonCheatSheeet.ipynb notebook file (which was
automatically uploaded to the JupyterLab IDE). The notebook will open in
a new tab in the editor.

The JupyterLab environment will look like the following image. You will
now examine at its components in detail.

The top includes the menu bar, which provides all the commands to
control the notebook and environment. It includes:

o File – Used to save, revert, or create a checkpoint for your


notebook.
o Edit – Edit your notebook structure, which includes the following
commands.
 Cut (Shortcut: x)
 Copy (Shortcut: c)
 Paste (Shortcut for Paste below: V)
 Delete (Shortcut: dd)
 Undo delete (Shortcut: z)
o View – Toggles different options for your notebook.
o Run – Commands to run the cells in the notebook.
o Kernel – Change the state of the kernel (or programming language)
that's used by the notebooks. Amazon SageMaker includes various
kernels based on Python, depending on frameworks you want to
use (for example, TensorFlow, Pytorch, and MXNet).
o Git – Commands to interact with a git repository (if you have one
that's configured to work with JupyterLab).
o Tabs – Commands to navigate the notebook tabs.
o Settings – Commands to change your JupyterLab preferences.
o Help – Information to help you use JupyterLab.

The left side of the screen (1) includes the navigation sidebar and the
main work area (2). The navigation sidebar contains the following tabs:

o – File browser

o – List of running kernels and terminals

o - Git repository viewer

o – JupyterLab command palette


o – Notebook tools

o – View the open tabs within the environment

o – View the headings of the notebook

o – List of SageMaker samples

The main work area in JupyterLab enables you to arrange documents


(such as notebooks, text files, and others) and other activities (such as
terminals, code consoles, and others) into panels of tabs that can be
resized or subdivided:

o Drag a tab to the center of a tab panel to move the tab to the panel.
o Subdivide a tab panel by dragging a tab to the left, right, top, or
bottom of the pane.

The work area has a single current activity. The tab for the current activity
is marked with a colored top border (blue by default).

The main work area has a toolbar, which changes depending on the type
of file that's open and in focus. The toolbar for a Jupyter notebook looks
like the following example:

1 – Save, insert, cut, copy, and paste.

2 – Run a cell, interrupt a cell, and restart the kernel button.

3 – A dropdown menu for changing the cell type. The run behavior of a
cell is determined by the cell's type. Cells include the following types.

o Code cells: The cells that take input in the form of code.
o Markdown cells: Cells that contain additional information as text
that's in a language called Markdown. The output of this cell is text
that's formatted similar to an HTML page. You will look at this cell in
the next task step.
o Raw NBconvert cells: Raw cells that don't give you an output.

4 – The kernel name and its running status. Solid indicates that code is
being run.

You can run code in the cell:


o On the keyboard by pressing SHIFT + ENTER
o In the toolbar by choosing | Run
o In the menu bar by choosing Cell > Run Cells

The first cell in the notebook is a Markdown cell. A Markdown cell uses
Markdown, which is a markup language with plaintext-formatting syntax.
It's often used to format readme files to create rich text and additional
documentation in the Jupyter notebook. You will now examine the
Markdown cell.

16.To look at how to structure a Markdown cell, double-click the cell to


inspect it.

For more information about how to structure Markdown, see the Jupyter
notebook Markdown documentation

17.Lastly, you have a code cell that you can use to run your code.

A notebook can run code in different languages, but it can only use one
kernel at a time. A code cell enables you to write code in a single block
with full-syntax highlighting. Each cell is run individually, and the order can
be found by using the number to the left of the cell In[<number>] . Similarly,
the output of that cell is given by Out[<number>] .

18.Run through this notebook one time, and then proceed to the next task.

Learn more To learn more about Jupyter notebooks, see the Jupyter notebook
documentation.

Task 3: Opening a sample notebook


In this task, you will browse through a provided sample notebook and familiarize
yourself with working in a Jupyter notebook.

19.In your JupyterLab environment, switch the left navigation view to the
Amazon SageMaker Samples.
20.Locate the sample named linear_learner_mnist.ipynb . Choose the sample to
load it into the main work area.
21.To create a copy, in the file header, choose the Create a Copy button and
in the dialog box, choose Create a Copy again.

The sample notebook will be copied to your JupyterLab environment.


Feel free to scroll through the notebook. However, be aware that you
won't be able to run the steps because an Amazon Simple Storage Service
(Amazon S3) bucket is required.

Task 4: Importing data


In this task, you will create a new notebook for your labs and add code to the
notebook that will download and extract the data that's used throughout the
remainder of the guided labs. For this task, you will enter code into the
notebook. However, in future tasks, you will work through an existing notebook
so you can save time by not typing.

The data you will use throughout the guided labs is a dataset that contains
medical data about the vertebral column. To learn more about this dataset, see
the Vertebral Column Dataset at the UC Irvine Machine Learning Repository.

To obtain, extract, and load the data into a pandas DataFrame:

22.In your JupyterLab environment, choose File > New and then choose
Notebook.
23.In the Select kernel dialog window, choose conda_python3 and then choose
Select.

You should have a blank code cell in the main work area. You will change
this blank cell to a Markup cell and add some text.

24.On the keyboard, press M. The cell type in the dropdown menu should
change to Markdown. If not, use the dropdown menu to change the cell
type.

Next, you will give your notebook a title. Remember that a notebook can contain
both code and Markdown.

25.Press ENTER and in the cell, enter the following text:

# Importing the data

26.To exit the cell and render the Markup, press SHIFT + ENTER.

Next, you must download the data from the internet. You will use a URL,
but the file is a .zip file. You could download the .zip file and extract it.
However, because the file is small, you can download the file to a stream.
You will then extract the files so you can save it locally.
Start by adding a few imports.

27.On the keyboard, press ENTER and then type the following code into the
cell:

import warnings, requests, zipfile, io


warnings.simplefilter('ignore')
import pandas as pd
from scipy.io import arff

28.Exit the cell without running the code by pressing ESC.

Next, add the code to download and extract the .zip file.

29.Add a cell below by pressing B.


30.Press ENTER and in the cell, enter the following code:

f_zip = 'http://archive.ics.uci.edu/ml/machine-learning-databases/00212/vertebral_column_data.zip'
r = requests.get(f_zip, stream=True)
Vertebral_zip = zipfile.ZipFile(io.BytesIO(r.content))
Vertebral_zip.extractall()

31.Exit the cell without running the code by pressing ESC.


32.Select the two code cells by holding SHIFT and choosing both cells. Both
cells should be highlighted, as shown in the following example.

33.Run the code in the two cells by pressing SHIFT + ENTER. If you have
errors because of spelling errors, fix them now.

In the file viewer in the left navigation pane, you should see four new files:
- column_2C_weka.arff - column_2C.dat - column_3C_weka.arff -
column_3C.dat

34.Load the files into the main working window by clicking each file. Examine
the data in these files. What format is the data in? Does the data have
column headings?
35.You will now load the data from the two classes file. Switch back to your
notebook, select the empty cell, press ENTER, and enter the following
code:

data = arff.loadarff('column_2C_weka.arff')
df = pd.DataFrame(data[0])
df.head()

36.This time, run the cell by pressing SHIFT + ENTER.


Task 5: Downloading your notebook and
saving your work (Optional)
When you are finished with the lab environment—or if the time allocated to the
lab environment expires—your SageMaker instance will be terminated, and you
will lose any notebooks you created. If the lab requires you to save your
notebook, the instructions will clearly indicate that you must do so. If you want
to save your notebook yourself, you can use these instructions.

37.In the file browser in the left navigation, right-click the file that you want to
save, then choose Download.
38.Next, choose the location where you want to save your file on your local
computer.
39.If you want to continue working on the notebook, start the lab
environment again, create your notebook instance, and upload the
notebook you downloaded.

Conclusion
You now have successfully:

 Launched an Amazon SageMaker notebook instance


 Launched a Jupyter notebook
 Ran code in a notebook
 Downloaded and extracted data from an external source

Lab complete
Congratulations! You have completed the lab.

40.To confirm that you want to end the lab, at the top of this page, choose
End Lab , and then choose Yes.

A panel should appear with this message: DELETE has been initiated... You may
close this message box now.

41.To close the panel, choose the X in the top-right corner.


Guided Lab: Amazon Forecast
Lab overview
In this lab, you will use Amazon Forecast to create a forecast for sales data. You
will start with the Online Retail II Data Set. This Online Retail II dataset contains
all the transactions occurring between January 12, 2009 and September 12, 2011
for a non-store, online retail organization that's registered and based in the
United Kingdom.The company mainly sells unique all-occasion giftware. Many
customers of the company are wholesalers.

Objectives
After completing this lab, you will be able to:

 Use pandas to prepare time series data


 Use Amazon Forecast to create a predictor
 Use an Amazon Forecast predictor to create a forecast
 Compare a forecast against test data

Prerequisites
This lab requires:

 Access to a notebook computer with Wi-Fi and Microsoft Windows,


macOS, or Linux (Ubuntu, SUSE, or Red Hat)
 For Microsoft Windows users: Administrator access to the computer
 An internet browser such as Chrome, Firefox, or IE9 (previous versions of
Internet Explorer are not supported)

Duration
This lab takes approximately 90 minutes. The lab will remain active for 180
minutes

AWS services not used in this lab


AWS services that are not used in this lab are disabled in the lab environment. In
addition, the capabilities of the services used in this lab are limited to what the
lab requires. Expect errors when you access other services or perform actions
beyond those provided in this lab guide.

Accessing the AWS Management Console


1. At the top of these instructions, choose Start Lab to launch your lab.

A Start Lab panel opens, which displays the lab status.

2. Wait until you see the message Lab status: ready, then close the Start Lab
panel by choosing the X.
3. At the top of these instructions, choose AWS

This will open the AWS Management Console in a new browser tab. The
system will automatically log you in.

Tip: If a new browser tab does not open, there will typically be a banner or
icon at the top of your browser that indicates that your browser is
preventing the website from opening pop-up windows. Select the banner
or icon and then choose Allow pop ups.

4. Arrange the AWS Management Console browser tab so that it displays


next to these instructions. Ideally, you should be able to see both browser
tabs at the same time, which can make it easier to follow the lab steps.

Task 1: Accessing a notebook instance in


Amazon SageMaker
In this task, you will connect to your JupyterLab environment.

To open JupyterLab:

5. On the AWS Management Console, on the Services menu, choose


Amazon SageMaker.
6. From the navigation menu, choose Notebook instances.
7. Look for the notebook instance that is named MyNotebook . Go to the end of
the row and open the JupyterLab notebook instance by choosing Open
JupyterLab.
Task 2: Opening a notebook in your
notebook instance
In this task, you will open the notebook for this lab.

8. In your JupyterLab environment, go to the file browser in the left pane and
locate the forecast-lab.ipynb file.
9. Open the en_us/forecast-lab.ipynb file by choosing it.

Tip: If a window appears asking you to select a kernel, select


conda_python3, then choose Select.

10.Follow the instructions in the notebook.

Conclusion
You now have successfully:

 Used pandas to prepare time series data


 Used Amazon Forecast to create a predictor
 Used an Amazon Forecast predictor to create a forecast
 Compared a forecast against test data

Lab complete
Congratulations! You have completed the lab.

11.To confirm that you want to end the lab, at the top of this page, choose
End Lab , and then choose Yes.

A panel should appear with this message: DELETE has been initiated... You may
close this message box now.

12.To close the panel, choose the X in the top-right corner.

�2020 Amazon Web Services, Inc. and its affiliates. All rights reserved. This work may
not be reproduced or redistributed, in whole or in part, without prior written
permission from Amazon Web Services, Inc. Commercial copying, lending, or selling is
prohibited.
Guided Lab: Natural Language
Processing
Lab overview
Natural language processing (NLP) is a common use case for machine learning (ML).
In this lab, you will learn how to use Amazon Lex to create a chatbot that users can interact
with to create a dental appointment.
The high-level steps you will perform are:
 Create and test a bot by using the Amazon Lex ScheduleAppointment blueprint
 Create and test an AWS Lambda function to perform initiation, validation, and
fulfillment tasks
 Configure the MakeAppointment intent to use your Lambda function as a code hook
 Test the bot in the console and through a static webpage that is hosted on Amazon
Simple Storage Service (Amazon S3)

Objectives
After completing this lab, you will be able to:
 Create and test a bot by using Amazon Lex
 Create a Lambda function and configure it to work with Amazon Lex
 Create a static webpage in Amazon S3 to host the bot
 Interact with the bot in the webpage

Prerequisites
This lab requires:
 Access to a notebook computer with Wi-Fi and Microsoft Windows, macOS, or Linux
(Ubuntu, SUSE, or Red Hat)
 For Microsoft Windows users: Administrator access to the computer
 An internet browser such as Chrome, Firefox, or IE9 (previous versions of Internet
Explorer are not supported)

Duration
This lab requires 60 minutes to complete. The lab will remain active for 180 minutes.

Accessing the AWS Management Console


1. At the top of these instructions, choose Start Lab to launch your lab.
A Start Lab panel opens, which displays the lab status.
2. Wait until you see the message Lab status: ready, then close the Start Lab panel by
choosing the X.
3. At the top of these instructions, choose AWS
This will open the AWS Management Console in a new browser tab. The system will
automatically log you in.
Tip: If a new browser tab does not open, there will typically be a banner or icon at the top of
your browser that indicates that your browser is preventing the website from opening pop-up
windows. Select the banner or icon and then choose Allow pop ups.
4. Arrange the AWS Management Console browser tab so that it displays next to these
instructions. Ideally, you should be able to see both browser tabs at the same time,
which can make it easier to follow the lab steps.

Scenario summary
The following diagram illustrates the environment that you will build in this lab:

Task 1: Creating a bot with Amazon Lex


In this task, you will create a bot by using the AWS Management Console.
To create a bot with Amazon Lex:
5. On the AWS Management Console, on the Services menu, choose Amazon Lex.
6. On the Amazon Lex page, choose Get Started.
7. In the left navigation pane, choose Return to the V1 console.
8. Choose Create.
9. On the Create your bot page, choose the ScheduleAppointment blueprint.
10. For the Language section, select English (US).
11. For the COPPA section, select No.
12. Choose Create.

Task 2: Testing your bot


Now, you will test your bot by using the test window in the console.
13. When you see the status Ready Build complete, test your bot by entering the following
values:

 I would like to make an appointment


 A root canal
 5/1/2020
 4:00 PM
 Yes

You should see the following confirmation.

Task 3: Creating an AWS Lambda function


14. On the AWS Management Console, on the Services menu, choose Lambda.
15. Choose Create a function.
16. Choose the Use a blueprint tab.
17. In the search box, filter for Amazon Lex blueprints by entering Lex .
18. Open the Make an appointment with Lex blueprint by selecting it.
19. For the Function name, enter MakeAppointmentCodeHook .
20. For the Execution role, select Create a new role from AWS policy templates.
21. For the Role name, enter myLexrole .
Take a few minutes to review the Python code in the function.
22. Choose Create function.
When your function is ready, it should be in the Lambda Designer window.
!

Task 4: Testing your Lambda function


23. On the Designer page, choose Test.
24. On the Test event page, for the name of the event, enter MyMakeAppointmentEvent .
25. Choose Save.
26. Choose Test.
You see the message: Execution result: succeeded. You can examine the details of the test by
expanding the Details section.

Task 5: Updating the intent of your bot


Each bot you create in Amazon Lex has an intent. The intent is an action that the bot will
fulfill. In this task, you will update the intent to use the AWS Lambda function that you
created.
27. On the AWS Management Console, on the Services menu, choose Amazon Lex. In
the left navigation pane, choose Return to the V1 console.
28. From the Bots list, select the ScheduleAppointment bot that you created in Task 1.
29. Expand the Lambda initialization and validation section.
30. Select the Initialization and validation code hook option.
31. From the dropdown menu, select MakeAppointmentCodeHook.
You should get a message that you are going to give Amazon Lex permission to invoke your
Lambda function.
32. Choose OK.
In addition to adding the code for initializing the bot, you must also add code to fulfill the
request.
33. In the Fulfillment section, choose the AWS Lambda function radio button.
34. From the dropdown list of Lambda functions, select MakeAppointmentCodeHook.
35. Choose Save Intent.

Task 6: Building and testing your bot


Now, you will test your bot to make sure that it uses the Lambda function.
36. Select Build.
You are prompted with a message that says that you can continue to edit your bot while it
builds.
37. Select Build.
After the build is complete, you should receive a confirmation that your bot build was
successful.
38. Test your bot by entering the following details.
 Enter Make an appointment
 Select root canal.
 Select one of the times that are displayed. If you select any of the available times and
do not get a prompt to confirm the appointment, continue to the next step.
 Confirm the appointment by selecting yes.
Now that you have a working version of your bot, you must publish it so that you can test it
by calling it from a webpage.
39. Choose Publish.
40. For your bot's alias, enter a unique name.
41. Choose Publish.
After the bot finishes publishing, you should get a confirmation notification. Make a note of
the alias because you will need it in the next task.

Incorporating your bot into a webpage


Now that your bot is working, it's time to test it by running it from a webpage. The easiest
way to do the test is to create a static webpage and host it on Amazon S3. The webpage will
invoke the Amazon Lex API to load your bot. Visitors to the webpage can then interact with
it.

Task 7: Setting up an Amazon Cognito identity pool


You will now set up a webpage for testing your appointment bot. This webpage will be
hosted in Amazon S3 as a static webpage. To add security to this page, you must first set up
an Amazon Cognito identity pool.
To set up the identity pool:
42. On the AWS Management Console, on the Services menu, choose Cognito.
43. In the Amazon Cognito navigation pane at the left, choose Identity pools.
44. Choose Create identity pool. Choose Guest access. Choose Next.
45. For IAM role name use myidentitypoolrole . Choose Next. For Name use
myidentitypool .
46. Choose Next. Choose Create identity pool. Expand the View Details section.
47. Select the myidentitypool .
48. Under Identity pool overview.
49. Make a note of the IdentityPoolID because you will need this ID later in the lab.

Task 8: Modifying IAM roles to allow access to Amazon Lex


The webpage that hosts your bot must be allowed to access Amazon Lex. To do this, the two
roles that were created in the Amazon Cognito identity pool need permissions to access
Amazon Lex. You must configure AWS Identity and Access Management (IAM) to grant
these permissions to the identity pool roles.
50. On the AWS Management Console, on the Services menu, choose IAM.
51. Choose Roles.
52. Search for myidentitypoolrole.
53. From the list of search results, select the role that you created.
54. Choose Add permissions.
55. Choose Attach policies.
56. In the search box, enter AmazonLex .
57. Select the AmazonLexReadOnly and AmazonLexRunBotsOnly policies.
58. Choose Add permissions.

Task 9: Creating an S3 bucket


Now that you set up the security permissions, you must create an S3 bucket to host your
webpage.
59. First, download the following two webpage files and extract them to a local file
directory.
 index.html
 error.html
The index.html file includes the script that will load your bot.
Download the .zip file.
60. On the AWS Management Console, on the Services menu, choose S3.
61. On the Amazon S3 page, choose Create bucket.
62. Enter a name for your bucket. Because all S3 bucket names must be unique, try
entering lexlab6 and six random letters.
63. Select Create bucket.
64. On the Buckets page, select the bucket that you just created.
65. On the Bucket overview page, select Upload.
66. On the Upload page, select Add files.
67. Browse to the location for the index.html and error.html files that you downloaded
previously.
68. Select both files, and then select Upload.
69. After the upload is complete, return to the Bucket overview page by selecting Close.
70. On the Properties tab, scroll down to the Static website hosting section and select
Edit.
71. Select Enable.
72. For the Index document, enter: index.html
73. For the error page, enter: error.html
74. Choose Save changes.

Task 10: Updating and testing the demonstration file


You must now update the demonstration HTML file so that it uses the Amazon Cognito
identity pool that you created in Task 6.
Use a text editor to make the following changes to the HTML page.
75. On line 144 of the script, add the IdentitypoolID for the identity pool that you created
in Task 6.
76. On lines 185 and 186 of the script, add the botAlias and botName for your bot.
77. Save your updated HTML page locally.
78. Choose the Objects tab for the bucket that you created in Task 9.
79. Choose Upload and upload the HTML file that you edited.
80. Choose Close to close the Upload page.
81. Choose the Permissions tab.
82. In the Block public access section, choose Edit.
83. Clear the following options:
 Block all public access
84. Choose Save changes.
85. In the confirmation dialog box, enter Confirm and then choose Confirm.
86. In the Bucket policy section, choose Edit.
87. To grant public read access to the webpage, copy the following bucket policy. In the
Bucket policy editor, paste the policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::example.com/*"
]
}
]
}

88. In the Resource part of the policy, edit the value of the Amazon Resource Name
(ARN) by replacing example.com with the name of your bucket.
89. Choose Save changes. You will get a warning that the bucket has public access.
90. Choose the Properties tab.
91. Scroll down to the Static website hosting section.
92. At the bottom of the Static website hosting section, choose the URL.
Your webpage opens, and you can interact with your bot like you did in the AWS
Management Console.

Conclusion
You now have successfully created a bot with Amazon Lex and tested it in a webpage.

Lab complete
Congratulations! You have completed the lab.

93. To confirm that you want to end the lab, at the top of this page, choose End Lab , and
then choose Yes
A panel should appear with this message: DELETE has been initiated... You may close this
message box now.
94. To close the panel, choose the X in the top-right corner.
©2020 Amazon Web Services, Inc. and its affiliates. All rights reserved. This work may not
be reproduced or redistributed, in whole or in part, without prior written permission from
Amazon Web Services, Inc. Commercial copying, lending, or selling is prohibited.

You might also like