<?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: sanchezg7</title>
    <description>The latest articles on DEV Community by sanchezg7 (@sanchezg7).</description>
    <link>https://dev.to/sanchezg7</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%2F1024338%2Fbc823b0e-7a0f-49b2-8246-4903d01f3e41.png</url>
      <title>DEV Community: sanchezg7</title>
      <link>https://dev.to/sanchezg7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanchezg7"/>
    <language>en</language>
    <item>
      <title>Git Rebase Vs Git Merge</title>
      <dc:creator>sanchezg7</dc:creator>
      <pubDate>Fri, 26 Jul 2024 23:32:54 +0000</pubDate>
      <link>https://dev.to/sanchezg7/git-rebase-vs-git-merge-4j4c</link>
      <guid>https://dev.to/sanchezg7/git-rebase-vs-git-merge-4j4c</guid>
      <description>&lt;p&gt;Objective: Describe the difference between merge and rebase, and when to use each.  &lt;/p&gt;

&lt;p&gt;Let start with the problem we want to solve.&lt;/p&gt;

&lt;p&gt;Problem: How to keep a branch in sync with the teams latest changes?&lt;br&gt;&lt;br&gt;
Different approaches are available, depending on the circumstances.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdzs2qjalwzj3fo2v4wy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdzs2qjalwzj3fo2v4wy.png" alt="Feature Branch and Main Branch divert" width="642" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Merge
&lt;/h2&gt;

&lt;p&gt;Merging is a non-destructive approach.&lt;br&gt;
It will create a &lt;strong&gt;merge commit&lt;/strong&gt; containing upstream changes and place it into your feature branch.&lt;br&gt;
&lt;strong&gt;Scenario&lt;/strong&gt;: Keeping a feature branch up to date with main&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F08rzxrb7a1gym8arevrp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F08rzxrb7a1gym8arevrp.png" alt="Merge workflow" width="800" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You create a feature branch from main on May 1st.&lt;/li&gt;
&lt;li&gt;You work on your feature branch for a week.&lt;/li&gt;
&lt;li&gt;Commits from other team members are merged into main&lt;/li&gt;
&lt;li&gt;Your feature branch is now out of sync&lt;/li&gt;
&lt;li&gt;git merge on May 10th

&lt;ul&gt;
&lt;li&gt;Will bring in changes from main into your feature branch as a new commit (containing changes since May 1st)&lt;/li&gt;
&lt;li&gt;All changes will show up in your history when a PR is raised to go back into &lt;code&gt;main&lt;/code&gt; (even changes from main)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Pros:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linear history is maintained&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Longer lived branches and/or active main branch makes for a messy history.

&lt;ul&gt;
&lt;li&gt;Your changes are mixed in with other's changes&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Identifying only your changes in the PR is much more difficult&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  When should I use &lt;code&gt;git merge&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;When others are actively sourcing this branch for work. e.g.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;main&lt;/li&gt;
&lt;li&gt;feature branches&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because there are multiple people relying on these branches, git needs to be able to reconstruct the history in a linear fashion; otherwise, git tries to fix it and ultimately the local copy of the branch is no longer in sync with remote (github.com). This, by design, will break git and what allows git to follow the distributed code versioning model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rebase
&lt;/h2&gt;

&lt;p&gt;This alternative is a destructive option. It rewrites the history in a branch.&lt;/p&gt;

