AWS ManagedBlockchain + Hyperledger Explorer quickstart (1)

rdg7739
4 min readMar 4, 2020

--

Easy steps to connect Hyperledger explorer with AWS ManagedBlockchain.

In this series of post, I’ll provide the steps to deploy the Hyperledger Fabric network to AWS ManagedBlockchain with Cloud9 IDE, configure Hyperledger Explorer and connect to Managed Blockchain

This article has the following structure:

  • Setup AWS ManagedBlockchain
  • Setup Cloud9
  • Dependency installs for Hyperledger Explorer

The following are prerequisites for this workshop:

  • Ability to log into the AWS account.
  • Permissions to: S3, Amazon Managed Blockchain.

Step 0: Setup ManagedBlockchain

Create a Blockchain Network with the following parameters:

  • Choose Hyperledger Fabric version 1.2
  • Provide a name for the network such as “blockchainBank”
  • Keep all other fields as default. -> Next
  • Enter a member name such as “bank1”
  • Please provides Admin credentials:
  • Admin name: “admin”
  • Password: “Admin123”. (This will be important later on.) -> Next

2. The network should now provision with a single member.

  • This will take a few minutes
  • Make sure you wait for the network to be ready. You will not be able to create a node if the network is not ready yet!

3. Create a Node.

  • Click into the network.
  • On the top tab, click on “Members”.
  • Click on the Member (bank1) in the “Members owned by you”
  • Click the “Create peer node” button.
  • Select “bc.t3.small” as your node instance type.-> “Create a peer node

Step 1. Setting Cloud9 Environment

1. Create a Cloud9 Environment

  • Open another tab and click create Cloud9
  • Keep all the values as is, but make sure to change ‘Platform’ to ‘Ubuntu Server 18.04 LTS’ instead of Amazon Linux

2. Select your Cloud9 Env and click ‘Open IDE’

Within a minute or two, you will have working Cloud IDE

3. Increase the size of Cloud9

When you are working on this project, You probably need more memory than the default size. Let’s use resize.sh script provided by AWS. In your Cloud9 environment, create a file with the following contents, and then save the file with the extension .sh, for example, resize.sh.

#!/bin/bash# Specify the desired volume size in GiB as a command-line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Install the jq command-line JSON processor.
sudo apt install -y jq
# Get the ID of the envrionment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data//instance-id)
# Get the ID of the Amazon EBS volume associated with the instance.
VOLUMEID=$(aws ec2 describe-instances --instance-id $INSTANCEID | jq -r .Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId)
# Resize the EBS volume.
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE
# Wait for the resize to finish.
while [ "$(aws ec2 describe-volumes-modifications --volume-id $VOLUMEID --filters Name=modification-state,Values="optimizing","completed" | jq '.VolumesModifications | length')" != "1" ]; do
sleep 1
done
# Rewrite the partition table so that the partition takes up all the space that it can.
sudo growpart /dev/xvda 1
# Expand the size of the file system.
sudo resize2fs /dev/xvda1

Now you can run the ‘resize.sh’ script to increase your EBS volume

sh resize.sh 20

4. Open Terminal and clone the repo.

You probably realized what kind of blockchain we will make, by the example name that I put it for the network. We will use the AWS bank-transfer workshop. But since their workshop is designed for Amazon Linux, I had to update the script for our use.

cd ~/environment/
git clone https://github.com/rdg7739/bank-transfer-blockchain-reinvent2019-workshop.git

5. Set up Cloud9 Environment

~/environment/bank-transfer-blockchain-reinvent2019-workshop/setup/setup_environment.sh

This will take a few minutes. When it’s complete please run the following:

source ~/.bash_profile
python ~/environment/bank-transfer-blockchain-reinvent2019-workshop/setup/setup_fabric_environment.py

You will be asked a series of questions. Select the network, member, and node that you have available to you. The script will then go and set up a few things:

  1. ‘~/fabric_exports’: contains environment variables that hold information about your network.
  2. An admin certificate: you can use it to sign requests sent to the network.
  3. Helper scripts in ~/bin/ location.
  4. VPC Endpoint: Allow your VPC to communicate to the Blockchain network. The script will also update security groups as necessary, and add any additional rules to ensure that your Cloud9 instance can communicate with the network.
  5. Copy public certificates to S3. so that if you choose to do the multi-member section, all other members can easily access the certificates.
source ~/fabric_exports
echo "source ~/fabric_exports" >> ~/.bash_profile

Part 2. Set up Dependencies for Hyperledger Explorer

This article is written using Hyperledger Explorer release-3.9.

Homebrew

If you don’t already have it installed follow the instructions on the site.

node.js (8.11.x) & PostgreSQL

Note that v9.x is not currently supported.

#Install node 8.11.1 
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
source ~/.profile
nvm install 8.11.1
nvm use 8.11.1
sudo apt-get install linuxbrew-wrapper -y
brew install postgres
# If error shows up, Enter the password
# Or if you do not know the password, simply press "Control+D"

Installing Postgres will take a few minutes.

Clone Hyperledger Explorer repo

cd ~/environment
git clone https://github.com/rdg7739/blockchain-explorer.git

I have updated script in ‘blockchain-explorer’ to be able to connect to AWS ManagedBlockchain

Now your environment is ready to go! On the upcoming posts, I’ll walk through each step to show how to configure and connect Hyperledger Explorer to Amazon ManagedBlockchain.

I hope you follow these steps without any issue. If you have faced any issue. Please leave the comments and I will help you out!

Thank you for reading! Let me know in a comment what you liked about this post or not.

--

--