Setting up Hyperledger Network and ChainCode Installation in AWS Managed Blockchain — Part 1

Rangesh Sripathi
6 min readJan 20, 2020

It’s tedious for any enterprise organization to create and manage Blockchain Network. Lets look at challenges to create and manage on-premise Infrastructure for Blockchain Network

Challenges with on-premise Blockchain Network

1. Maintenance of Network

2. Monitoring of Network

3. High Availability of Network

4. Dynamically Scaling out nodes / peers

5. Inviting / On-boarding partners to existing network in Blockchain

6. Managing Crypto materials of the network

Listed challenges can always be achieved with on-premise Blockhain network , but it’s quite challenging and it would always keep Devops/Network team on the edge. An alternate way is to use AWS Managed Blockchain(Blockchain as Service) which provides all the challenges as features in button-click.

What is AWS Managed Blockchain ?

AWS Managed Blockchain lets you easily create and manage scalable Blockchain Network. They support Hyperledger Fabric V1.2 today and probably sooner release Ethereum.

Advantages of AWS Managed Blockchain :

1. Setup Network with Button-Clicks

2. Adding partners to Network via Voting Mechanism

3.Easy to scale — You are free to roll different EC2 instances for peers

4.Secure VPC Endpoints

5. Fabric CA Keys is managed via AWS Key Management Service

6. Ordering service for Fabric is built out with Amazon QLDB.

Lets dive into creating a Blockchain Network with AWS Managemnt Blockchain Network with Hyperlegder Fabric.

**Pre-requisites : I would be discussing only steps to create and network and assuming audience are aware of Hyperleger Fabric and its core concept.

I would be using Cloud 9 and Cloud Formation Stack to create and manage AWS Blockchain.

Step 1:

Create Cloud 9 Environment for Sample Network : (US-EAST Region)

https://us-east-1.console.aws.amazon.com/cloud9/home/create

Step -2 :

I am leaving the default environments and using free-tier eligibility , would not recommend the same for production.

This will create EC2 instance and you can take a look at cloud formation. we would be using this create aws managed blockchain network via CLI.

https://console.aws.amazon.com/cloudformation/home?region=us-east-1

We would using the ngo-nonprofit sample through out the article.

Source :https://github.com/aws-samples/non-profit-blockchain

Let us download the sample and have the latest version of CLI, to achieve the same connect to your cloud9 EC2 instance and execute the following

cd ~
git clone https://github.com/aws-samples/non-profit-blockchain.git
sudo pip install awscli --upgrade

Step-3 :

The featured sample provides you an option to create managed network from CLI. i.e the shell scripts lets you create network , Org ,Peer and these are core components of network. You are always free to modify amb.sh with desired network and Org name, I am leaving ti to default for case of simplicity. Let’s execute the command and watch the output of cloudstack. This will take longer time to execute (Ideally 15–20 mins).

export REGION=us-east-1
export STACKNAME=non-profit-amb
cd ~/non-profit-blockchain/ngo-fabric
./amb.sh

Once network is created successfully , you should be able to see the following

Check AWS Managed Blockchain Network , you should be able to see ngo-network like below ,

https://console.aws.amazon.com/managedblockchain/home?region=us-east-1#networks

Its quite simple as that and we have created a network with an Org that has a single peer to it.

Step -4 :

Lets now create Fabric CLI which would interact with Orderer and Peer nodes, we would be creating a seperate EC2 instance for the same via Cloud Formation Stack.

export REGION=us-east-1
cd ~/non-profit-blockchain/ngo-fabric
./vpc-client-node.sh

Once we have stack created ,check for DNS name of EC2 instace and connect with respective key pair. i.e just ssh into it

cd ~
ssh ec2-user@<dns of EC2 instance> -i ~/<Fabric network name>-keypair.pem

Step -5 :

We will the ngo-fabric sample that has chaincode , node app and fabric -source.

git clone https://github.com/aws-samples/non-profit-blockchain.git

Step -6

Let us source and provide necessary export variables from created aws managed network by executing the below command

export REGION=us-east-1
cd ~/non-profit-blockchain/ngo-fabric
cp templates/exports-template.sh fabric-exports.sh
source fabric-exports.sh
source ~/peer-exports.sh

This should provide you output like below from the Fabric CLI EC2 instance

Step-7

Lets enroll an admin identity to create channel in the existing network.

export PATH=$PATH:/home/ec2-user/go/src/github.com/hyperledger/fabric-ca/bin
cd ~
fabric-ca-client enroll -u https://$ADMINUSER:$ADMINPWD@$CASERVICEENDPOINT --tls.certfiles /home/ec2-user/managedblockchain-tls-chain.pem -M /home/ec2-user/admin-msp

Step-8

Let us create Genesis block, channel and join the peer to channel.

a) Create Genesis block

docker exec cli configtxgen -outputCreateChannelTx /opt/home/$CHANNEL.pb -profile OneOrgChannel -channelID $CHANNEL --configPath /opt/home/

b) Create Channel

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
-e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
cli peer channel create -c $CHANNEL -f /opt/home/$CHANNEL.pb -o $ORDERER --cafile $CAFILE --tls --timeout 900s

c) Join Peer

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
-e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
cli peer channel join -b $CHANNEL.block -o $ORDERER --cafile $CAFILE --tls

You could also verify the channel creation from the AWS Managed Blockchain Network

Step -9 :

Let us Install / Instantiate/ Invoke/Query Sample Chaincode from CLI

a) Install chaincode :

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
-e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
cli peer chaincode install -n $CHAINCODENAME -v $CHAINCODEVERSION -p $CHAINCODEDIR

b) Instantiate Chaincode :

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
-e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
cli peer chaincode instantiate -o $ORDERER -C $CHANNEL -n $CHAINCODENAME -v $CHAINCODEVERSION \
-c '{"Args":["init","a","100","b","200"]}' --cafile $CAFILE --tls

c) Query Chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
-e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
cli peer chaincode query -C $CHANNEL -n $CHAINCODENAME -c '{"Args":["query","a"]}'

You have now created AWS Managed Blockchain solution with Cloud 9 and Cloud stack formation and have tested out by installing and invoking sample chaincode.

Source : https://github.com/aws-samples/non-profit-blockchain

I would recommend AWS Managed Blockchain for Enterprise Oragnization ,its easy to manage and scale.

--

--