<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gowri Sankar on Medium]]></title>
        <description><![CDATA[Stories by Gowri Sankar on Medium]]></description>
        <link>https://medium.com/@shankarshan6991?source=rss-d96f4e622871------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*n0ZsiymfMVzPMKsH</url>
            <title>Stories by Gowri Sankar on Medium</title>
            <link>https://medium.com/@shankarshan6991?source=rss-d96f4e622871------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:23:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shankarshan6991/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Log Monitoring System using Kibana.]]></title>
            <link>https://medium.com/@shankarshan6991/log-monitoring-system-using-kibana-19a361988d02?source=rss-d96f4e622871------2</link>
            <guid isPermaLink="false">https://medium.com/p/19a361988d02</guid>
            <category><![CDATA[log-monitoring]]></category>
            <category><![CDATA[kibana]]></category>
            <dc:creator><![CDATA[Gowri Sankar]]></dc:creator>
            <pubDate>Tue, 18 Jun 2024 11:32:35 GMT</pubDate>
            <atom:updated>2024-07-08T15:26:40.392Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Summary:</strong></p><p>This article is specially focused on how to create a Centralised log monitoring system for multiple application using <a href="https://www.elastic.co/elastic-stack">ELK</a>.</p><p><strong>The Products used in Elastic Stack for Log monitoring:</strong></p><ol><li><a href="https://www.elastic.co/elasticsearch">Elasticsearch</a></li><li><a href="https://www.elastic.co/kibana">Kibana</a></li><li><a href="https://www.elastic.co/beats/filebeat">FileBeat</a></li></ol><p><strong>Kibana Server Setup:</strong></p><ol><li>Create a Virtual machine. I have used Azure Cloud virtual machine.</li><li>Install the Kibana and Elasticsearch application with latest stable version inside the VM.</li><li>In Azure Network Security Group associated to the created VM. <br>1. <em>Add rule to whitelist port 80 for </em><strong><em>http </em></strong><em>protocol</em><strong><em> </em></strong><em>and 443 for </em><strong><em>https </em></strong><em>protocol connections.</em><br>2. <em>(Optional)Add the rules to whitelist the 5601(default port forKibana), 9002(default port for Elasticsearch) .</em></li><li>Add Ngnix reverse proxy to route the http traffic to access the Kibana and Elasticsearch service.</li></ol><p><strong>Push Application logs from into ElasticSearch index:</strong></p><ol><li>Create the dedicated Elasticsearch index for the application.</li><li>Install <a href="https://www.elastic.co/beats/filebeat">Filebeat</a> service into the application server.</li><li>Configure the Filebeat service with the application logs path.</li><li>Configure the Filebeat service to push the logs to the Elasticsearch index created for the application.</li><li>Start the Filebeat service in the application server, this service will continuosly monitors our new application logs and pushes the logs into the Elasticsearch index.</li></ol><p><strong>Kibana Logs Visualisation Setup:</strong></p><ol><li>Open the Kibana web <strong>(https://{{domain-name}}/kibana)</strong>.</li><li>Go to <strong>Management -&gt; Stack Management -&gt; Kibana -&gt; Index patterns -&gt; Create Index Patters -&gt; Application Index.</strong></li><li>Go to <strong>Discover -&gt; </strong>Choose the created index pattern<strong>, </strong>we can see our applications logs.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4CXkXMVXUYw15czgYeeZjQ.png" /><figcaption>Logs</figcaption></figure><p><strong>Architecture:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zYtM6HvwMTX7sJOg_ReHGw.png" /></figure><p><strong>IAC(Infrastructure As a Code):</strong></p><p>Github Link: <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard">https://github.com/GowrisankarK/kibana-log-monitoring-dashboard</a></p><p><strong>How to use the above IAC to setup the Kibana Log Monitoring System?</strong></p><ol><li>Clone the above repository</li><li>Install terraform in local(&gt; 1.9.1)</li><li>I have used Route 53 for DNS and used Azure for VM.</li><li>Create AWS account and get the Access Key and Secret Key details for AWS.</li><li>Create Azure account and get the Azure client id and client secret and subscription id.</li><li>Create Route53 Zone id and register your domain or import the name server into route 53.</li><li>Then add the command terraform apply, share the below terraform variable informations.<br>1. AWS account details(Access key, Secret key)<br>2. Azure account details(Client id, Client secret, Subscription id)<br>3. AWS Route 53 A record name which is domain name<br>4. Elastic search index name(project name)<br>5. SSH user name<br>6. SSH password <br>7.Kibana dashboard user name<br>8. Kibana dashboard password</li><li>Kibana dashboard setup is ready now.</li><li>In the repo, there is folder named <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/tree/main/sample_node_project">sample_node_project</a>, using this project we can validate our logs are being lively get pushed.</li><li>Inside <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/tree/main/sample_node_project">sample_node_project</a> folder, update the <strong>index_name</strong> flag with terraform variables elastic index name in <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/blob/main/sample_node_project/filebeat.yml">filebeat.yml</a> and <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/blob/main/sample_node_project/push-log.sh">push-log.sh</a></li><li>Inside <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/tree/main/sample_node_project">sample_node_project</a> folder, update the <strong>path-to-project </strong>flag with your repo cloned path in <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/blob/main/sample_node_project/filebeat.yml">filebeat.yml</a>.</li><li>Inside <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/tree/main/sample_node_project">sample_node_project</a> folder, update the <strong>domain_name </strong>flag with terraform variables elastic index name in <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/blob/main/sample_node_project/filebeat.yml">filebeat.yml</a>.</li><li>After that start the <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/tree/main/sample_node_project">sample_node_project</a> by doing below two commands,<br>1. Install node ( version ≥ 18)<br>2. npm install<br>3. node app.js</li><li>After that run this command sh <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/blob/main/sample_node_project/push-log.sh">push-log.sh</a> inside <a href="https://github.com/GowrisankarK/kibana-log-monitoring-dashboard/tree/main/sample_node_project">sample_node_project</a> folder.</li><li>Filebeat setup is done, it is running in the background to push the live logs into elastic index.</li><li>Open the Kibana dashboard using the DNS name provided in the terraform variables, Follow the <strong>Kibana Logs Visualisation Setup </strong>mentioned above to create the Index pattern. Under the <strong>Discover </strong>folder, you can see the logs under your index pattern.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19a361988d02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create fullstack application infrastructure with Kubernetes and Traefik and Let’s encrypt in…]]></title>
            <link>https://medium.com/@shankarshan6991/how-to-create-fullstack-application-infrastructure-with-kubernetes-and-traefik-and-lets-encrypt-in-b1347d83569a?source=rss-d96f4e622871------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1347d83569a</guid>
            <dc:creator><![CDATA[Gowri Sankar]]></dc:creator>
            <pubDate>Fri, 22 Sep 2023 14:22:31 GMT</pubDate>
            <atom:updated>2024-06-22T17:33:33.344Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to create fullstack application infrastructure with Kubernetes and Traefik and Let’s encrypt in AWS Cloud?</h3><p><strong>Summary:</strong></p><p>Create end to end setup for an application using Kubernetes for all layers(application, cache, data).</p><p><strong>Github URL</strong>:</p><p><a href="https://github.com/GowrisankarK/fullstack-app-infra-k8s">https://github.com/GowrisankarK/fullstack-app-infra-k8s</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1347d83569a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Next.js Application into Vercel from AWS S3]]></title>
            <link>https://medium.com/@shankarshan6991/deploy-next-js-application-into-vercel-from-aws-s3-e2a8a36ce0a9?source=rss-d96f4e622871------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2a8a36ce0a9</guid>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[aws-s3-project-to-vercel]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Gowri Sankar]]></dc:creator>
            <pubDate>Fri, 04 Aug 2023 18:08:22 GMT</pubDate>
            <atom:updated>2023-09-06T08:48:22.656Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction to Vercel</strong>:</p><p>Vercel is a cloud platform that helps developers deploy and scale their frontend web applications. It is a serverless platform, which means that Vercel takes care of the underlying infrastructure so that developers can focus on building their applications. Vercel is also a Jamstack platform, which means that it is optimized for static websites and web applications.</p><p>Vercel offers a number of features that make it a valuable tool for developers, including:</p><ul><li><strong>Instant deployment</strong>: Vercel deploys your applications instantly, so you can see your changes as soon as you make them.</li><li><strong>Global CDN</strong>: Vercel uses a global CDN to deliver your applications to users around the world with low latency.</li><li><strong>Automatic scaling</strong>: Vercel automatically scales your applications to handle traffic spikes.</li><li><strong>Security</strong>: Vercel provides a secure environment for your applications, with features like SSL certificates and rate limiting.</li><li><strong>Ease of use</strong>: Vercel is easy to use, with a simple interface and a number of pre-configured templates.</li></ul><p>By default, we can do the vercel deployment by only linking our git project repositories through vercel dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*psQCAr2j4yXADkxQi5IxBQ.png" /></figure><p>In the above image, you can see the vercel dashboard, the only way we can import the project into the vercel is using the git repositories.</p><p><strong>Usecase</strong>:</p><p>I have multiple <strong>next.js</strong> projects which is uploaded in a AWS S3 bucket under seperate folders. When the project is uploaded into a folder under AWS S3 bucket, need to deploy it into a Vercel as static site and store the preview static site url into a database.</p><p><strong>Architecture</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k5xiSROd0GzKbZU98Pek1A.png" /><figcaption>AWS S3 to Vercel Architecture</figcaption></figure><p>As mentioned in the usecase our goal is to deploy the next.js projects which got uploaded inside a AWS S3 bucket as a folder into a Vercel. So, we will be uisng AWS Lambda for doing the vercel deployment automatically using AWS Lambda Triggers for the AWS S3 event notifications for next.js project upload into AWS S3.</p><p><strong>How to trigger the AWS lambda to create and deploy the next.js application from AWS S3 folder into Vercel:</strong></p><p>There is no events for AWS S3 folder creation, the event notifications is only available for the object creations in the AWS S3.</p><p>So, there is something called as <strong>sentinel</strong> file. We can use it for the triggering the events from AWS S3 for folder creation by uploading this file in any specific format like .sentinel into the folder after all the actual files for the project got uploaded. The sentinel file can contain anything like organisation data or project related details etc.,</p><p><strong>What is Sentinel file?</strong></p><p>A Sentinel file is not a standard or well-known concept in the context of AWS S3 or general cloud computing. However, the term “Sentinel file” is used in various other scenarios outside of AWS.</p><p>In general computing or software development, a Sentinel file typically refers to a special file or marker that is placed in a directory or folder to indicate a specific condition or state. It is often used to control or trigger certain processes or actions in a system.</p><p><strong>Attach the Sentinel file AWS S3 upload event as a triggers to the AWS Lambda:</strong></p><p>Create the AWS S3 event notification for the sentinel file upload using the sentinel file name extension as suffix path and add the destination as Lambda which will do the vercel project creation and deployment process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*auUdfZUY9MmnVB6BM4gNLQ.png" /><figcaption>AWS S3 event notification</figcaption></figure><p>Here, in the above image i have created a event notification with suffix path as <strong>_.txt</strong> which means the sentinel file for my use case would be in the format of <strong>{sentinel_file_name}</strong>_.txt to trigger the event.</p><p><strong>What does Lambda do</strong>:</p><p>Lambda will connect with the Vercel using the auth token and creates a project if it is not there and deploy the nextJs application or if the project is already there, it will do the deployment alone.</p><p><strong>AWS Lambda to deploy the next.js app from AWS S3 into Vercel</strong>:</p><ol><li>Install serverless if it is not installed</li></ol><pre>npm install -g serverless</pre><p>2. Set the SLS Config to map the AWS account of yours to deploy the application</p><pre>serverless config credentials --provider aws --key AWS_ACCESS_KEY --secret AWS_SECRET_KEY</pre><p>3. Create a serverless application with node.js as a runtime</p><pre>sls create --template aws-nodejs --path deploy-nextjs-app-into-vercel</pre><p>The Node.js application will be created with below folder structure under <strong>deploy-nextjs-app-into-vercel </strong>folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*84SiWuZ3g1yxkZkcXM5jTQ.png" /></figure><p>you need to create package.json by using <strong>npm init </strong>command<strong> </strong>which has to be run inside the project folder(<strong>deploy-nextjs-app-into-vercel</strong>).</p><p>The lambda will get triggered when the sentinel file is uploaded into the project folder after the project files got uploaded, from the event data we can get the project folder name under the S3 bucket and then we need to create a pre-signed url for all the files in the project and download that to the AWS lambda runtime folder(<strong>tmp/</strong>). The AWS lambda has the <a href="https://aws.amazon.com/blogs/aws/aws-lambda-now-supports-up-to-10-gb-ephemeral-storage/">ephemeral storage</a> which supports upto 10 GB, the default storage size is 512 MB. If you want to increase it, you can do it in the configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHF8yWeZb79SfJwTpIP4qg.png" /><figcaption>Ephemeral storage of Lambda</figcaption></figure><p>Then, the lambda will check is the project got created already there in the vercel, if the project is already there, we will get the vercel project id using the vercel rest api and do the deployment using the vercel id and download next.js application in the Lambda ephemeral stoage location (/tmp path) using the @vercel/client npm package. If the project is not already there in the vercel, the lambda will create a new project using the vercel rest api and deploy the application using the @vercel/client npm package.</p><p><strong>Lambda Code</strong>:</p><ol><li><strong>package.json</strong></li></ol><pre>{<br>  &quot;name&quot;: &quot;deploy-nextjs-app-into-vercel&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;handler.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;@aws-sdk/client-s3&quot;: &quot;^3.370.0&quot;,<br>    &quot;@aws-sdk/s3-request-presigner&quot;: &quot;^3.370.0&quot;,<br>    &quot;@aws-sdk/util-create-request&quot;: &quot;^3.370.0&quot;,<br>    &quot;@types/node&quot;: &quot;^18.0.6&quot;,<br>    &quot;@vercel/client&quot;: &quot;^12.6.5&quot;,<br>    &quot;axios&quot;: &quot;^1.4.0&quot;,<br>    &quot;follow-redirects&quot;: &quot;^1.15.2&quot;,<br>    &quot;next&quot;: &quot;^13.4.10&quot;,<br>    &quot;node-fetch&quot;: &quot;^3.2.6&quot;,<br>    &quot;os&quot;: &quot;^0.1.2&quot;<br>  }<br>}</pre><p>2. <strong>handler.js</strong></p><pre>&#39;use strict&#39;;<br>const { S3Client, GetObjectCommand, ListObjectsCommand } = require(&#39;@aws-sdk/client-s3&#39;);<br>const { getSignedUrl } = require(&quot;@aws-sdk/s3-request-presigner&quot;);<br>const https = require(&quot;https&quot;);<br>const { createDeployment } = require(&#39;@vercel/client&#39;);<br>const fs = require(&#39;fs&#39;);<br>const path = require(&#39;path&#39;);<br>const axios = require(&#39;axios&#39;);<br>const os = require(&#39;os&#39;);<br>const { parse } = require(&quot;url&quot;);<br><br>const s3Client = new S3Client(<br>  {<br>    region: YOUR_AWS_REGION,<br>    credentials: {<br>      accessKeyId: YOUR_AWS_ACCESS_KEY,<br>      secretAccessKey: YOUR_AWS_SECRET_KEY,<br>    },<br>});<br><br>module.exports.deployNextJsAppToVercel  = async (event, context) =&gt; {<br>  const token = YOUR_VERCEL_TOKEN;<br>  const projectName = event.Records[0].s3.object.key.split(&quot;/&quot;)[0];<br>  // For local testing<br>  // const projectName = YOUR_PROJECT_NAME;<br>  console.log(&quot;projectName&quot;, projectName);<br>  const s3BucketName = YOUR_S3_BUCKET_NAME;<br>  const folderName = projectName;<br><br>  let projectID = await createVercelProject(token, projectName);<br>  console.log(projectID);<br>  const vercelProject = await setNodeVersion(projectID, token);<br>  console.log(&quot;vercelProject:&quot;, vercelProject);<br>  if (!projectID) {<br>    try {<br>      const projects = await getVercelProjects(token);<br>      const project = projects.projects.find((proj) =&gt; proj.name === projectName);<br>      if (project) {<br>        const projectID = project.id;<br>        console.log(&#39;Vercel Project ID:&#39;, projectID);<br>      } else {<br>        throw new Error(`Project &#39;${projectName}&#39; not found.`);<br>      }<br>    } catch (error) {<br>      console.error(&#39;Error:&#39;, error.message);<br>      return {<br>        statusCode: 500,<br>        body: `Error: ${error.message}`,<br>      };<br>    }<br>  }<br>  const objectKeys = await getObjectKeys(s3BucketName, folderName);<br>  const filteredObjectKeys = objectKeys.filter(objectKey =&gt; !objectKey.includes(&#39;.git&#39;) &amp;&amp; !objectKey.includes(&#39;README.md&#39;));<br>  const signedUrls = await Promise.all(<br>    filteredObjectKeys.map((key) =&gt; getSignedUrlData(s3BucketName, key))<br>  );<br>  console.log(&quot;urls&quot;, signedUrls);<br>  await downloadFiles(signedUrls);<br>  // Step 2: Trigger a deployment in Vercel for the signed URLs<br>  const deployment = await triggerVercelDeployment(token, projectID, signedUrls, folderName);<br>  await deleteFolder(folderName)<br>  return {<br>    statusCode: 200,<br>    body: `Deployment got successful, the website url is ${deployment?.url}`,<br>  };<br>};<br><br>const deleteFolder = async (folderName) =&gt; {<br>  const temporaryDirectory = os.tmpdir();<br>  console.log(&quot;temporaryDirectory&quot;, temporaryDirectory);<br>  if (!fs.existsSync(temporaryDirectory+folderName)) {<br>    return;<br>  }<br><br>  await fs.rmdir(temporaryDirectory+folderName);<br>};<br>/**<br> * getObjectKeys - get the nextjs application files as S3 objects<br> * @param {*} bucketName s3 bucket name which contains the list of Next Js application<br> * @param {*} folderName s3 folder contains the Next Js we want to deploy into Vercel<br> * @returns <br> */<br>async function getObjectKeys(bucketName, folderName) {<br>  const listObjectsCommand = new ListObjectsCommand({<br>    Bucket: bucketName,<br>    Prefix: `${folderName}/`,<br>  });<br><br>  const response = await s3Client.send(listObjectsCommand);<br>  const objects = response.Contents;<br>  const objectKeys = objects.map((object) =&gt; object.Key);<br><br>  return objectKeys;<br>}<br><br>/**<br> * getSignedUrlData - get the presigned URL for all the s3 object keys(i.e for all the project files)<br> * @param {*} bucketName s3 bucket name which contains the list of Next Js application<br> * @param {*} objectKey s3 object key for the Next Js application files<br> * @returns <br> */<br>async function getSignedUrlData(bucketName, objectKey) {<br>  const params = {<br>    Bucket: bucketName,<br>    Key: objectKey,<br>  };<br><br>  const command = new GetObjectCommand(params);<br>  const signedUrl = await getSignedUrl(s3Client, command, { expiresIn: 360000 });<br>  // return signedUrl;<br>  const parsedUrl = parse(signedUrl);<br>  parsedUrl.protocol = &quot;http:&quot;;<br><br>  // Convert the modified URL object back to a string<br>  const httpPresignedUrl = parsedUrl.format();<br><br>  return httpPresignedUrl;<br>}<br><br>/**<br> * triggerVercelDeployment - triggers the Vercel Deployment inside the project created for the Next Js application.<br> * @param {*} authToken authentication token for the vercel account<br> * @param {*} projectID vercel project id<br> * @param {*} signedUrls aws s3 nextjs project file presigned URL&#39;s<br> * @param {*} folderName aws s3 nextjs project folder inside the AWS S3 bucket<br> * @returns vercel deployment data<br> */<br>async function triggerVercelDeployment(authToken, projectID, signedUrls, folderName) {<br>  let deployment = undefined;<br>  const temporaryDirectory = os.tmpdir();<br>  console.log(&quot;temporaryDirectory&quot;, temporaryDirectory);<br>  console.log(&#39;createDeployment &#39;, createDeployment);<br>  for await (const event of createDeployment({<br>    token: authToken,<br>    teamId: &quot;team_Y6iorVTQiUAff3HsrpWHZ6am&quot;,<br>    path: path.resolve(`/tmp/${folderName}`),<br>    // path: path.resolve(`./${folderName}`),<br>    project: {<br>      id: projectID<br>    },<br>    projectSettings: {<br>      buildCommand: null,<br>      devCommand: null,<br>      framework: &#39;nextjs&#39;,<br>      commandForIgnoringBuildStep: &#39;&#39;,<br>      installCommand: null,<br>      outputDirectory: null,<br>    },<br>    files: signedUrls,<br>  })) {<br>    console.log(&#39;event.type&#39;, event.type);<br>    if (event.type === &#39;ready&#39;) {<br>      console.log(&#39;Breaking &#39;, event);<br>      deployment = event.payload;<br>      break;<br>    }<br>    if (event.type === &#39;error&#39;) {<br>      console.log(&#39;Breaking &#39;, event);<br>      break;<br>    }<br>  }<br>  fs.rm(`${temporaryDirectory}/${folderName}`, { recursive: true, force: true }, (error) =&gt; {<br>    if (error) {<br>      console.error(error);<br>    } else {<br>      console.log(`Directory &#39;${folderName}&#39; is deleted.`);<br>    }<br>  });<br>  return deployment;<br>}<br><br>/**<br> * getVercelProjects - get the list of vercel projects under the account.<br> * @param {*} token authentication token for the vercel account<br> * @returns list of vercel projects<br> */<br>async function getVercelProjects(token) {<br>  const options = {<br>    hostname: &#39;api.vercel.com&#39;,<br>    path: &#39;/v8/projects/?teamId=team_Y6iorVTQiUAff3HsrpWHZ6am&#39;,<br>    method: &#39;GET&#39;,<br>    headers: {<br>      &#39;Content-Type&#39;: &#39;application/json&#39;,<br>      Authorization: `Bearer ${token}`,<br>    },<br>  };<br><br>  return new Promise((resolve, reject) =&gt; {<br>    const req = https.request(options, (res) =&gt; {<br>      let data = &#39;&#39;;<br><br>      res.on(&#39;data&#39;, (chunk) =&gt; {<br>        data += chunk;<br>      });<br><br>      res.on(&#39;end&#39;, () =&gt; {<br>        if (res.statusCode === 200) {<br>          const projects = JSON.parse(data);<br>          resolve(projects);<br>        } else {<br>          reject(new Error(`Failed to fetch Vercel projects: ${res.statusCode} ${res.statusMessage}`));<br>        }<br>      });<br>    });<br><br>    req.on(&#39;error&#39;, (err) =&gt; {<br>      reject(err);<br>    });<br><br>    req.end();<br>  });<br>}<br><br>/**<br> * downloadFile - download the file<br> * @param {*} url aWS s3 objects presigned URL<br> * @param {*} destination local path location<br> */<br>async function downloadFile(url, destination) {<br>  const response = await axios.get(url, { responseType: &#39;arraybuffer&#39; });<br>  fs.writeFileSync(destination, Buffer.from(response.data, &#39;binary&#39;));<br>}<br><br>/**<br> * downloadFiles - download the files<br> * @param {*} urls aws s3 objects presigned URL<br> */<br>async function downloadFiles(urls) {<br>  for (const url of urls) {<br>    console.log(url);<br>    let fileName = path.basename(url.split(&#39;?&#39;)[0]);<br>    const temporaryDirectory = os.tmpdir();<br>    console.log(&quot;temporaryDirectory&quot;, temporaryDirectory);<br>    let dirName = `${temporaryDirectory}/${url.split(&#39;?&#39;)[0].split(&quot;amazonaws.com/&quot;)[url.split(&#39;?&#39;)[0].split(&quot;amazonaws.com/&quot;).length-1]}`;<br>    dirName = dirName.replace(`/${fileName}`, &#39;&#39;);<br>    path.resolve(dirName);<br>    try {<br>      fs.mkdirSync(dirName, { recursive: true });<br>    } catch(error) {<br>      console.log(error)<br>    }<br>    // if (!fs.existsSync(dirName)) {<br>    //   fs.mkdirSync(dirName, { recursive: true });<br>    // }<br>    console.log(fileName);<br>    const filePath = path.join(dirName, fileName);<br>    await downloadFile(url, filePath);<br>    console.log(`Downloaded: ${filePath}`);<br>  }<br>}<br><br>/**<br> * createVercelProject - creates the vercel nextjs framework project<br> * @param {*} token authentication token for the vercel account<br> * @param {*} projectName vercel project name<br> * @returns <br> */<br>async function createVercelProject(token, projectName) {<br>  const options = {<br>    hostname: &#39;api.vercel.com&#39;,<br>    path: &#39;/v1/projects/?teamId=team_Y6iorVTQiUAff3HsrpWHZ6am&#39;,<br>    method: &#39;POST&#39;,<br>    headers: {<br>      &#39;Content-Type&#39;: &#39;application/json&#39;,<br>      Authorization: `Bearer ${token}`,<br>    },<br>  };<br><br>  return new Promise((resolve, reject) =&gt; {<br>    const req = https.request(options, (res) =&gt; {<br>      let data = &#39;&#39;;<br><br>      res.on(&#39;data&#39;, (chunk) =&gt; {<br>        data += chunk;<br>      });<br><br>      res.on(&#39;end&#39;, () =&gt; {<br>        console.log(res.statusCode)<br>        console.log(data)<br>        if (res.statusCode === 200) {<br>          const { id } = JSON.parse(data);<br>          resolve(id);<br>        } else {<br>          resolve(undefined);<br>        }<br>      });<br>    });<br><br>    req.on(&#39;error&#39;, (err) =&gt; {<br>      reject(err);<br>    });<br><br>    req.write(JSON.stringify({ <br>      name: projectName, <br>      framework: &quot;nextjs&quot;<br>    }));<br><br>    req.end();<br>  });<br>}<br><br>// Function to set the Node.js version using Vercel API&#39;s set-build-env endpoint<br>function setNodeVersion(projectId, token) {<br>  const options = {<br>    hostname: &#39;api.vercel.com&#39;,<br>    path: `/v1/projects/${projectId}/?teamId=YOUR_VERCEL_TEAM_ID`,<br>    method: &#39;POST&#39;,<br>    headers: {<br>      &#39;Content-Type&#39;: &#39;application/json&#39;,<br>      Authorization: `Bearer ${token}`,<br>    },<br>  };<br><br>  const envData = {<br>    key: &#39;NODE_VERSION&#39;,<br>    value: &#39;16&#39;,<br>    teamId: YOUR_VERCEL_TEAM_ID,<br>    scope: &#39;team&#39;,<br>  };<br><br>  const req = https.request(options, (res) =&gt; {<br>    let data = &#39;&#39;;<br><br>    res.on(&#39;data&#39;, (chunk) =&gt; {<br>      data += chunk;<br>    });<br><br>    res.on(&#39;end&#39;, () =&gt; {<br>      console.log(data)<br>      console.log(&#39;Node.js version set successfully:&#39;, JSON.parse(data));<br>    });<br>  });<br><br>  req.on(&#39;error&#39;, (err) =&gt; {<br>    console.log(err)<br>    console.error(&#39;Error setting Node.js version:&#39;, err.message);<br>  });<br><br>  req.write(JSON.stringify(envData)); // Send the environment variable data in the request body<br>  req.end();<br>}</pre><p><strong>Serverless.yaml</strong></p><pre>service: deploy-nextjs-app-vercel<br>frameworkVersion: &quot;3&quot;<br><br>provider:<br>  name: aws<br>  runtime: nodejs18.x<br>  region: YOUR_AWS_REGION<br><br>functions:<br>  deployNextJsAppToVercel:<br>    handler: handler.deployNextJsAppToVercel<br>    timeout: 900</pre><p>Github URL: <a href="https://github.com/GowrisankarK/deploy-nextjs-apps-into-vercel-from-aws-s3">https://github.com/GowrisankarK/deploy-nextjs-apps-into-vercel-from-aws-s3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2a8a36ce0a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>