Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted download addressables from aws S3 bucket (not public)

Discussion in 'Addressables' started by elfasito, Jun 22, 2021.

  1. elfasito

    elfasito

    Joined:
    Jul 4, 2017
    Posts:
    28
    Hello people, I need to download files from s3 private bucket using addressables system.
    I see a lot of guides about S3 and addressables working, but all set the bucket as public, so Anybody can download, thats dont is what I need.
    I want to download a addressable scene from a bucket in S3 only for my cognito authenticated users.
    I already have configurated my aws backend (I think).

    for example from unity I can execute this function:
    Code (CSharp):
    1. public async void ExecuteLambda()
    2.     {
    3.         Debug.Log("ExecuteLambda actually S3 test");
    4.  
    5.         S3Client = new AmazonS3Client(_authenticationManager.GetCredentials(), AuthenticationManager.Region);
    6.  
    7.         ListObjectsRequest request = new ListObjectsRequest
    8.         {
    9.             BucketName = _s3BucketName,
    10.             MaxKeys = 10
    11.         };
    12.  
    13.         ListObjectsResponse response = await S3Client.ListObjectsAsync(request);
    14.         Debug.Log("Response code: " + response.HttpStatusCode);
    15.  
    16.         foreach (S3Object entry in response.S3Objects)
    17.         {
    18.             Debug.Log("key = " + entry.Key + " size = " + entry.Size);
    19.         }
    20.     }
    and that list the objects what I have in my private bucket. (only a authenticated user can see the bucket).

    but if I try to download a file/scene with addressables system I get:
    UnityWebRequest result : ProtocolError : HTTP/1.1 403 Forbidden
    ResponseCode : 403, Method : GET


    this is my function for download a bundle: (not working)
    Code (CSharp):
    1. public async void ExecuteLambda2()
    2.     {
    3.         Debug.Log("ExecuteLambda actually S3 test");
    4.  
    5.         S3Client = new AmazonS3Client(_authenticationManager.GetCredentials(), AuthenticationManager.Region);
    6.  
    7.         ListObjectsRequest request = new ListObjectsRequest
    8.         {
    9.             BucketName = _s3BucketName,
    10.             MaxKeys = 10
    11.         };
    12.  
    13.         ListObjectsResponse response = await S3Client.ListObjectsAsync(request);
    14.         Debug.Log("Response code: " + response.HttpStatusCode);
    15.  
    16.         var locations = await Addressables.LoadResourceLocationsAsync(SceneToLoad).Task;
    17.  
    18.         foreach (var location in locations)
    19.             await Addressables.InstantiateAsync(location).Task;
    20.     }
    can someone give me a hint about what im doing wrong?.

    PD: if I set the s3 bucket as public access, I can download the bundles, so I think I need to call addressables system using my aws credentials (no clue about how)
     
  2. ImmotionPeter

    ImmotionPeter

    Joined:
    Sep 15, 2020
    Posts:
    34
    Bumping this thread because we want to do the same thing.

    How do we use addressables and S3 buckets set to private?
     
  3. TeachingComJeff

    TeachingComJeff

    Joined:
    Mar 27, 2020
    Posts:
    1
    Any answers to this? We need the same issue resolved.
     
  4. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,698
    I'll flag with the team for some guidance!
     
    KingKRoecks likes this.
  5. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    356
  6. unity_krista

    unity_krista

    Unity Technologies

    Joined:
    Apr 28, 2020
    Posts:
    27
    @nilsdr is correct that used to be the only way to do what you're trying to do.

    However starting in Addressables 1.19.0, you can assign a function to the Addressables object's WebRequestOverride property to individually modify the UnityWebRequest from which is used to download files, such as an AssetBundle or catalog json file.

    You must assign the function before the relevant operation starts, otherwise the default UnityWebRequest is used.
    The ResourceManager calls your WebRequestOverride function before UnityWebRequest.SendWebRequest is called, passing the UnityWebRequest for the download to your function.

    I believe something like this should help you with AWS S3 authenticating requests:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using UnityEngine.AddressableAssets;
    4.  
    5. public class WebRequestOverride : MonoBehaviour
    6. {
    7.     private string AWSauthorizationToken;
    8.  
    9.     //Register to override WebRequests Addressables creates
    10.     //The UnityWebRequests will default to the standard behaviour
    11.     private void Start()
    12.     {
    13.         Addressables.WebRequestOverride = EditWebRequestURL;
    14.     }
    15.  
    16.     //Override the url of the WebRequest
    17.     private void EditWebRequestURL(UnityWebRequest request)
    18.     {
    19.         request.SetRequestHeader("Authorization", AWSauthorizationToken);
    20.     }
    21. }
    For getting your authentication token to use, I think this page on AWS documentation will help
     
    nilsdr likes this.
unityunity