&lt;p&gt;Pros:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cleaner project history&lt;/li&gt;
&lt;li&gt;Cleaner insight into PR changes&lt;/li&gt;
&lt;li&gt;Your changes are played after the latest changes from &lt;code&gt;main&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The changes happen only in your repository until you FORCE PUSH&lt;/li&gt;
&lt;li&gt;Feature branch will retain your changes as a BRAND NEW SET OF COMMITS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Scenario&lt;/strong&gt;: Keeping a feature branch up to date with main&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5j2ty8pn0fyvrnj0f73a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5j2ty8pn0fyvrnj0f73a.png" alt="Rebase workflow" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This can be interpreted as, “construct the changes on my branch to be placed &lt;em&gt;after&lt;/em&gt; the changes on the &lt;code&gt;main&lt;/code&gt; branch.”&lt;br&gt;&lt;br&gt;
This workflow applies to any branch serving as the source of truth, where child branches are dependent on newer changes from their parent branch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;feature branch sourcing new changes from main&lt;/li&gt;
&lt;li&gt;story branch sourcing new change from feature branch&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When should I use &lt;code&gt;git rebase&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Rebase is great when you have complete control over branch and no one is actively dependent on it. You can rewrite history as much as you want. As a result, the local and remote branch can stay in sync with ease (with a force push git push -f). If you rewrite history on a branch, other people will not be able to pull it down without running into problems.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Git is a powerful framework for versioning code across teams and individuals. It doesn't force any certain workflow, in fact, it can be made to fit any common workflow in the software development lifecycle. Let me know how you use git to contribute to software in team-based settings!&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>vcs</category>
    </item>
    <item>
      <title>Setup a node app with Elastic Beanstalk and CI/CD</title>
      <dc:creator>sanchezg7</dc:creator>
      <pubDate>Sun, 12 Feb 2023 15:48:20 +0000</pubDate>
      <link>https://dev.to/sanchezg7/setup-a-node-app-with-elastic-beanstalk-and-cicd-an0</link>
      <guid>https://dev.to/sanchezg7/setup-a-node-app-with-elastic-beanstalk-and-cicd-an0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Suppose we have a node express application that we need to publish to the cloud. After searching, there aren't many relevant articles and resources covering this topic, so I hope this is helpful to fit the exact needs. AWS CloudFormation is a good solution but it has a big barrier to entry. Instead, we will use AWS Elastic Beanstalk to do a lot of the heavy lifting. It will enable all the required AWS resources for my application; in addition, we will automate this process so that when the code is updated with new changes. The code will automatically deploy to Elastic Beanstalk with the latest changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this article is not
&lt;/h2&gt;

&lt;p&gt;There are many ways to write a node express application. This blog will not attempt to convince how to design or where to host the repository. &lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Node application
&lt;/h3&gt;

&lt;p&gt;We need a node express application. It is an API that is used only for the purposes of stubbing a real node application. &lt;/p&gt;

&lt;h3&gt;
  
  
  AWS CLI setup and access
&lt;/h3&gt;

&lt;p&gt;AWS provides a free tier for to work with. Check out tutorials online for how to create a free tier account and set up the terminal with the AWS CLI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concepts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Elastic Beanstalk
&lt;/h3&gt;

&lt;p&gt;This service, provided by AWS, does a lot of the heavy lifting for procuring all the infrastructure needed for the application to work. It will connect up all the required dependencies. &lt;/p&gt;

&lt;h3&gt;
  
  
  Elastic Beanstalk Environment
&lt;/h3&gt;

&lt;p&gt;An environment is the space to deploy an application to. All the necessary AWS resources are associated to the environment in order to facilitate the needs of the platform. This tutorial will only use one environment; however, we can have as many environments needed to meet the software lifecycle means.&lt;/p&gt;

&lt;h3&gt;
  
  
  Application Version
&lt;/h3&gt;

&lt;p&gt;The version is associated to a source bundle, identified by a label. It represents an application artifact that will get deployed to an Elastic Beanstalk environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Source Bundle
&lt;/h3&gt;

&lt;p&gt;The artifact of the code and the reference for where it is stored. In this case, we will use S3 as the repository for the source bundle.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple Storage Service (S3)
&lt;/h3&gt;

&lt;p&gt;This service is an object store that allows saving any type of data for accessing later. For example, it can store zip files. The source bundle will be stored here.&lt;/p&gt;

&lt;h2&gt;
  
  
  How To - Manual Steps
&lt;/h2&gt;

