Lumberyard
User Guide (Version 1.15)

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

  1. Upload a plain text file named presigntest.txt to the s3nodeexamples bucket.

  2. In Lumberyard Editor, choose Tools, Script Canvas.

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

  4. In Variable Manager, click Create Variable.

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

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

  7. In Node Inspector, expand AWSBehaviorS3Presign to show the input fields. Type or choose the values in the following table.

    Input Field Value
    BucketName CloudGemAWSBehavior.s3nodeexamples
    KeyName presigntest.txt
    RequestMethod GET
    ContentType text/html
  8. 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.)

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

  10. In the Node Palette, expand AWS, AWSBehaviorS3Presign.

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

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

  13. 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

  1. In the Node Palette, expand AWS, AWSBehaviorS3PresignNotificationBus.

  2. Drag OnError to the canvas. Place the node under the three nodes that are already connected.

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

  4. 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.

  5. Connect the Out pins of the AWSBehaviorS3PresignNotificationBus OnError and OnSuccess nodes to the In pin of the Print node.

  6. 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:

    
                        A Script Canvas graph that presigns a URL for an object in
                            Amazon S3
  7. Save the canvas with a name like MyS3PresignTest.scriptcanvas. The default file location is the lumberyard_version\dev\project_name\scriptcanvas directory.

  8. 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

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

  2. In Entity Inspector, click Add Component.

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

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

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

  6. 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.

  7. 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}