How Do You Upload Aws to Github
In this article, I'chiliad going to practice a walkthrough of how to deploy our Nodejs app to Elastic Beanstalk, but start I'thousand going to give a cursory overview of the service.
Overview of Elastic Beanstalk
AWS Elastic beanstalk is a managed service which means AWS automatically handles capacity provisioning, load balancing, scaling, application wellness monitoring, and instance configuration, leaving just application code as the responsibility of the programmer. It is a developer-axial view of deploying an application on AWS.
Rubberband beanstalk enables us to be able to leave provisioning of services to AWS while still having full command over the configuration. Elastic beanstalk can be very useful for companies and startups that do not accept a large engineering team and would rather just focus on the logic of their app. Beanstalk is free to use, just yous pay for the underlying instances and provisioned resource.
Components of Elastic Beanstalk
-
Application: This includes the collection of environments, versions, configurations and all the components in general.
-
Application Version: This is an iteration of your awarding code.
-
Environment: This is the collection of AWS resources running on an application version. Multiple environments tin can be created. i.e dev, examination, product
Supported Platforms
-
Go
-
Java SE
-
Nodejs
-
PHP
-
Python
-
Ruby
-
.Net
-
Docker
Note: If your language/platform isn't supported, you can write your custom platform.
Deployment Presets
-
Single Instance: This is great for evolution. The code is deployed to 1 availability zone on 1 EC2 instance.
-
High Availability: This is great for production. Yous become an application load balancer, and your lawmaking is deployed to two AZ's and also ii EC2 instances.
-
Custom Configuration: This allows you lot to use whatever custom configuration you want to.
Deployment Options for Updates
-
All at once (deploy all in one go) – fastest, merely instances aren't available to serve traffic for a bit (downtime)
-
Rolling: update a few instances at a time (saucepan), and then move onto the next saucepan once the commencement saucepan is healthy
-
Rolling with additional batches: like rolling, just spins up new instances to motion the batch (so that the sometime application is still available)
-
Immutable: spins up new instances in a new car-scaling grouping, deploys version to these
instances, and then swap all the instances when everything is healthy
Deployment Process
-
First, you take to describe dependencies eastward.g (requirements.txt for python, package.json for Nodejs)
-
Package code every bit Zip
-
Console: upload the zip file (creates new app version), so deploy
-
CLI: create a new app version using CLI (uploads zip), and and then deploy
Lifecycle Policy
-
Elastic Beanstalk tin can store at most 1000 application versions
-
If you lot don't remove old versions, you lot won't be able to deploy any more
-
To stage out old awarding versions, use a lifecycle policy
-
Versions that are currently used won't be deleted
-
Option non to delete the source packet in S3 to prevent data loss
Extensions
-
A zip file containing our lawmaking must be deployed to Elastic Beanstalk
-
All the parameters set in the UI can be configured with code using files
-
Requirements:
-
in the .ebextensions/ directory in the root of source code
-
YAML / JSON format
-
config extensions (example: logging.config)
-
Able to change some default settings using: option_settings
-
Ability to add resources such as RDS, ElastiCache, DynamoDB, etc…
-
-
Resources managed by .ebextensions get deleted if the environment goes away
Under the hood, AWS Elastic Beanstalk uses Cloudformation to provision resources needed which means we can define Cloudformation resources in the .ebextensions to provision annihilation nosotros want.
Deploying our Nodejs App to Elastic Beanstalk
Nosotros will need a pre-built sample of a Nodejs application, which you can download using this URL from GitHub – Aeeiee-Team/Nodejs-ElasticBeanstalk . You should also take a GitHub account, MongoDB Atlas business relationship and an AWS business relationship; you can create a free AWS account from https://aws.amazon.com/. Yous can sign up for MongoDB atlas here.
Click hither to create an AWS Account and enter your AWS User name and Password and information technology will open up the AWS Direction Console page. Click on All services and choose AWS Rubberband Beanstalk.
Fig i: AWS Elastic Beanstalk Dashboard page
To create an Application
Yous tin utilise the "Create Web app" console sorcerer to create your sample awarding by clicking on the "Create Application" push.
You'll specify the elastic beanstalk awarding name i.e demo-app
-
Click on the Platform drop-down and select your platform e.k: node.js. Platform branch and platform version will be auto-populated.
-
Select the Sample Awarding as application code and click on the "Create Application " push. It volition take few minutes to launch your awarding.
Fig ii: Creating a Spider web App Information page
We will deploy the sample application and and so utilize CI/CD to deploy our own custom application from GitHub.
Figure 3: Environment setup folio
When nosotros become to the URL provided by AWS, we see that our sample application has been deployed, now we tin can go and ready upwardly a CI/CD pipeline to deploy our custom application.
Effigy four: Surround overview page
When we go to the URL provided by AWS, we see that our sample application has been deployed, now nosotros can go and fix a CI/CD pipeline to deploy our custom awarding.
Figure 5: Deployed Sample app homepage
We will set up continuous integration and deployment(CI/CD) using AWS Code Pipeline Service. AWS Code pipeline services help u.s.a. to Build, Tests and Deploy code when there is any lawmaking changes in your source code.
I volition show how to create a simple pipeline that pulls code from the GitHub repository and automatically deploy it to AWS EC2 instances.
To practise this, go dorsum to your console, or click on the search bar, and search for "CodePipeline". It tin too be constitute under developer tools.
To get started, click on the "Create Pipeline" button.
Effigy half dozen: Lawmaking Pipeline page
Figure 7: Code Pipeline Settings page
Choose Pipeline settings
AWS source resources you created must be in the aforementioned region as your pipeline.
Stride ane: Enter the pipeline proper noun east.one thousand Demo-app
- In Service Role default to 'New Service Office', it will help CodePipeline to create a new service office in IAM.
- In Part Name default to 'AWSCodePipelineServiceRole-Region-pipeline proper name'. For example, this is the service role created for a pipeline named AWSCodePipelineServiceRole-us-west-2-musician-pipeline.
- Click on the Next Button as shown in the image above
Footstep two: Add together Source Stage
- On the Source page, under Source Provider, choose GitHub(Version 2).
- AWS recommends GitHub (Version ii) and you should stick to that for best practices
- If you have not created a GitHub connection, click on the "Connect to GitHub" button to grant permission to the AWS Code pipeline to access your GitHub repository. This will help AWS Code Pipeline to upload your committed changes from GitHub to AWS Code Pipeline.
Figure viii: Add source phase page
Input a connection name (in my case, I used demo), so click on "Connect to GitHub". It will bring an hallmark screen and y'all accept to authorize AWS to admission your GitHub account, later which the screen below pops up.
Figure nine: Create GitHub Connection
Click on the "Install a new app" push and another authority screen shows up and asks "Where do you lot desire to install AWS Connector for GitHub?". Select your account or GitHub organization where your demo app is (in case you are someone similar me with multiple GitHub organizations).
Figure 10: Install AWS Connector for GitHub
Once you lot've selected where the AWS connector volition exist installed, click on the "connect" push button and yous will be redirected to the "Add source stage" page where you volition see a observe that GitHub is gear up for use.
Figure xi: GitHub continued successfully
4. After Connection to Github, you'll be able to see a listing of your repositories, and select the 1 which you lot want to ready this code pipeline.
5. You'll also be able to choose the branch from which you want this pipeline to mind to and pull code.
Stride iii: Add Build Stage
-
You can skip the build stage every bit we don't need it for this pipeline
Pace four: Add Deploy Phase
- In Deploy provider, choose AWS Elastic Beanstalk.
- In Region, select the region where you have created your source code.
- For the Application name, enter or cull the name that yous have already created on the AWS Elastic Beanstalk console.
- In the Environment name, enter or choose the proper noun that you lot already created on the AWS Elastic Beanstalk console.
- Click the "Next" push button
Figure 12: Add deploy stage page
Subsequently clicking side by side, you will exist directed to the Pipeline 'Review Folio' and then you lot can click on the create pipeline button. Your code will and so be taken from the source and deployed to Elastic Beanstalk as shown below:
Figure 13: Lawmaking Pipeline Overview folio
And with this, our code should be deployed to Rubberband Beanstalk. We'll go dorsum to our Elastic Beanstalk URL and information technology works fine as seen in the prototype below.
Figure 14: Server Dwelling page
I'm using MongoDB for the purposes of this tutorial, and I'm going to go alee and connect to the MongoDB database using a connection string.
Steps to Add MongoDB connectedness string as an env variable
-
I'll navigate back to our Elastic Beanstalk dashboard and select my awarding
-
Choose a configuration from the navigation airplane
-
For theSoftwarecategory, cull Edit.
-
In theEnvironment backdrop section, enter the fundamental-value pairs for the environment backdrop that yous want to pass to your instances.
-
The cardinal for our database used in this tutorial is "DATA_DB" i.e DATA_DB={mongoDB connection string}
-
Click Use
Figure fifteen: Configuration Page
Now, I'll utilize postman to examination if my application works the style it should. I created a register endpoint in my code. I made a request to that endpoint with the necessary details and everything works fine as seen below.
Effigy 16: Postman test page
Conclusion
You can see information technology's very easy to deploy our code from GitHub using code pipeline to AWS Rubberband Beanstalk. If you follow this commodity for tutorial purposes only, you should brand sure to delete your environments and app when yous are done then yous don't incur unnecessary costs from AWS.
Source: https://www.aeeiee.com/blog/2021/11/10/deploying-your-nodejs-app-to-aws-elastic-beanstalk-from-github-using-codepipeline/
0 Response to "How Do You Upload Aws to Github"
Post a Comment