&lt;p&gt;First, we need to carry out the steps manually. This will ensure all dependencies, permissions, and sequence of events are correct. This will ease any hiccups when automating this pipeline in Gitlab.&lt;/p&gt;

&lt;h3&gt;
  
  
  Procure an application to upload to Elastic Beanstalk
&lt;/h3&gt;

&lt;p&gt;You can use this example in &lt;a href="https://gitlab.com/ayogsynergy/eb_node_sandbox/-/tree/step1_helloworld"&gt;https://gitlab.com/ayogsynergy/eb_node_sandbox/-/tree/step1_helloworld&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Upload Source Bundle to S3
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Bundle the source code from VCS into a zip file.

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git archive -v -o eb-node-sandbox.zip --format=zip HEAD&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Create a S3 bucket.

&lt;ul&gt;
&lt;li&gt;This example will use &lt;code&gt;manual-eb&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Upload the bundle to the S3 bucket.

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;aws s3 cp eb-node-sandbox.zip s3://manual-eb&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create application version
&lt;/h3&gt;

&lt;p&gt;Elastic Beanstalk expects an application version to be specified in order to instantiate an environment.&lt;/p&gt;

&lt;p&gt;Usage&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws elasticbeanstalk create-application-version &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--application-name&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APP_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--version-label&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"new version &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--source-bundle&lt;/span&gt; &lt;span class="nv"&gt;S3Bucket&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3Bucket&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;,S3Key&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3Key&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--auto-create-application&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--region&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;AWS_REGION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws elasticbeanstalk create-application-version &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--application-name&lt;/span&gt; eb-node-sandbox &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--version-label&lt;/span&gt; v0.0.01 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"new version v0.0.01"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--source-bundle&lt;/span&gt; &lt;span class="nv"&gt;S3Bucket&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;manual-eb,S3Key&lt;span class="o"&gt;=&lt;/span&gt;eb-node-sandbox.zip &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--auto-create-application&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--region&lt;/span&gt; us-east-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Describe application version
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Confirm the application version is created.

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;aws elasticbeanstalk describe-application-versions --application-name eb-node-sandbox&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create the Elastic Beanstalk environment
&lt;/h2&gt;

&lt;p&gt;Next, instantiate an environment that will accept the application version to deploy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a configuration template
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws elasticbeanstalk create-configuration-template &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--application-name&lt;/span&gt; eb-node-sandbox &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--template-name&lt;/span&gt; v1-template &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--solution-stack-name&lt;/span&gt; &lt;span class="s2"&gt;"64bit Amazon Linux 2 v5.6.4 running Node.js 16"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Describe the configuration template
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws elasticbeanstalk describe-configuration-settings &lt;span class="nt"&gt;--application-name&lt;/span&gt; eb-node-sandbox &lt;span class="nt"&gt;--template-name&lt;/span&gt; v1-template
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create Elastic Beanstalk environment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Create an options file for use of making environment&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"Namespace"&lt;/span&gt;: &lt;span class="s2"&gt;"aws:autoscaling:launchconfiguration"&lt;/span&gt;,
        &lt;span class="s2"&gt;"OptionName"&lt;/span&gt;: &lt;span class="s2"&gt;"IamInstanceProfile"&lt;/span&gt;,
        &lt;span class="s2"&gt;"Value"&lt;/span&gt;: &lt;span class="s2"&gt;"aws-elasticbeanstalk-ec2-role"&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create an Elastic Beanstalk Environment for the application&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws elasticbeanstalk create-environment \
--application-name eb-node-sandbox \
--template-name v1-template \
--version-label v0.0.01 \
--environment-name eb-node-sandbox-env \
--option-settings file://options.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Describe the environment
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Confirm the environment is created

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;aws elasticbeanstalk describe-environments --environment-names eb-node-sandbox-env&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this point, there is a running Elastic Beanstalk environment accessible via the internet.&lt;/p&gt;

