This is a technical repo to demonstrate the application deployment using MongoDB Atlas and AWS Fargate. This tutorial is intended for those who want to
- Serverless Application Deployment for Production Environment
- Production deployment to auto-scale, HA, and Security
- Agile development of application modernization
- Deployment of containerized application in AWS
- Want to try out the AWS Fargate 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 developer workload on the development and management of the database environment. It also provides a free tier to test out the application/database features.
AWS Fargate is a serverless, pay-as-you-go compute engine that lets you focus on building applications without managing servers. AWS Fargate is compatible with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS).
AWS Console with cloud shell access
Node version v18.8.2 and above. (this code repository is not compatible for node v16.x.x)
Please follow the link to set up a free cluster in MongoDB Atlas
Configure the database for database access and network security
a. In AWS Console navigate to Secret Manager and click on Store a New secret
b. Choose Other type of secret then Plaintext tab and provide the full URL of MongoDB Atlas Cluster
c. Proceed to the next page where you supply the secret name as workshop/atlas_secret
d. Continue to other pages without any changes to store the secret
e. Confirm the secret is created by observing it listed on the page. Note: you might need to hit the refresh button to reload the secrets.
a. Login to AWS Console and launch the cloud shell
b. Install ECS Copilot CLI by running the following commands
sudo curl -Lo /usr/local/bin/copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && sudo chmod +x /usr/local/bin/copilot && copilot --help
c. Clone the GitHub repository for the code. Ensure node version is 18.x.x or above
git clone https://github.com/mongodb-partners/MEANStack_with_Atlas_on_Fargate.git
cd MEANStack_with_Atlas_on_Fargate/code/MEANSTACK/partner-meanstack-atlas-fargate
node --version
d. Install the Application and Environment
copilot init
Type your application a name atlasmean
and hit Enter Key
Next, select Load Balanced Web Service and hit Enter Key
We are now creating a service. There's a predefined service called server. Type server
as the service name.
Select the server/Dockerfile
from the menu and hit Enter key
Wait till initial infrastructure provisioning finishes and you are prompted for a deployment environment
Press y
to deploy
Supply the environment name dev
and hit Enter Key.
Ensure the server is deployed successfully.
For the frontend application to communicate to the server service, it needs to know the server service URI. We have a placeholder in the code where you need to make the change.
a. First, we need to find the server service DNS. In AWS Console, navigate to EC2 and then in Left Side Navigation to Load Balancing|Load Balancers. Note the DNS name in the bottom right part of the page.
b. Next update employee.service.ts
to point to the DNS. Leave the port as is.
c. Run the following command
nano client/src/app/employee.service.ts
d. Use arrow keys to navigate to the placeholder, and paste the DNS keeping the port number intact.
e. Ctrl-X
to save
a. Use the same command we used before copilot init
and select Load Balanced Web Service
b. Supply frontend
as the service name
c. Press y
to deploy, and chose the dev
environment we created earlier.
d. If you get the message below. Then type copilot deploy
.
e. Make sure you select frontend (using the spacebar)
f. Wait for the deployment process to complete in AWS Console CloudFormation UI or from the CloudShell. You should see at least one running task.
g. Now, you need to find the DNS for the frontend. Like before, navigate to EC2 --> Load Balancing --> Load Balancers. Note there are now two load balancers, one for the frontend and the other for the server. Select the frontend one. It has a listener configured on port 8080.
h. Now switch to the details tab and copy the DNS
Test the application by invoking the <"DNS for frontend loadbalancer">:8080 copied from the above step.
Resolving EACCES permissions errors when installing packages globally
AWS CloudShell compute environment: specifications and software
Congratulations!! you have successully deployed the containerized application onto AWS ECS Fargte.
Use the command copilot svc ls
to list all the servrices
Use the command copilot svc delete --name frontend
& copilot svc delete --name server
to delete the services
Pls share your feedback/queries in the comments