This is a technical repo to demonstrate the application deployment using MongoDB Atlas and AWS Elastic Beanstalk. This tutorial is intended for those who want to
- Have a rapid application deployment
- Test out the features of an application
- Fail fast in their development cycle
- Want to try out the AWS Elastic Beanstalk and MongoDB Atlas
MongoDB Atlas is an all-purpose database having features like Document Model, Geo-spatial, Time-series, hybrid deployment, and multi-cloud services. It evolved as a "Developer Data Platform", intended to reduce the developers' workload on the development and management of the database environment. It also provides a free tier to test out the application/database features.
AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.
Please follow the link to setup a free cluster in MongoDB Atlas
Configure the database for network security and access.
Set up the Elastic Beanstalk cli based on your Operating System using the link
a. Git Clone the code from Repo
git clone https://github.com/mongodb-partners/MEANStack_with_Atlas_on_AWS_EB.git
b. Select database parameters in .env file and uncomment the line.(MEANSTACKwithAtlasonAWSEB --> partner-eb-meanstack-atlas --> server --> .env)
Refer the link for getting the MongoDB Atlas connection string
c. Set up the Elastic Beanstalk initialization parameters through eb init command
cd code/partner-eb-meanstack-atlas
eb init
Parameters for eb init:
a) Select a default region : 1 [ select the region in which you want to deploy the Elastic Beanstalk and note it down for future reference]
b) Select an application to use : Create new Application
Enter the application name : Select the default option.
c) It appears you are using Node.js. Is this correct?: "N"
d) Select a platform : 3) Docker
e) Select a platform branch. : default [ 1) Docker running on 64bit Amazon Linux 2)]
f) Cannot setup CodeCommit because there is no Source Control setup, continuing with initialization Do you want to set up SSH for your instances? : default [Y]
g) Select a keypair. : default
d. Create the environment with 'eb create'.
eb create --vpc
Note: if you want to use the default vpc or not using private link for MongoDB Atlas, use only "eb create".
a) Enter Environment Name : default [partner-eb-meanstack-atlas-dev]
b) Enter DNS CNAME prefix : default [partner-eb-meanstack-atlas-dev]
CNAME should be unique. if it gives an option on account of duplicate, select the default option suggested.
Copy and paste the DNS CNAME selected to the code as the private URL. Location: "client --> src --> app --> employee.service.ts (line 10)"
Ensure the CNAME selected and Private URL server names are the same.
Also ensure the region in the URL to updated to the region selected during eb init.
c) Enter the VPC ID: "Enter the VPCID to which the privatelink is created in MongoDB Atlas cluster"
d) Do you want to associate a public IP address? (Y/n): default
e) Enter a comma-separated list of Amazon EC2 subnets: enter the public subnets as comma separated
f) Enter a comma-separated list of Amazon ELB subnets: enter the public subnets as comma separated
g) Do you want the load balancer to be public? (Select no for internal) (Y/n):
h) Enter a comma-separated list of Amazon VPC security groups:
i) Select a load balancer type : default [application]
optional parameter:
Your account has one or more sharable load balancers. Would you like your new environment to use a shared load balancer? (y/N): default
j) Would you like to enable Spot Fleet requests for this environment? (y/N): default [N]
Refer the below screenshot for further details
k) Ensure the successful creation of the environment. It will take minimum 10mins to create the environment. The Health status will be initiall "Green" and then change to "Severe" , when the loadbalancer started to validate the backend. This is the normal flow.
l) Update the configuration parameters for Loadbalancer in the below sequence (only)
a. update the Processes - deafult : Change the port to 8000
b. Add a new process for the backend with port 5200 and HTTP code to 200,404
c. insert a new listener for the backend process created.
m) Ensure the configuration changes are applied successfully
Before testing the application, ensure the security group created by "eb create" command is opened for the port 80. This will ensure the health check is green
The endpoint of the application is displayed in the elastic beanstalk environment. ex: partner-eb-meanstack-atlas-dev2.us-east-1.elasticbeanstalk.com
Test the application for CRUD operations and ensure the data are reflected in MongoDB Atlas documents
Errors:
a) The current user does not have the correct permissions. Reason: Operation Denied. The security token included in the request is invalid.
b) ebcli.lib.aws : Error while contacting Elastic Beanstalk Service ERROR: ('Connection aborted.', gaierror(-2, 'Name or service not known'))
Steps:
a) Verify the AWS profile is set.
b) remove the folder .elasticbeanstalk (in partner-eb-meanstack-atlas directory) and restart the steps from begining.
To redeploy the solution:
ebs deploy
Any containerized application can be deployed within no time using this template. Please check out the Application Modernization with Fargate to have similar deployments on AWS Fargate
Pls share your feedback/queries to [email protected]