&lt;p&gt;Launch the instance and send a request to &lt;code&gt;GET /&lt;/code&gt; to verify the appropriate &lt;code&gt;Hello World&lt;/code&gt; response is returned. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pTiCCno7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/grz1fbdw2h3912vxwqxs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pTiCCno7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/grz1fbdw2h3912vxwqxs.png" alt="Hello World Application" width="880" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Update the environment
&lt;/h2&gt;

&lt;p&gt;Now, let’s simulate a new change in the source code. We will need to publish the new changes. We will update the Elastic Beanstalk environment with the new version.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload new source bundle with a new key name to the S3 bucket&lt;/li&gt;
&lt;li&gt;Create a new application version

&lt;ul&gt;
&lt;li&gt;Associate it to the new respective bundle&lt;/li&gt;
&lt;li&gt;&lt;code&gt;eb-node-sandbox-1.0.0-02&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Update the &lt;em&gt;existing&lt;/em&gt; Elastic Beanstalk environment with the new application version&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws elasticbeanstalk update-environment \
--application-name eb-node-sandbox \
--environment-name eb-node-sandbox-env \
--version-label eb-node-sandbox-1.0.0-02 \
--region us-east-1
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run this command to update the environment. It will take some time. Wait until the environment deployment is finished.&lt;/p&gt;




&lt;p&gt;Try to do this in one sitting, if possible. Otherwise, terminate the environment as AWS will keep the meter running for the infrastructure that you are leveraging in your environment (e.g. EC2). This will help avoid unexpected costs.&lt;/p&gt;




&lt;h3&gt;
  
  
  Troubleshooting (log analysis)
&lt;/h3&gt;

&lt;p&gt;If the application does not respond successfully, take a look at the logs. Here is some sample log output below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Jan 15 14:50:25 ip-172-31-7-140 web: &amp;gt; Elastic-Beanstalk-Sample-App@0.0.1 start
Jan 15 14:50:25 ip-172-31-7-140 web: &amp;gt; node app.js
Jan 15 14:50:25 ip-172-31-7-140 web: Server running at http://127.0.0.1:8080/
Jan 15 15:06:21 ip-172-31-7-140 web: &amp;gt; eb_node_sandbox@1.0.0 start
Jan 15 15:06:21 ip-172-31-7-140 web: &amp;gt; node server.js
Jan 15 15:06:21 ip-172-31-7-140 web: Running on Port: 8080
Jan 15 15:18:20 ip-172-31-7-140 web: &amp;gt; eb_node_sandbox@1.0.0 start
Jan 15 15:18:20 ip-172-31-7-140 web: &amp;gt; node server.js
Jan 15 15:18:21 ip-172-31-7-140 web: Running on Port: 8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By convention, it will default to &lt;code&gt;npm run start&lt;/code&gt; to boot your application. Make sure your &lt;code&gt;package.json&lt;/code&gt; has this script defined. It will also run &lt;code&gt;npm install&lt;/code&gt; prior to running your application, if it detects a &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;

&lt;h2&gt;
  
  
  CI/CD
&lt;/h2&gt;

&lt;p&gt;Now, automate this publish process to trigger every time the repository code is updated. This example will leverage Gitlab.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;.gitlb-ci.yml&lt;/code&gt; file to indicate how/what to include in the CI/CD pipeline
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;stages:
  - build
  - run

variables:
  APP_NAME: &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;CI_PROJECT_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  ENV_NAME: &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;ENV_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  APP_VERSION: &lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;
  S3BUCKET: &lt;span class="s2"&gt;"manual-eb"&lt;/span&gt;
  AWS_ID: &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;AWS_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  AWS_ACCESS_KEY_ID: &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  AWS_SECRET_ACCESS_KEY: &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  AWS_REGION: us-east-1

