Demonstrate Mongo ECS Replica setup with terraform, it will setup 3 MongoDb nodes in ECS with EC2 launch type
Run terraform init
Run terraform plan
Run terraform apply --auto-approve
Run terraform destroy --auto-approve
Run the brew command:-
brew tap dkanejs/aws-session-manager-plugin
and
brew install aws-session-manager-plugin
Verify the session manager plugin:-
session-manager-plugin
Edit SSH config in ~/.ssh/config
(MAC) or window C:\Users\username\.ssh\config
and add the following content:-
For Mac:-
host i-* mi-*
ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
Or Window:-
host i-* mi-*
ProxyCommand C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p"
ssh -i /path/my-key-pair.pem username@instance-id
ssh -i /path/my-key-pair.pem username@instance-id -L localport:targethost:destport
You can port forward multiple ports for testing your application
After configure SSH proxy, run command make tunnel
to connect, and provide default password mypassword
to open tunnel to EC2 instance
In order to use Seed list connection string in SSH tunnel, you need configure primary node to map localhost. Edit host file /private/etc/hosts
, add the following entry:-
127.0.0.1 mongo-ecs-primary.ecs.demo
Use the following connection string to access Replica nodes:-
mongodb://root:mypassword@localhost:27017,localhost:27018/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false