0

I'm trying to get a static website hosted in AWS S3 to be the only way to download/view files from another S3 bucket.

Is this possible?

I've implemented a solution with a custom nodejs backend to do the validation and send the file to the front-end but I think this would be more expensive in the long run.

9
  • I believe you'll have to create an access key (docs.aws.amazon.com/general/latest/gr/…). Seeing as you have a Node JS backend, you'll have to use the AWS Node.js API to retrieve the file from AWS within your backend (stackoverflow.com/questions/16799956/…). Then you can forward the file to the client from there. Commented Jan 7, 2021 at 21:38
  • 1
    Although I suppose temporary URLs could be slightly useful in this scenario, depending on the reason as to why you don't want to use a server in the middle in the first place, and why you want to restrict access to public static content in the first place. If you're just trying to save yourself time on writing a backend, then temporary URLs won't help you. If you just want to keep track of certain custom metrics that S3 doesn't do by default, then forwarding through a server or using temporary URLs will both solve your problem, each with their own tradeoffs. Commented Jan 7, 2021 at 22:23
  • 1
    Bandwidth was one of the tradeoffs I was referring to. If the content is relatively small, latency could also be an issue, which is the other end of the tradeoff. With temporary URLs, the flow is as follows : client -> backend -> aws -> backend -> client -> aws -> client (a client/backend round trip, backend/aws round trip, and client/aws round trip). With forwarding, the flow is as follows: client -> backend -> aws -> backend -> client (a client/backend round trip, and a backend/aws round trip). Forwarding thus saves you a round trip between client and aws, reducing latency. Commented Jan 8, 2021 at 0:44
  • 1
    @Nerdizzle so found this stackoverflow.com/a/53952138/3632722 I think there isn't really another roundtrip assuming this is correct? Commented Jan 8, 2021 at 16:29
  • 1
    That seems to be the case, so I more or less stand corrected. That being said, if your backend is hosted on AWS (and in the same region as the S3 storage bucket), there is likely to be a guaranteed lower latency between your backend and S3 than between the client and S3. This obviously only applies if your backend is hosted on AWS or is otherwise guaranteed to have a relatively low latency round trip to S3. In such a case, it'd likely be smarter to measure latency and bandwidth and decide which solution is appropriate for you in an informed way. Commented Jan 8, 2021 at 17:20

1 Answer 1

1

You can use the AWS SDK for Node to create a S3 pre-signed URL that makes the item available at that link temporarily... few seconds, few minutes. Every time you do it, you get a new unique URL that expires.

APIDoc: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.