create_app_version:
  stage: build
  image: python:latest
  allow_failure: &lt;span class="nb"&gt;false
  &lt;/span&gt;script: |
    pip &lt;span class="nb"&gt;install &lt;/span&gt;awscli
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Creating zip file"&lt;/span&gt;
    &lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APP_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;-&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APP_VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;-&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;CI_PIPELINE_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;S3Key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.zip"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Zipping: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3Key&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    git archive &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3Key&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;zip HEAD

    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Creating bundle..."&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Uploading bundle: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3Key&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ..."&lt;/span&gt;
    aws s3 &lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3Key&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; s3://&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3BUCKET&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3Key&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;--region&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;AWS_REGION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;

    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Creating app version"&lt;/span&gt;
    aws elasticbeanstalk create-application-version &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--application-name&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APP_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--version-label&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"new version &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--source-bundle&lt;/span&gt; &lt;span class="nv"&gt;S3Bucket&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3BUCKET&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;,S3Key&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;S3Key&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--auto-create-application&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--region&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;AWS_REGION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  only:
    refs:
      - main
deploy_version_to_env:
  stage: run
  image: coxauto/aws-ebcli
  when: manual
  script: |
    &lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APP_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;-&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APP_VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;-&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;CI_PIPELINE_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;

    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Deploying version: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; to env: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;ENV_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    aws elasticbeanstalk update-environment &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--application-name&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APP_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--environment-name&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;ENV_NAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--version-label&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION_LABEL&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;AWS_REGION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  only:
    refs:
      - main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pipeline is split in two stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stage

&lt;ul&gt;
&lt;li&gt;create_app_version

&lt;ul&gt;
&lt;li&gt;Bundle the source code at HEAD and publish to the S3 bucket&lt;/li&gt;
&lt;li&gt;Create a new application version and associate it to the bundle that was uploaded&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Deploy

&lt;ul&gt;
&lt;li&gt;deploy_version_to_env (manual)

&lt;ul&gt;
&lt;li&gt;Upload the new application version to the (already established and running) Elastic Beanstalk environment&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This pipeline will trigger when the &lt;code&gt;main&lt;/code&gt; branch is updated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup CI/CD pipeline env variables
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Settings → CI/CD&lt;/li&gt;
&lt;li&gt;Variables → Expand&lt;/li&gt;
&lt;li&gt;Add the following keys

&lt;ul&gt;
&lt;li&gt;APP_NAME: eb-node-sandbox&lt;/li&gt;
&lt;li&gt;AWS_ID: xxxxx&lt;/li&gt;
&lt;li&gt;AWS_ACCESS_KEY_ID: xxxx&lt;/li&gt;
&lt;li&gt;AWS_SECRET_ACCESS_KEY: xxxxxxx&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z6YrdHFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmie044eo2fm4i3qr70b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z6YrdHFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmie044eo2fm4i3qr70b.png" alt="Elastic Beanstalk Environment Variables" width="702" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;If you are following this tutorial, make sure to terminate your environment. This will help you avoid unexpected running costs that AWS will bill you for. Refer to the action drop-down menu to &lt;code&gt;Terminate environment&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E2TbkyHi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otqbzy1g4r9y4mr7qh3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E2TbkyHi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otqbzy1g4r9y4mr7qh3n.png" alt="Terminate Environment" width="705" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Avoiding manual processes by automating can save a lot of time and unintended mistakes. It is possible to also add a test stage that is not allowed to fail in order to prevent publishing bad software to your environment. &lt;/p&gt;

</description>
      <category>node</category>
      <category>cicd</category>
      <category>javascript</category>
      <category>aws</category>
    </item>
    <item>
      <title>How to Support Environment Variables - Node Application - Elasticbeanstalk</title>
      <dc:creator>sanchezg7</dc:creator>
      <pubDate>Fri, 10 Feb 2023 14:55:25 +0000</pubDate>
      <link>https://dev.to/sanchezg7/how-to-support-environment-variables-node-application-elasticbeanstalk-hfn</link>
      <guid>https://dev.to/sanchezg7/how-to-support-environment-variables-node-application-elasticbeanstalk-hfn</guid>
      <description>&lt;h2&gt;
  
  
  Problem statement
&lt;/h2&gt;

