Next.js + AWS S3 Upload
This is an example of a Next.js application allowing you to upload photos to an S3 bucket.
Option 1: Use an existing S3 bucket.
Retrieve your existing access key, secret key, S3 bucket region and name. Provide those values after clicking "Deploy" to automatically set the environment variables.
Option 2: Create an S3 bucket.
- Create a new IAM role with permission for
- Save the access key and secret key.
- Install the AWS CLI and run
- This will prompt you to enter the access key and secret key.
- Create an
.env.localfile similar to
cdk deployto create an S3 bucket with the correct CORS settings.
- Visit your newly created S3 bucket and retrieve the name and region.
- Add the name and region to
yarn devto start the Next app at
- Choose a
- You should see your file successfully uploaded to S3.
yarn dev– Starts the Next.js app at
cdk deploy– Deploy this stack to your default AWS account/region
cdk diff– Compare deployed stack with current state
cdk synth– Emits the synthesized CloudFormation template