I'm working on an updated nextjs-aws application, where the user is able to get, put and delete data from an S3 storage bucket. In addition to it, I've integrated Amazon CloudFront for caching data in order to decrease the latency across different regions. The performance test before and after the CloudFront integration will be illustrated in the README.md of this new project.
An example of a Next.js application allowing you to upload photos to an Amazon Web Services S3 storage bucket.
- Create a new Next.js project or fork this repo.
- Create a new IAM User:
- Select
Attach existing policies directly
- Add AmazonS3FullAccess
- Select
- Create a new S3 Bucket
- In the Object Ownership tab, select
ACLs enabled & Bucket owner preferred
- In Block Public Access settings for this bucket, uncheck
Block all public access
- The bucket needs to be in the same region as your IAM user
- In the Object Ownership tab, select
- Save the access key and secret key for the IAM User.
- This is used for programmatic access in the API Route.
- Install the AWS CLI:
- Run
aws configure
- Enter your root AWS user access key and secret key, the bucket's region name
- Run
- Create an .env
- Enter your access key and secret key from the IAM user
- Add this file in your .gitingore dependencies
- Go to your bucket, and select the Permissions tab
- Scroll down to find
Cross-origin resource sharing (CORS)
and clickEdit
on the right side - Paste the following code below
[ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET", "PUT", "POST", "DELETE"], "AllowedOrigins": ["*"], "ExposeHeaders": [] } ]
- Scroll down to find