IN THIS ARTICLE
Generating an Amazon S3 Presigned URL With Script Canvas
Generating an Amazon S3 Presigned URL With Script Canvas
You can use presigned URLs to share Amazon S3 objects with others. The Presign node in Script Canvas generates a presigned URL that links to an Amazon S3 object that you specify.
Add Nodes that Generate a Presigned URL
To use the Presign node to presign a URL
Upload a plain text file named
presigntest.txt
to thes3nodeexamples
bucket.In Lumberyard Editor, choose Tools, Script Canvas.
In the Node Palette, expand Utilities and drag On Graph Start to the canvas.
In Variable Manager, click Create Variable.
In the Variable Type search box, enter AWSBehaviorS3Presign, or scroll down to AWSBehaviorS3Presign.
Click AWSBehaviorS3Presign. In Node Inspector, AWSBehaviorS3Presign Variable appears. The default name of the variable is Variable 1.
In Node Inspector, expand AWSBehaviorS3Presign to show the input fields. Type or choose the values in the following table.
[See the AWS documentation website for more details]
From the Variable Manager, press Shift and drag Variable 1 AWSBehaviorS3Presign to the canvas to create the Get Variable 1 node. (You can also drag AWSBehaviorS3Presign 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, AWSBehaviorS3Presign.
Drag the Presign 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 Presign node.
Connect the AWSBehaviorS3Presign pin of the Get Variable 1 node to the AWSBehaviorS3Presign:0 pin of the Presign node.
Add Nodes to Display the Result
Next, to see the success or failure of the operation, you add AWSBehaviorS3PresignNotificationBus nodes and a Print node to the graph. The nodes monitor for AWSBehaviorS3PresignNotificationBus
events and show you the result in the Lumberyard console window.
To display the success or failure of the presign operation in the console window
In the Node Palette, expand AWS, AWSBehaviorS3PresignNotificationBus.
Drag OnError to the canvas. 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 AWSBehaviorS3PresignNotificationBus nodes on the canvas. The Print node displays messages in the Lumberyard Editor console.
Connect the Out pins of the AWSBehaviorS3PresignNotificationBus OnError and OnSuccess nodes to the In pin of the Print node.
Connect the String pins of the AWSBehaviorS3PresignNotificationBus OnError 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
MyS3PresignTest.scriptcanvas
. The default file location is thelumberyard_version\dev\project_name\scriptcanvas
directory.Exit the Script Canvas editor.
Test Generate a Presigned URL
Now you are ready to attach the script canvas to an entity and test it.
To test the presigned Amazon S3 URL
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, mys3presigntest (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 in the following example.
(Script Canvas) - https://s3.amazonaws.com//presigntest.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential={string}