

# Work with Hyperledger Fabric Peer Nodes on AMB Access
Work with Peer Nodes

Hyperledger Fabric peer nodes do the work for your member on the network. They keep a local copy of the shared ledger, let you query the ledger, and interact with clients and other peer nodes to perform transactions. A new member has no peer nodes. Create at least one peer node per member.

Each peer node runs on a *AMB Access instance type*. You cannot add a custom Amazon EC2 instance to your member, nor can you connect an on-premises machine. The number of peer nodes and the AMB Access instance type of peer nodes available to each member depends on the network edition specified when the network was created. For more information, see [Amazon Managed Blockchain (AMB) Pricing](https://aws.amazon.com/managed-blockchain/pricing).

When you create a peer node, you select the following characteristics:
+ **AMB Access instance type**

  This determines the computational and memory capacity allocated to this node for the blockchain workload. You can choose more CPU and RAM if you anticipate a more demanding workload for each node. For example, your nodes may need to process a higher rate of transactions. Different instance types are subject to different pricing. You can monitor CPU and memory utilization to determine if your AMB Access instance type is appropriate. For more information, see [Use Hyperledger Fabric Peer Node Metrics on Amazon Managed Blockchain (AMB)](managed-blockchain-peer-node-metrics.md)
+ **Availability Zone**

  You can select the Availability Zone to launch the peer node in. The ability to distribute peer nodes in a member across different Availability Zones allows you to design your blockchain application for resiliency. For more information, see [Regions and Availability Zones](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html) in the *Amazon EC2 User Guide*.

  
+ **State DB configuration**

  This determines the type of state database that the peer node uses. **LevelDB** stores chaincode data as simple key-value pairs. It supports only key, key range, and composite key queries. 
+ **Logging configuration**

  You can enable peer node logs, chaincode logs, or both for a member. Peer node logs allow you to debug timeout errors associated with proposals and identify rejected proposals. Chaincode logs help you analyze and debug business logic. For more information, see [Monitoring AMB Access Hyperledger Fabric Using CloudWatch Logs](monitoring-cloudwatch-logs.md).

# Create a Hyperledger Fabric Peer Node on Amazon Managed Blockchain (AMB)
Create a Peer Node

You can create a Hyperledger Fabric peer node in a member that is in your AWS account using the AWS Management Console, the AWS CLI, or the AMB Access SDK [CreateNode](https://docs.aws.amazon.com/managed-blockchain/latest/APIReference/>API_CreateNode.html) action.

## To create a peer node using the AWS Management Console


1. Open the AMB Access console at [https://console.aws.amazon.com/managedblockchain/](https://console.aws.amazon.com/managedblockchain/).

1. Choose **Networks**, select the network from the list, and then choose **View details**.

1. Select a **Member** from the list, and then choose **Create peer node**.

1. Choose configuration parameters for your peer node according to the guidelines in [Work with Hyperledger Fabric Peer Nodes on AMB Access](managed-blockchain-hyperledger-peer-nodes.md), and then choose **Create peer node**.

## To create a peer node using the AWS CLI

+ Use the `create-node` command, as shown in the following example. Replace the value of `--network-id`, `--member-id`, and `AvailabilityZone` as appropriate.

  ```
  [ec2-user@ip-192-0-2-17 ~]$ aws managedblockchain create-node \
  --node-configuration '{"InstanceType":"bc.t3.small","AvailabilityZone":"us-east-1a"}' \
  --network-id n-MWY63ZJZU5HGNCMBQER7IN6OIU \
  --member-id m-K46ICRRXJRCGRNNS4ES4XUUS5A
  ```

  The command returns output that includes the peer node's `NodeID`, as shown in the following example:

  ```
  {
       "NodeId": "nd-6EAJ5VA43JGGNPXOUZP7Y47E4Y"
  }
  ```

# View Hyperledger Fabric Peer Node Properties on Amazon Managed Blockchain (AMB)
View Peer Node Properties

You can view information about each Hyperledger Fabric peer node that belong to your member using the AWS Management Console, the AWS CLI or the AMB Access API [GetNode](https://docs.aws.amazon.com/managed-blockchain/latest/APIReference/API_GetNode.html) command. Details include basic information like the AMB Access instance type, Availability Zone, and creation date, along with the following important properties:
+ Status
  + **Creating**

    AMB Access is provisioning and configuring the AMB Access instance for the peer node.
  + **Available**

    The peer node is running and available on the network.
  + **Failed**

    The peer node has an issue that has caused AMB Access to add it to the deny list on the network. This usually indicates that the peer node has reached memory or storage capacity. As a first step, we recommend that you delete the instance and provision an instance with more capacity.
  + **Create Failed**

    The node could not be created with the AMB Access instance type and the Availability Zone specified. We recommend trying another availability zone, a different instance type, or both.
  + **Deleting**

    The node is being deleted. This can happen because the node was deleted by the member, the member was deleted by the AWS account, or the member was deleted through an approved removal proposal.
  + **Deleted**

    The node has been deleted. See the previous item for possible reasons.
+ Endpoints

  Hyperledger Fabric uses endpoints associated with each peer node to identify the peer node on the network for different processes. AMB Access assigns unique peer node endpoints to each peer node on each network when the peer node is created. The peer node endpoint consists of the applicable port and the domain name of the peer node derived from the network ID, member ID, and peer node ID. For more information, see [Identifying AMB Access Resources and Connecting from a Client](network-components.md#network-components-connecting). Do not assume that the ports for a service are the same among members; different members may use different ports for the same service. Conversely, peer nodes in different networks may use the same ports, but their endpoints are always unique.
  + **Peer endpoint**

    Use this endpoint, including the port, within Hyperledger Fabric to address the peer node when using all services other than peer channel-based event services. 
  + **Peer event endpoint**

    Use this endpoint, including the port, within Hyperledger Fabric to address the peer node for peer channel-based event services.

You can also view and monitor **Metrics** related to peer node performance. For more information, see [Use Hyperledger Fabric Peer Node Metrics on Amazon Managed Blockchain (AMB)](managed-blockchain-peer-node-metrics.md).

You can check the peer node status using the `get-node` command, as shown in the following example:

```
aws managedblockchain get-node \
--network-id n-MWY63ZJZU5HGNCMBQER7IN6OIU \ 
--member-id m-K46ICRRXJRCGRNNS4ES4XUUS5A \
--node-id nd-6EAJ5VA43JGGNPXOUZP7Y47E4Y
```

The command returns output that includes the peer node's `PeerEndpoint` and `PeerEventEndpoint`, as shown in the following example. You need this endpoint and port when communicating with the node using your blockchain framework client or addressing the node within an application.

```
{
   "Node": { 
      "AvailabilityZone": "us-east-1a",
      "CreationDate": 2019-04-08T23:40:20.628Z,
      "FrameworkAttributes": { 
         "Fabric": { 
            "PeerEndpoint": "nd-6EAJ5VA43JGGNPXOUZP7Y47E4Y.m-K46ICRRXJRCGRNNS4ES4XUUS5A.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.us-east-1.amazonaws.com:30003",
            "PeerEventEndpoint": "nd-6EAJ5VA43JGGNPXOUZP7Y47E4Y.m-K46ICRRXJRCGRNNS4ES4XUUS5A.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.us-east-1.amazonaws.com:30004"
         }
      },
      "Id": "nd-6EAJ5VA43JGGNPXOUZP7Y47E4Y",
      "InstanceType": "bc.t3.small",
      "LogPublishingConfiguration": { 
         "Fabric": { 
            "ChaincodeLogs": { 
               "Cloudwatch": { 
                  "Enabled": true
               }
            },
            "PeerLogs": { 
               "Cloudwatch": { 
                  "Enabled": true
               }
            }
         }
      },
      "StateDB": "CouchDB"
      "Status": "AVAILABLE"
   }
}
```

# Use Hyperledger Fabric Peer Node Metrics on Amazon Managed Blockchain (AMB)
Use Peer Node Metrics

You can use peer node metrics to track the activity and health of Hyperledger Fabric peer nodes on Amazon Managed Blockchain (AMB) that belong to your member. You can use the AMB Access console to view the metrics for a peer node. AMB Access also reports metrics to Amazon CloudWatch. You can use CloudWatch to set up dashboards, receive alarms, and view log files for peer node metrics. For more information, see [Using Amazon CloudWatch Metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html) in the *Amazon CloudWatch User Guide*.

In addition to using peer node metrics, you optionally can enable CloudWatch Logs for peer nodes and for instances of chaincode running on a peer node to view **Peer node logs** and **Chaincode logs**. These logs are useful for troubleshooting and analysis of chaincode activity. For more information, see [Monitoring AMB Access Hyperledger Fabric Using CloudWatch Logs](monitoring-cloudwatch-logs.md).

AMB Access collects the following metrics for each peer node in the `aws/managedblockchain` namespace. Available metrics in AMB Access correspond to [Hyperledger Fabric metrics](https://hyperledger-fabric.readthedocs.io/en/release-2.2/metrics_reference.html).


| Metric name | Description | 
| --- | --- | 
| Fabric metrics | 
|  ChaincodeExecuteTimeouts  |  The number of chaincode executions (`Init` or `Invoke`) that have timed out. Units: Count  | 
|  EndorserProposalDuration  |  For each proposal, the time to complete the proposal. Units: Seconds  | 
|  EndorserProposalValidationFailures  |  The number of proposals that have failed initial validation. Units: Count  | 
|  EndorserProposalsReceived  |  The number of proposals received. Units: Count  | 
|  EndorserSuccessfulProposals  |  The number of successful proposals. Units: Count  | 
|  Transactions  |  The number of transactions that a peer node receives per minute. Units: Count  | 
| Utilization metrics | 
|  CPUUtilization  |  The percentage of total CPU capacity used on the peer node's AMB Access instance at any given instant. Units: Percent  | 
|  MemoryUtilization  |  The percentage of total available memory used on the peer node's AMB Access instance at any given instant. Units: Percent  | 

## Viewing Peer Node Metrics


You can use the Amazon Managed Blockchain (AMB) console to view graphs for peer node metrics. Metrics are available on the peer node details page.

**To view metrics using the AMB Access console**

1. Open the AMB Access console at [https://console.aws.amazon.com/managedblockchain/](https://console.aws.amazon.com/managedblockchain/).

1. Under **Network**, choose the **Name** of the network.

1. Choose **Members**. Under **Members owned by you**, choose the **Name** of the member to which the node belongs.

1. Under **Peer Nodes**, choose the **Node ID** you want to view.

   Under **Metrics**, tabs for **Channel Metrics** and **Utilization Metrics** are available.

1. For **Channel Metrics**, choose the channels you want to view or compare from the list.

1. Choose a chart and then use **Statistics**, **Time Range**, and **Period** to customize the chart.  
![\[Customizing a metrics chart in AMB Access.\]](http://docs.aws.amazon.com/managed-blockchain/latest/hyperledger-fabric-dev/images/metrics_chart.png)