Git Product home page Git Product logo

meanstack_with_atlas_on_fargate's Introduction

App Modernization with AWS Fargate(ECS) and MongoDB Atlas

Introduction:

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

  1. Serverless Application Deployment for Production Environment
  2. Production deployment to auto-scale, HA, and Security
  3. Agile development of application modernization
  4. Deployment of containerized application in AWS
  5. 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).

Architecture Diagram:

image

Pre-requisite:

Code editor: VSCode

Code repository: Git

Command Line execution: AWS CLI

Container: Docker Desktop (with docker compose)

image

Side Note: Ensure the versions are managed as shown. Will have compatibility issues with the latest versions.

Step-by-Step Fargate Deployment:

Step1a: Set up the MongoDB Atlas cluster

Please follow the link to set up a free cluster in MongoDB Atlas

Step1b: Configure the Network access **

Configure the database for network security

Step1c: Set up the Role-based Authentication

Follow the link for IAM Role based authentication for AWS Fargate

On successful creation of the role, click "Add permissions" and select "Attach policies" to add "AmazonEC2ContainerRegistryReadOnly" policy to the role.

image

Copy the ARN created for the role

Select IAM Type as IAM role in MongoDB Atlas for the database user and provide the ARN as shown below

image

**Step2: Copy the code and configure **

git clone the code from the repository

          git clone https://github.com/mongodb-partners/MEANStack_with_Atlas_on_Fargate.git
          
          cd code/MEANSTACK/partner-meanstack-atlas-fargate

Open the code in VSCode

Configure the MongoDB Connection string in ".env" in partner-meanstack-atlas-fargate --> server --> .env file. Update the server details.

image

**Step3a: Create the Elastic Container Repository(ECR) **

Setup the AWS CLI environment

Create the ECR for the client and note down the URI for the repository.

              	aws ecr create-repository \
              --repository-name partner-meanstack-atlas-fargate-client \
              --image-scanning-configuration scanOnPush=true \
              --region us-east-1

Create the ECR for the backend and note down the URI for the repository.

	aws ecr create-repository \
              --repository-name partner-meanstack-atlas-fargate-server \
              --image-scanning-configuration scanOnPush=true \
              --region us-east-1

**Step3b: Open the code and update for docker-compose.yaml **

Configure the Docker image in "docker-compose.yml" in partner-meanstack-atlas-fargate folder.

Update the details for x-aws-vpc , x-aws-role, and images of both server and client, and platform. For the image, paste the URI copied from the earlier step.

Ensure the VPC has having least two public subnets in different AZs. if any of the subnets are in the same AZs, the docker-compose up command will fail.

image

Ensure the docker desktop is up and running. if not start the docker deamon

**Step4: Build the docker image and push it to ECR **

update the ECR URI with the account_id in the below command.

ensure the current directory is ...code/partner-meanstack-atlas-fargate

	aws ecr get-login-password --region us-east-1| docker login --username AWS --password-stdin <account_id>.dkr.ecr.us-east-1.amazonaws.com

	docker context use default

	docker compose build

	docker compose push

	docker context create ecs  partner-meanstack-atlas-fargate

	docker context use partner-meanstack-atlas-fargate

	docker compose up

Note: While creating the docker context, it will give the option for selecting the AWS authentication. Choose the default. Please refer link for further details


? Create a Docker context using: [Use arrows to move, type to filter]

An existing AWS profile

AWS secret and token credentials

AWS environment variables


This will automatically create the AWS CloudFormation stack and deploy the stack.

Verify that the stack is completed successfully

Verify the ECS cluster, task definition, and services are created successfully.

image

image

image

Copy the DNS Name from the Load Balancer

image

update the private URL in the code with the copied DNS Name. (partner-meanstack-atlas-fargate --> client --> src --> app --> employee.service.ts )

image

Ensure the code is saved successfully.

complete the rebuild. It will be a rolling update and the changes will be deployed, without impact to the running instances.

	docker context use default
	
	docker compose build
	
	docker compose push
	
	docker context use partner-meanstack-atlas-fargate

	docker compose up

Ensure that both the client and server tasks are up and running after the update.

image

Ensure the AWS Cloud map service is registered with both client and server services.

image

copy the public IP address of the client task

image

Step7: Testing the Application

Test the application by invoking the public ipaddress:8080 copied from the above step.

image

Summary:

Hope this provides the steps to successfully deploy the containerized application onto AWS Fargate.

Pls share your feedback/queries to [email protected]

meanstack_with_atlas_on_fargate's People

Contributors

babusrinivasan76 avatar utsavmongodb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.