NEAR Protocol integrates cleanly with AWS services. This guide covers the most common patterns for developers building production applications that combine NEAR blockchain with AWS infrastructure.
Architecture Overview
A typical NEAR + AWS stack: EC2 or ECS for NEAR RPC node (optional, can use public RPC), Lambda for event-driven processing of NEAR transactions, DynamoDB or S3 for indexed blockchain data, CloudWatch for monitoring and alerting, and CodePipeline for CI/CD of NEAR contracts.
NEAR RPC Node on EC2
For production applications needing reliable RPC access without depending on public nodes:
# Instance type recommendation: r6i.2xlarge (64GB RAM, 8 vCPU) # Storage: 2TB gp3 SSD for archival node, 500GB for non-archival # Install nearcore curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh git clone https://github.com/near/nearcore.git cd nearcore && git checkout $(cat RELEASE_VERSION) cargo build -p neard --release # Initialize node ./target/release/neard --home ~/.near init --chain-id mainnet # Download latest snapshot (faster than syncing from genesis) curl -L https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/mainnet/config.json \ -o ~/.near/config.json # Sync state with AWS S3 public snapshot aws s3 --no-sign-request cp s3://near-protocol-public/backups/mainnet/rpc/latest /tmp/ # Extract to ~/.near/data/
Lambda for NEAR Event Processing
Process NEAR transactions reactively using Lambda + DynamoDB Streams or scheduled polling:
import json
import boto3
import requests
from datetime import datetime
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('near-transactions')
NEAR_RPC = 'https://rpc.mainnet.near.org'
def lambda_handler(event, context):
# Get latest block
response = requests.post(NEAR_RPC, json={
"jsonrpc": "2.0",
"id": "dontcare",
"method": "block",
"params": {"finality": "final"}
})
block = response.json()['result']
block_height = block['header']['height']
# Process transactions in the block
for chunk_hash in block['chunks']:
chunk = get_chunk(chunk_hash['chunk_hash'])
for tx in chunk.get('transactions', []):
process_transaction(tx, block_height)
return {'statusCode': 200}
def process_transaction(tx, block_height):
# Index to DynamoDB
table.put_item(Item={
'tx_hash': tx['hash'],
'signer_id': tx['signer_id'],
'receiver_id': tx['receiver_id'],
'block_height': block_height,
'timestamp': datetime.utcnow().isoformat()
})
def get_chunk(chunk_hash):
response = requests.post(NEAR_RPC, json={
"jsonrpc": "2.0",
"id": "dontcare",
"method": "chunk",
"params": {"chunk_id": chunk_hash}
})
return response.json()['result']
DynamoDB Schema for NEAR Data
A practical schema for indexing NEAR transactions:
# Primary table: transactions
# Partition key: tx_hash (String)
# Sort key: block_height (Number)
# GSI 1: by account
# Partition key: account_id (String)
# Sort key: block_height (Number)
# GSI 2: by receiver
# Partition key: receiver_id (String)
# Sort key: timestamp (String ISO 8601)
# S3 for large data (contract state, WASM files)
# Bucket: near-contract-data
# Key pattern: {network}/{account_id}/{timestamp}.json
CloudWatch Monitoring
Key metrics to monitor for NEAR applications:
import boto3
cloudwatch = boto3.client('cloudwatch')
def publish_near_metrics(rpc_latency_ms, block_lag, failed_txs):
cloudwatch.put_metric_data(
Namespace='NEAR/Application',
MetricData=[
{
'MetricName': 'RPCLatency',
'Value': rpc_latency_ms,
'Unit': 'Milliseconds'
},
{
'MetricName': 'BlockLag',
'Value': block_lag,
'Unit': 'Count'
},
{
'MetricName': 'FailedTransactions',
'Value': failed_txs,
'Unit': 'Count'
}
]
)
# CloudWatch Alarm: Alert when block lag exceeds 100 blocks
# This indicates your indexer is falling behind the chain
CI/CD with CodePipeline
# buildspec.yml for NEAR contract deployment
version: 0.2
env:
secrets-manager:
NEAR_PRIVATE_KEY: near-testnet/deployer-key
phases:
install:
commands:
- curl --proto https --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- source $HOME/.cargo/env
- rustup target add wasm32-unknown-unknown
- npm install -g near-cli
build:
commands:
- cargo build --target wasm32-unknown-unknown --release
- cp target/wasm32-unknown-unknown/release/contract.wasm .
post_build:
commands:
- near deploy contract.testnet.near contract.wasm
- near call contract.testnet.near migrate '{}' --accountId deployer.testnet
artifacts:
files:
- contract.wasm
Security Best Practices for AWS + NEAR
Store NEAR private keys in AWS Secrets Manager, never in environment variables or code. Use IAM roles for Lambda functions with minimal permissions. Enable CloudTrail logging for all API calls. Use VPC endpoints for DynamoDB to avoid public internet exposure. Rotate NEAR keys stored in Secrets Manager on a schedule using Lambda.
Written by Alex Chen | alexchen.chitacloud.dev | February 26, 2026