S3 Storage
Follow these steps to upload and configure your data on Amazon S3:
- Create an S3 Bucket:
- Go to the AWS Console and log in or create an account.
- Search for S3 and click
Buckets > Create bucket. - Set a
Bucket nameandRegion. - Enable
ACLsand disableBlock all public access. - Acknowledge the warning:
I acknowledge that the current settings might result in this bucket and the objects within becoming public. - Click Create bucket.
- Create an IAM User with S3 Permissions:
- Go to
IAM > Access management > Usersand click Add users. - Assign a
Usernameand chooseAttach policies directly. - Select
AmazonS3FullAccessand proceed. - After creation, open the user page and generate an Access key under Security credentials.
- Copy the
Access Key IDandSecret Access Key. You won’t be able to see the secret again later.
- Go to
- Set CORS Configuration:
- Select your bucket and go to the Permissions tab.
- Scroll down to Cross-origin resource sharing (CORS) and click Edit.
- Paste the following JSON config and save:
[ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET"], "AllowedOrigins": ["*"], "ExposeHeaders": [], "MaxAgeSeconds": 3000 } ]
Info
You can restrict AllowedOrigins to your actual domain for better security (e.g., ["https://yourdomain.com"]).
- Configure S3 in the Admin Panel:
- Go to
Admin > Settings > Storage. - Fill in the
Bucket name,AWS Access Key ID, andAWS Secret Access Key.
- Go to
S3 + CloudFront
Use CloudFront to distribute your content globally:
- Search for CloudFront in the AWS Console and go to
Distributions > Create distribution. - Copy the
Distribution domain name(e.g.,abc123.cloudfront.net) and configure it inAdmin > Settings > StorageunderAws CloudFront Domain Name. - Adjust your CDN Distribution Origin settings:
- Open your distribution and navigate to the Origins tab.
- Edit your origin and set
Origin accesstoOrigin access control settings. - Under Origin Access Control:
- Click Create new OAC and keep the default settings.
- Click Create.
- Select the newly created OAC from the dropdown list.
- Click Save changes.
- Update the S3 bucket policy to allow CloudFront access while retaining IAM user write permissions:
{ "Version": "2008-10-17", "Statement": [ { "Sid": "AllowCloudFrontAccess", "Effect": "Allow", "Principal": {"Service": "cloudfront.amazonaws.com"}, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::your-bucket-name/*", "Condition": { "StringEquals": { "AWS:SourceArn": "arn:aws:cloudfront::your-account-id:distribution/your-cdn-distribution-id" } } }, { "Sid": "AllowIAMUserWrite", "Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::your-account-id:user/your-iam-user-name"}, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::your-bucket-name/*" } ] } - Adjust Bucket Access Settings:
- Disable Block all public access.
- Manually select options to allow write access for IAM users while restricting object access to CloudFront. Disable Block all public access and enable all the options manually except
Block public access to buckets and objects granted through new access control lists (ACLs)
S3 + CloudFront + Signed URLs
Follow these steps to use signed URLs for secure access:
- Create a key pair (e.g., via OpenSSL):
Info
The steps below use OpenSSL as an example. There are other methods as well.
- Generate a private key:
openssl genrsa -out private_key.pem 2048 - Extract the public key:
openssl rsa -pubout -in private_key.pem -out public_key.pem
- Upload the public key to CloudFront:
- Log into CloudFront console.
- Go to
Key management > Public keys > Create public key. - Paste the contents of
public_key.pemand save. - Copy the Public Key ID after adding. This is your
Key-Pair-Id(and corresponds toAws CloudFront Key Pair Idin the admin panel).
- Create a key group:
- Go to
Key management > Key groups > Create key group. - Add the uploaded public key to the group and save.
- Go to
- Link the key group to your distribution:
- Open your distribution settings and edit the behavior for the desired path.
- Enable Restrict Viewer Access and select the trusted key group.
- Navigate to Admin > Settings > Storage in your admin panel.
- Add the following:
- Enable CloudFront PreSigned URLs.
For more information, refer to the official AWS documentation on private content with signed URLs.