&lt;p&gt;You have a node application that needs to support variances in environment variables; however, this application is hosted in Elasticbeanstalk. This post will show how to enable environment variable support for your node application. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;

&lt;p&gt;Environment variables allows flexibility to your code without having to have hard code values that could change for various reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You don’t control the values

&lt;ul&gt;
&lt;li&gt;Third party integrations&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;The value varies based on the environment

&lt;ul&gt;
&lt;li&gt;DEV, UAT, STAGING, PROD, etc&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;The values can determine some conditional execution path

&lt;ul&gt;
&lt;li&gt;Disable emails&lt;/li&gt;
&lt;li&gt;Control logging patterns&lt;/li&gt;
&lt;li&gt;Feature toggles
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  How
&lt;/h2&gt;

&lt;p&gt;We need a file to standardize environment variable support in the application. Create a file named &lt;code&gt;env.js&lt;/code&gt;. It will export an object containing everything in &lt;code&gt;process.env&lt;/code&gt; in addition to a specific &lt;code&gt;PORT&lt;/code&gt; variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;import dotenv from &lt;span class="s2"&gt;"dotenv"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

// injects values from the .env file into process.env
dotenv.config&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

const PORT &lt;span class="o"&gt;=&lt;/span&gt; process.env.PORT &lt;span class="o"&gt;||&lt;/span&gt; 8080&lt;span class="p"&gt;;&lt;/span&gt;

const resolved &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; ...process.env, PORT &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;export &lt;/span&gt;default resolved&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assume we have a basic node express application. For ease of debugging, add a basic route displaying some environment variable &lt;code&gt;MY_ENV_VALUE&lt;/code&gt;. It will return a specific environment variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./env.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/env&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MY_ENV_VALUE&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="nx"&gt;MY_ENV_VALUE&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Running on Port: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running the application in Elasticbeanstalk and sending a request to &lt;code&gt;GET /env&lt;/code&gt; will show the environment variable as undefined. &lt;/p&gt;

&lt;p&gt;Let’s define it in Elasticbeankstalk. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to Configuration&lt;/li&gt;
&lt;/ul&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%2Fw257zzndojwse14k3rjd.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%2Fw257zzndojwse14k3rjd.png" alt="Configuration Menu" width="708" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Find the &lt;code&gt;Software&lt;/code&gt; section. Select &lt;code&gt;Edit&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&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%2F8zknlgyjo5yqp5iozxdc.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%2F8zknlgyjo5yqp5iozxdc.png" alt="Software-Edit Option" width="703" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set the environment key and value. Select &lt;code&gt;Apply&lt;/code&gt; .&lt;/li&gt;
&lt;/ul&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%2Flswy0wficntfgm675ujh.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%2Flswy0wficntfgm675ujh.png" alt="Set environment key and value" width="703" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wait for environment to reload with the new environment properties we specified. The environment property will be added to &lt;code&gt;process.env&lt;/code&gt; and by design, will be exposed in the &lt;code&gt;env&lt;/code&gt; module we exported earlier.&lt;/li&gt;
&lt;/ul&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%2Fl075yugrqbskb9olxh4z.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%2Fl075yugrqbskb9olxh4z.png" alt="EB Environment Relaunching" width="701" height="497"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Once the environment is done refreshing, launch it in the browser.&lt;/p&gt;

&lt;p&gt;GET /env shows:&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%2Fx40itxtftp8ihyu5cwr3.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%2Fx40itxtftp8ihyu5cwr3.png" alt="GET /env browser request" width="702" height="130"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Supporting environment variables in your application will allow for scalable applications that do not need changes to support variances in your environments. If you need to support secret environment variables I recommend using AWS KMS &lt;a href="https://aws.amazon.com/kms/" rel="noopener noreferrer"&gt;https://aws.amazon.com/kms/&lt;/a&gt;, this service will encrypt your keys at rest and give you more granular access control of the values.&lt;/p&gt;

</description>
      <category>express</category>
      <category>api</category>
      <category>googlecloud</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
