<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Christophe Parmentier</title>
    <description>The latest articles on DEV Community by Christophe Parmentier (@parmentierchristophe).</description>
    <link>https://dev.to/parmentierchristophe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F103074%2Fdcb3ae6a-893e-4db1-8c45-3c3d8d10147f.jpg</url>
      <title>DEV Community: Christophe Parmentier</title>
      <link>https://dev.to/parmentierchristophe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/parmentierchristophe"/>
    <language>en</language>
    <item>
      <title>How to deploy static Next.js to AWS S3</title>
      <dc:creator>Christophe Parmentier</dc:creator>
      <pubDate>Tue, 24 Nov 2020 09:51:37 +0000</pubDate>
      <link>https://dev.to/parmentierchristophe/how-to-deploy-static-next-js-to-aws-s3-1d4f</link>
      <guid>https://dev.to/parmentierchristophe/how-to-deploy-static-next-js-to-aws-s3-1d4f</guid>
      <description>&lt;p&gt;&lt;a href="https://nextjs.org" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt; this fabulous open source framework based on React allows you to manage an entire application! Both front-end and back-end, perfect for a javascript developer and all this with high performance, but if you arrive on this article, you must surely know it, if not, hop, little link to the &lt;a href="https://nextjs.org/docs/getting-started" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;For this tutorial Node.js is required.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create &lt;strong&gt;Next.js&lt;/strong&gt; app&lt;/li&gt;
&lt;li&gt;Setup &lt;strong&gt;AWS S3 butcket&lt;/strong&gt; static website&lt;/li&gt;
&lt;li&gt;Publish &lt;strong&gt;Next.js&lt;/strong&gt; Application to &lt;strong&gt;S3 bucket&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create Next.js app
&lt;/h2&gt;

&lt;p&gt;As recommended by &lt;strong&gt;Next.js&lt;/strong&gt; we will use &lt;code&gt;create-next-app&lt;/code&gt; for create a project.&lt;br&gt;
There are two possibilities to initialize a project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app
&lt;span class="c"&gt;# or&lt;/span&gt;
yarn create next-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then follow the instructions and finally go to our project and start it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;my-project &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; yarn dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server starts up on port &lt;code&gt;3000&lt;/code&gt;, so let's go to &lt;code&gt;http://localhost:3000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98562391-4d347400-22aa-11eb-8e1e-d9dbec1d37e5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98562391-4d347400-22aa-11eb-8e1e-d9dbec1d37e5.png" title="The next app started" alt="NextApp" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations 🎉 ! now let's deploy this static &lt;strong&gt;Next.js&lt;/strong&gt; application to &lt;strong&gt;aws S3 bucket&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup AWS S3 butcket static website
&lt;/h2&gt;

