Kuyashii
Kuyashii

Reputation: 388

How to securely retrieve assets from a private S3 bucket via an Angular frontend

I have a scenario where there is an application that uploads user profile images to an AWS S3 bucket.

I'd like to know what is an optimal solution/approach to the above, given the details I've provided?

Update: The frontend is hosted separately, on an EC2 of it's own, under the same AWS account as the S3.

Upvotes: 0

Views: 1694

Answers (1)

Jaffer
Jaffer

Reputation: 2968

I will try to explain two possible ways to achieve this.

First,

Because you said "user profile images" - I assume the User is logged in. So you could access the s3 file through "web identity federation". You could use cognito or you could directly do it your self

Sample example The sample app authenticates users using web identity federation and Facebook login -

Note the Resource part of the IAM role

"Resource": [
    "arn:aws:s3:::YOUR_BUCKET_NAME/facebook-${graph.facebook.com:id}/*"
]

Each user has own folder for their files, So you can keep her files securely.

Second,

Now option one is not very simple.

Simple option would be, the moment you need the profile image of the user, you fire an API to your Ec2 based server to create a presigned URL

Problem here is, the url expires after the time you specified, so each time you have to create it and send it to browser.

Upvotes: 1

Related Questions