This article was written 102 days ago. The content of the article may be out of date.
This article is based on my personal project needs and the knowledge I’ve gathered through self-study. If you find any errors or inaccuracies, please feel free to point them out.
AWS Setups
In order to embed code in Spring Boot to access the bucket, there are 4 things you need to write in properties files.
So we need to create a bucket for sure. And the accessed key is combined with the IAM user (it’s better to use IAM user instead of the account ). So we also need to create IAM user.
Create IAM user
Follow the steps to create the user.
I created a user group for later convenience.
After that, we need to create an access key for the user.
Choose the local code
This is where we find the Secret access key.
NOTE: Save it to somewhere. This is the only way to see the secret key
Create E3 Bucket
For my bucket, I need to store pictures, and it is allowed to read by anyone, so I need to set it’s reading permission to public:
RESOURCE is the bucket or the access point. (TODO: Later change the Resource to arn:aws:s3::: bucket_name/dir/*). So I can use the bucket store more file than just pictures).
ACTION is the action you want to give permission to. For my case, I just need to add permission to view the files, so that’s s3:GetObject, there is also ListBucket and PutObject and so on. Action List
PRINCIPAL is the user you want to give permission, since it’s anyone, its *, but if you want to specify user, you will need to set "Principal":{"AWS":["arn:aws:iam::AccountID1WithoutHyphens:root","arn:aws:iam::AccountID2WithoutHyphens:root"]}. More Principal Examples