&lt;p&gt;To continue the tutorial, we are going to move on to the aws console, for this section I am assuming you already have an AWS account with access to the management console.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Access your management console&lt;/li&gt;
&lt;li&gt;on &lt;strong&gt;Find Services&lt;/strong&gt;, search &lt;strong&gt;S3&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98572716-398f0a80-22b6-11eb-847a-8cff5fe5d392.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98572716-398f0a80-22b6-11eb-847a-8cff5fe5d392.png" title="Search S3" alt="S3Service" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;click on &lt;strong&gt;Create bucket&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98572713-37c54700-22b6-11eb-96a2-9a3dd530284e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98572713-37c54700-22b6-11eb-96a2-9a3dd530284e.png" title="Create bucket" alt="createBucket" width="800" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;enter name your Bucket name (e.g: my-awesome-nextjs-app), it must be &lt;strong&gt;unique&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574220-f6359b80-22b7-11eb-9429-a25842f91b90.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574220-f6359b80-22b7-11eb-9429-a25842f91b90.png" title="add bucket name" alt="addname" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;enable access public and valide by unchecking Block all public access and check the acknowledgment of receipt, you can create the bucket&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574198-ed44ca00-22b7-11eb-9c60-acb054784221.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574198-ed44ca00-22b7-11eb-9c60-acb054784221.png" title="enable access public" alt="accesspublic" width="800" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;on list, select your bucket&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574186-eae27000-22b7-11eb-8422-b54b7ab7eca9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574186-eae27000-22b7-11eb-8422-b54b7ab7eca9.png" title="select bucket on list" alt="selectBucket" width="800" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;go to &lt;strong&gt;properties&lt;/strong&gt; &amp;gt; &lt;strong&gt;Static website hosting&lt;/strong&gt;, select &lt;strong&gt;Enable&lt;/strong&gt; static website hosting and &lt;strong&gt;Host as static website&lt;/strong&gt; on &lt;strong&gt;index document&lt;/strong&gt; and &lt;strong&gt;Error document&lt;/strong&gt; you can ad &lt;code&gt;index.html&lt;/code&gt;, Save changes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574156-e3bb6200-22b7-11eb-80eb-4998cc4b9394.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574156-e3bb6200-22b7-11eb-80eb-4998cc4b9394.png" title="static webstite hosting" alt="staticWebsite" width="800" height="744"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now go to &lt;strong&gt;Permissions&lt;/strong&gt; &amp;gt; &lt;strong&gt;Bucket policy&lt;/strong&gt; edit and add this, &lt;strong&gt;change Ressource with your bucket name&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::[bucket-name]/*"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574147-e027db00-22b7-11eb-99c2-02b5cc2153a3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98574147-e027db00-22b7-11eb-99c2-02b5cc2153a3.png" title="bucket policy" alt="bucketPolicy" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you're ready to export the &lt;strong&gt;Next.js&lt;/strong&gt; app and add this to yout bucket 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Publish Next.js Application to S3 bucket
&lt;/h2&gt;

&lt;p&gt;To complete this tutorial, we're going to export our &lt;strong&gt;Next.js&lt;/strong&gt; app using &lt;code&gt;package.json&lt;/code&gt; and import the exported app into our &lt;strong&gt;S3 bucket&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To start, we will have to modify the file &lt;code&gt;package.json&lt;/code&gt; to change a build script :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"next build &amp;amp;&amp;amp; next export"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This build script build the app and generate all the static files (to folder &lt;strong&gt;out&lt;/strong&gt;) necessary to run the application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98650919-dd6dca00-2339-11eb-9327-aef5cd8ce328.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98650919-dd6dca00-2339-11eb-9327-aef5cd8ce328.png" title="builded app" alt="appBuilded" width="800" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to your &lt;strong&gt;S3 Bucket&lt;/strong&gt; and upload the contents of the &lt;strong&gt;out&lt;/strong&gt; folder&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98651281-5705b800-233a-11eb-84f0-266bc64a1e31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13301795%2F98651281-5705b800-233a-11eb-84f0-266bc64a1e31.png" title="upload on S3 bucket" alt="UploadS3" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on &lt;strong&gt;Upload&lt;/strong&gt;, after loading you can exit&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa3g4vvnwssav2eu6r1pk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa3g4vvnwssav2eu6r1pk.png" alt="uploadedFiles" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To access our application, go to &lt;strong&gt;Properties&lt;/strong&gt;&amp;gt; &lt;strong&gt;Static website hosting&lt;/strong&gt; where the bucket link is displayed&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nx2ecubvjp4lnk071mh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nx2ecubvjp4lnk071mh.png" alt="linkBucket" width="800" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;let's go to this link :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdnac1z0vsx5q344lwf68.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdnac1z0vsx5q344lwf68.png" alt="s3bucket" width="800" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🎉 &lt;strong&gt;Congratulations&lt;/strong&gt; 🎉 We have uploaded our static &lt;strong&gt;Next.js&lt;/strong&gt; app to &lt;strong&gt;aws S3 bucket&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All you have to do is code your static application, export it and add it to your bucket&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As you can see it is very easy to host a static &lt;strong&gt;Next.js&lt;/strong&gt; app on aws, in the next article i think we will see how to work with github actions to use continuous integration on our &lt;strong&gt;Next.js&lt;/strong&gt; app, so every merge on branch main your application will be updated on your bucket.&lt;/p&gt;

&lt;p&gt;Thank you for following this article, do not hesitate to give me your feedback and if you liked it share it and follow me on &lt;a href="https://twitter.com/theCrispydesign" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>aws</category>
      <category>react</category>
    </item>
  </channel>
</rss>
