Amazon Managed Blockchain
Management Guide

Step 6: Create a Hyperledger Fabric Channel

In Hyperledger Fabric, a ledger exists in the scope of a channel. The ledger can be shared across the entire network if every member is operating on a common channel. A channel also can be privatized to include only a specific set of participants. Members can be in your AWS account, or they can be members that you invite from other AWS accounts.

In this step, you set up a basic channel. Later on in the tutorial, in Step 8: Invite Another AWS Account to be a Member and Create a Joint Channel, you go through a similar process to set up a channel that includes another member.

Step 6.1: Create configtx for Hyperledger Fabric Channel Creation

The configtx.yaml file contains details of the channel configuration. For more information, see Channel Configuration (configtx) in the Hyperledger Fabric documentation.

Use a text editor to create a file with the following contents and save it as configtx.yaml on your Hyperledger File client. Replace MemberID with the MemberID you returned previously. For example m-K46ICRRXJRCGRNNS4ES4XUUS5A.

Important

This file is sensitive. Artifacts from pasting can cause the file to fail with marshalling errors. We recommend using emacs to edit it. You can also use VI, but before using VI, enter :set paste, press i to enter insert mode, paste the contents, press escape, and then enter :set nopaste before saving.

################################################################################ # # Section: Organizations # # - This section defines the different organizational identities which will # be referenced later in the configuration. # ################################################################################ Organizations: - &Org1 # DefaultOrg defines the organization which is used in the sampleconfig # of the fabric.git development environment Name: MemberID # ID to load the MSP definition as ID: MemberID MSPDir: /opt/home/admin-msp # AnchorPeers defines the location of peers which can be used # for cross org gossip communication. Note, this value is only # encoded in the genesis block in the Application section context AnchorPeers: - Host: Port: ################################################################################ # # SECTION: Application # # - This section defines the values to encode into a config transaction or # genesis block for application related parameters # ################################################################################ Application: &ApplicationDefaults # Organizations is the list of orgs which are defined as participants on # the application side of the network Organizations: ################################################################################ # # Profile # # - Different configuration profiles may be encoded here to be specified # as parameters to the configtxgen tool # ################################################################################ Profiles: OneOrgChannel: Consortium: AWSSystemConsortium Application: <<: *ApplicationDefaults Organizations: - *Org1

Run the following command to generate the configtx peer block:

[ec2-user@ip-192-0-2-17 ~]$ docker exec cli configtxgen \ -outputCreateChannelTx /opt/home/mychannel.pb \ -profile OneOrgChannel -channelID mychannel \ --configPath /opt/home/

Important

Hyperledger Fabric 1.2 requires that a channel ID contain only lowercase ASCII alphanumeric characters, dots (.), and dashes (-). It must start with a letter, and must be fewer than 250 characters.

Step 6.2: Set Environment Variables for Convenience

Set the following environment variables for convenience. Replace the following values as indicated:

  • m-K46ICRRXJRCGRNNS4ES4XUUS5A is the MemberID returned by the aws blockchain list-members AWS CLI command and shown on the member details page of the Managed Blockchain console.

  • orderer.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.amazonaws.com:30001 is the OrderingServiceEndpoint returned by the aws blockchain get-network command and listed on the network details page of the Managed Blockchain console.

  • nd-6EAJ5VA43JGGNPXOUZP7Y47E4Y.m-K46ICRRXJRCGRNNS4ES4XUUS5A.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.us-east-1.amazonaws.com:30003 is the PeerEndpoint returned by the aws blockchain list-nodes command and listed on the node details page of the Managed Blockchain console.

[ec2-user@ip-192-0-2-17 ~]$ export MSP_PATH=/opt/home/admin-msp [ec2-user@ip-192-0-2-17 ~]$ export MSP=m-K46ICRRXJRCGRNNS4ES4XUUS5A [ec2-user@ip-192-0-2-17 ~]$ export ORDERER=orderer.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.amazonaws.com:30001 [ec2-user@ip-192-0-2-17 ~]$ export PEER=nd-6EAJ5VA43JGGNPXOUZP7Y47E4Y.m-K46ICRRXJRCGRNNS4ES4XUUS5A.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.us-east-1.amazonaws.com:30003

These variables must be exported each time you log out of the client. To persist the variables across sessions, add the export statement to your ~/.bash_profile as shown in the following example.

# .bash_profile ...other configurations export MSP_PATH=/opt/home/admin-msp export MSP=MemberID export ORDERER=OrderingServiceEndpoint export PEER=PeerNodeEndpoint

After updating .bash_profile, apply the changes:

[ec2-user@ip-192-0-2-17 ~]$source ~/.bash_profile

Step 6.3: Create the Channel

Run the following command to create a channel using the variables that you established and the configtx peer block that you created:

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 mychannel \ -f /opt/home/mychannel.pb -o $ORDERER \ --cafile /opt/home/managedblockchain-tls-chain.pem --tls

Step 6.4: Join Your Peer Node to the Channel

Run the following command to join the peer node that you created earlier to the channel:

[ec2-user@ip-192-0-2-17 ~]$ 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 mychannel.block \ -o $ORDERER --cafile /opt/home/managedblockchain-tls-chain.pem --tls