Step 1: Prepare a
Test File for Download

The following procedure shows you how to upload a file to Amazon S3 that you can later
download with a Script Canvas script.

To prepare a test file for download from Amazon S3

In a text editor, create a plain text file and save it as
downloadtest.txt.

In a text editor, open the
lumberyard_version\dev\Cache\CloudGemSamples\pc\user\AWS\user-settings.json
file.

In the user-settings.json file, locate the Amazon S3 name for
for the CloudGemAWSScriptBehaviors.s3nodeexamples bucket. The Amazon S3
bucket name is in the string for the PhysicalResourceId attribute,
as in the following example:

In the Amazon S3 management console, open the bucket that you identified in step
3.

Click Upload to upload the
downloadtest.txt to the bucket that is mapped to
CloudGemAWSScriptBehaviors.s3nodeexamples.

Step 2: Add Nodes
to Download a File from Amazon S3

Now you can create a Script Canvas script that downloads the file.

To create a Script Canvas script to download a file from Amazon S3

In Lumberyard Editor, click Tools,
Script Canvas.

In the Node Palette, expand
Utilities and drag On Graph Start
to the canvas.

On the right, in Variable Manager, click Create
Variable.

In the Variable Type search box, enter
AWSBehaviorS3Download, or scroll down to
AWSBehaviorS3Download.

Click AWSBehaviorS3Download. In Node
Inspector, AWSBehaviorS3DownloadVariable appears. The default name of the variable is
Variable 1.

In Node Inspector, expand
AWSBehaviorS3Download to show the input fields. Type
the values in the following table into the corresponding boxes.

Input Field

Value

BucketName

CloudGemAWSBehavior.s3nodeexamples

KeyName

downloadtest.txt

LocalFileName

s3downloadtest.txt

ContentType

text/html

From the Variable Manager, press
Shift and drag Variable 1
AWSBehaviorS3Download to the canvas to create the Get
Variable 1 node. (You can also drag
AWSBehaviorS3Download to the canvas and then select
Get Variable from the drop-down menu.)

Connect the Out pin of the On Graph
Start node to the In pin of the
Get Variable 1 node.

In the Node Palette, expand AWS,
AWSBehaviorS3Download.

Drag the Download node to the right of the Get
Variable 1 node on the canvas.

Connect the Out pin of the Get Variable
1 node to the In pin of the
Download node.

Connect the AWSBehaviorS3Download pin of the
Get Variable 1 node to the
AWSBehaviorS3Download:0 pin of the
Download node.

Step 3: Add
Nodes to Display the Result

Next, to see the success or failure of the operation, you add
AWSBehaviorS3DownloadNotificationBus nodes and a
Print node to the graph. The nodes monitor for
AWSBehaviorS3DownloadNotificationBus events and show you the result in
the Lumberyard console window.

To display the success or failure of the download operation in the console
window

Drag OnError to the canvas and place the node under the
three nodes that are already connected.

Drag OnSuccess to the canvas and place it under the
OnError node.

In the Node Palette, expand
Utilities, Debug and drag
Print to the right of the two
AWSBehaviorS3DownloadNotificationBus nodes on the
canvas. The Print node displays messages in the Lumberyard Editor
console.

Connect the Out pins of the
AWSBehaviorS3DownloadNotificationBusOnError and OnSuccess nodes to the
In pin of the Print node.

Connect the String pins of the
AWSBehaviorS3DownloadNotificationBusOnError and OnSuccess nodes to the
Value pin on the Print node. Your
canvas should look similar to the following image:

Save the canvas with a name like
MyS3DownloadTest.scriptcanvas. The default file
location is the
lumberyard_version\dev\project_name\scriptcanvas
directory.

Exit the Script Canvas editor.

Step 4: Test Download
the File from Amazon S3

Now you are ready to attach the script canvas to an entity and test it.

To test downloading a file from Amazon S3

In Lumberyard Editor, right-click the viewport and choose Create
entity.

In Entity Inspector, click Add
Component.

Under Scripting, click
Script Canvas to add a Script Canvas component to the
entity.

Under Script Canvas, click the browse button
(...).

In the Pick Script Canvas dialog box, choose the canvas
that you created - for example, mys3downloadtest (Script
Canvas), and then click OK.

If the Lumberyard console window is not already open, press ~ or choose
Tools, Console to open the console
window. If the console window is already open and you want to clear it, press
Ctrl+Shift+C.

Press Ctrl+G to start the level. The console reports the
success of the operation as follows.

(Script Canvas) - File Downloaded

The file s3downloadtest file is downloaded to the
lumberyard_version\dev
directory.

Javascript is disabled or is unavailable in your browser.

To use the AWS Documentation, Javascript must be enabled. Please refer to your browser's
Help pages for instructions.