Monday, December 16, 2019

AWS CLI describe-instances? Or describe-network interfaces

Using AWS CLI including explanation 


Que) sort output of describe-instances? Or describe-network interfaces ? 


Ex: aws ec2 describe-network-interfaces --region
us-east-1 --filters "Name=tag:Name,Values='Name_any*'
"  --query 'NetworkInterfaces[?Status==`available`]'


Now to take exact things out first flatten
o/p in bracket like structure as below


# aws ec2 describe-network-interfaces --region
us-east-1 --filters "Name=tag:Name,Values='Nameofinstance*'"  --query 'NetworkInterfaces[?Status==`available`].[NetworkInterfaceId,TagSet[*].Value | [0].Value]'


o/p
[
    [
        "eni-########",
        null
    ],
    [
        "eni-########",
        null
    ],
    [
        "eni-########",
        null
    ],
    [
        "eni-########",
        null
    ]
]


In above o/p eni is first column and null is 2nd
Will print 1st column using jmes path using sort_by 
Syntax [] | sort_by(@, &[3])

#aws ec2 describe-network-interfaces
--region us-east-1 --filters
"Name=tag:Name,Values='Nameofinstance*'"
--query 'NetworkInterfaces[?Status==
`available`].[NetworkInterfaceId,TagSet[*]
.Value | [0]] | sort_by(@, &[1])'

mongodb upgrade 3.6 to 4.0

1)  To Upgrade Mongo 3.6 to 4.0 The 3.6 instance must have
featureCompatibilityVersion set to 3.6. 


2) To check featureCompatibilityVersion:


>db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )


       The operation should return a result that includes: 


"featureCompatibilityVersion" : { "version" : "3.6" }.


3) if not then set featureCompatibilityVersion as below


 > db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )


Upgrade Process
1) now upgrade repo to 4  with name mongodb-org-4.0.repo

[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.6/
x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

# yum repolist all 

# yum upgrade mongodb-org
Remove pv0 for Replica Sets
# Starting in version 4.0, MongoDB removes the deprecated replica
set protocol version 0 pv0.
# Before upgrading to MongoDB 4.0, you must upgrade to pv1.
# To upgrade to pv1, connect a mongo shell to the replica set primary
and perform the following sequence of operations:
Steps i followed as below #

cfg = rs.conf();
cfg.protocolVersion=1;
rs.reconfig(cfg);

# Set future compatibility version to 4.0 go to primary and fire below
command on mongo shell 
>db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )

# Then check all secondary it must show 3.6 as compatible version to
upgrade it 4.0

# Now stop mongod on secondary

# Then upgrade repo to 4.0

# And restart mongod after restart it must be secondary 

# Now go to primary do the same up gradation procedure now all
replica set is in 4.0 

# Last step set future compatibility version to 4.0 go to mongo
primary and fire this command

>db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )

# Last Step check record count in both dbs go to mongo shell use db to check 
>mongo
>use locationdataV3
>db.LocationData.count()
#################### Done ###############################