Installation Guide¶
Complete installation and configuration guide for @arcaelas/dynamite
This guide covers everything you need to install, configure, and verify @arcaelas/dynamite in your project.
Table of Contents¶
- Prerequisites
- Installation
- AWS Configuration
- Basic Configuration
- Verification
- Troubleshooting
- Next Steps
Prerequisites¶
Before installing @arcaelas/dynamite, ensure your development environment meets these requirements:
Node.js Version¶
- Node.js 16.x or higher (18.x or 20.x recommended)
- npm 7.x or higher or yarn 1.22.x or higher
Check your versions:
If you need to upgrade Node.js, we recommend using nvm:
AWS Account Requirements¶
You'll need one of the following:
- AWS Account with DynamoDB access
- Valid AWS credentials (Access Key ID and Secret Access Key)
- IAM permissions for DynamoDB operations
-
AWS region selection (e.g.,
us-east-1,eu-west-1) -
DynamoDB Local for development (recommended for testing)
- Docker installed (easiest method)
- Or Java Runtime Environment 8.x or higher
DynamoDB Table Setup¶
@arcaelas/dynamite can automatically create tables, but you should understand:
- Primary Key Structure: Each table needs a partition key (and optionally a sort key)
- Billing Mode: Choose between On-Demand or Provisioned capacity
- Table Naming: Tables are automatically named based on your model class names
Note: For production, you may want to create tables manually for better control over capacity and indexes.
TypeScript (Optional but Recommended)¶
- TypeScript 5.x or higher for full type safety
- Configure
tsconfig.jsonwith strict mode enabled
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
Installation¶
Install via npm¶
# Install @arcaelas/dynamite
npm install @arcaelas/dynamite
# Install peer dependencies
npm install @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
Install via yarn¶
# Install @arcaelas/dynamite
yarn add @arcaelas/dynamite
# Install peer dependencies
yarn add @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
Install via pnpm¶
# Install @arcaelas/dynamite
pnpm add @arcaelas/dynamite
# Install peer dependencies
pnpm add @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
Verify Installation¶
After installation, verify the packages are installed correctly:
You should see output similar to:
project@1.0.0 /path/to/project
├── @arcaelas/dynamite@x.x.x
├── @aws-sdk/client-dynamodb@x.x.x
└── @aws-sdk/lib-dynamodb@x.x.x
AWS Configuration¶
Option 1: DynamoDB Local (Recommended for Development)¶
DynamoDB Local is perfect for development and testing without AWS costs.
Using Docker¶
The easiest way to run DynamoDB Local:
# Pull and run DynamoDB Local
docker run -d \
-p 8000:8000 \
--name dynamodb-local \
amazon/dynamodb-local
Using Docker Compose¶
Create a docker-compose.yml file:
version: '3.8'
services:
dynamodb-local:
image: amazon/dynamodb-local
container_name: dynamodb-local
ports:
- "8000:8000"
command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "/home/dynamodblocal/data/"]
volumes:
- dynamodb_data:/home/dynamodblocal/data
working_dir: /home/dynamodblocal
volumes:
dynamodb_data:
driver: local
Start the service:
Using Java Runtime¶
If you don't use Docker, download and run DynamoDB Local directly:
# Download DynamoDB Local
wget https://s3.us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz
# Extract
tar -xvzf dynamodb_local_latest.tar.gz
# Run
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
Verify DynamoDB Local is Running¶
# Test connection
curl http://localhost:8000
# Or list tables (should return empty array initially)
aws dynamodb list-tables --endpoint-url http://localhost:8000 --region us-east-1
Option 2: AWS DynamoDB (Production)¶
For production deployment, use AWS DynamoDB.
Set Up AWS Credentials¶
Method 1: AWS CLI Configuration (Recommended)
# Install AWS CLI if not already installed
# https://aws.amazon.com/cli/
# Configure credentials
aws configure
# Enter your credentials when prompted:
# AWS Access Key ID: YOUR_ACCESS_KEY_ID
# AWS Secret Access Key: YOUR_SECRET_ACCESS_KEY
# Default region name: us-east-1
# Default output format: json
Method 2: Environment Variables
export AWS_ACCESS_KEY_ID="your-access-key-id"
export AWS_SECRET_ACCESS_KEY="your-secret-access-key"
export AWS_REGION="us-east-1"
Method 3: IAM Roles (For EC2, Lambda, ECS)
If running on AWS infrastructure, use IAM roles instead of credentials:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:PutItem",
"dynamodb:GetItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem",
"dynamodb:DescribeTable",
"dynamodb:CreateTable"
],
"Resource": "arn:aws:dynamodb:*:*:table/*"
}
]
}
Select Your AWS Region¶
Choose a region close to your users for lower latency:
us-east-1- US East (N. Virginia)us-west-2- US West (Oregon)eu-west-1- Europe (Ireland)ap-southeast-1- Asia Pacific (Singapore)- View all regions
Basic Configuration¶
Create Configuration File¶
Create a configuration file to initialize Dynamite:
config/database.ts (TypeScript)
import { Dynamite } from "@arcaelas/dynamite";
import { User, Order } from "./models"; // Import your model classes
export async function ConfigureDatabase() {
const config = process.env.NODE_ENV === "development"
? {
region: "us-east-1",
endpoint: "http://localhost:8000",
tables: [User, Order],
credentials: { accessKeyId: "test", secretAccessKey: "test" }
}
: {
region: process.env.AWS_REGION || "us-east-1",
tables: [User, Order],
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!
}
};
const dynamite = new Dynamite(config);
dynamite.connect();
await dynamite.sync();
return dynamite;
}
config/database.js (JavaScript)
const { Dynamite } = require("@arcaelas/dynamite");
const { User, Order } = require("./models"); // Import your model classes
async function ConfigureDatabase() {
const config = process.env.NODE_ENV === "development"
? {
region: "us-east-1",
endpoint: "http://localhost:8000",
tables: [User, Order],
credentials: { accessKeyId: "test", secretAccessKey: "test" }
}
: {
region: process.env.AWS_REGION || "us-east-1",
tables: [User, Order],
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
}
};
const dynamite = new Dynamite(config);
dynamite.connect();
await dynamite.sync();
return dynamite;
}
module.exports = { ConfigureDatabase };
Environment Variables Setup¶
Create a .env file in your project root:
# Development
NODE_ENV=development
DYNAMODB_ENDPOINT=http://localhost:8000
# Production (only set these in production)
# NODE_ENV=production
# AWS_REGION=us-east-1
# AWS_ACCESS_KEY_ID=your-access-key-id
# AWS_SECRET_ACCESS_KEY=your-secret-access-key
Install dotenv to load environment variables:
Load environment variables in your application:
// At the top of your main file (index.ts, app.ts, server.ts)
import dotenv from "dotenv";
dotenv.config();
import { ConfigureDatabase } from "./config/database";
ConfigureDatabase();
Define Your First Model¶
Create a simple User model to test the installation:
models/user.ts (TypeScript)
import {
Table,
PrimaryKey,
Default,
CreatedAt,
UpdatedAt,
CreationOptional,
NotNull
} from "@arcaelas/dynamite";
export class User extends Table<User> {
@PrimaryKey()
@Default(() => crypto.randomUUID())
declare id: CreationOptional<string>;
@NotNull()
declare name: string;
@NotNull()
declare email: string;
@Default(() => "customer")
declare role: CreationOptional<string>;
@Default(() => true)
declare active: CreationOptional<boolean>;
@CreatedAt()
declare createdAt: CreationOptional<string>;
@UpdatedAt()
declare updatedAt: CreationOptional<string>;
}
models/user.js (JavaScript)
const {
Table,
PrimaryKey,
Default,
CreatedAt,
UpdatedAt,
NotNull
} = require("@arcaelas/dynamite");
class User extends Table {
id;
name;
email;
role;
active;
createdAt;
updatedAt;
}
// Apply decorators
PrimaryKey()(User.prototype, "id");
Default(() => crypto.randomUUID())(User.prototype, "id");
NotNull()(User.prototype, "name");
NotNull()(User.prototype, "email");
Default(() => "customer")(User.prototype, "role");
Default(() => true)(User.prototype, "active");
CreatedAt()(User.prototype, "createdAt");
UpdatedAt()(User.prototype, "updatedAt");
module.exports = { User };
Complete Application Setup¶
index.ts (TypeScript)
import dotenv from "dotenv";
dotenv.config();
import { ConfigureDatabase } from "./config/database";
import { User } from "./models/user";
// Initialize database connection
ConfigureDatabase();
async function main() {
try {
// Create a new user
const user = await User.create({
name: "John Doe",
email: "john@example.com"
});
console.log("User created:", user);
console.log("ID:", user.id);
console.log("Name:", user.name);
console.log("Email:", user.email);
console.log("Role:", user.role);
console.log("Active:", user.active);
console.log("Created At:", user.createdAt);
// Query all users
const allUsers = await User.where({});
console.log("Total users:", allUsers.length);
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
}
main();
Verification¶
Step 1: Test Database Connection¶
Create a simple test file:
test-connection.ts
import dotenv from "dotenv";
dotenv.config();
import { Dynamite, Table, PrimaryKey, Default } from "@arcaelas/dynamite";
// Define a test model
class TestModel extends Table<TestModel> {
@PrimaryKey()
@Default(() => "test-id")
declare id: string;
}
async function TestConnection() {
try {
const dynamite = new Dynamite({
region: "us-east-1",
endpoint: process.env.DYNAMODB_ENDPOINT || "http://localhost:8000",
tables: [TestModel],
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID || "test",
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || "test"
}
});
dynamite.connect();
await dynamite.sync();
console.log("✓ Dynamite configured successfully");
console.log("✓ Connection test passed");
} catch (error) {
console.error("✗ Connection failed:", error);
process.exit(1);
}
}
TestConnection();
Run the test:
npm run build # If using TypeScript
node dist/test-connection.js
# Or with ts-node
npx ts-node test-connection.ts
Expected output:
Step 2: Test Model Operations¶
Create a comprehensive test:
test-model.ts
import dotenv from "dotenv";
dotenv.config();
import { ConfigureDatabase } from "./config/database";
import { User } from "./models/user";
ConfigureDatabase();
async function TestModelOperations() {
console.log("Starting model operations test...\n");
try {
// Test 1: Create
console.log("Test 1: Creating user...");
const user = await User.create({
name: "Test User",
email: "test@example.com"
});
console.log("✓ User created:", user.id);
// Test 2: Read
console.log("\nTest 2: Reading user...");
const foundUser = await User.first({ id: user.id });
console.log("✓ User found:", foundUser?.name);
// Test 3: Update
console.log("\nTest 3: Updating user...");
await User.update(user.id, { name: "Updated Name" });
const updatedUser = await User.first({ id: user.id });
console.log("✓ User updated:", updatedUser?.name);
// Test 4: Query
console.log("\nTest 4: Querying users...");
const users = await User.where({ active: true });
console.log("✓ Found", users.length, "active users");
// Test 5: Delete
console.log("\nTest 5: Deleting user...");
await User.delete(user.id);
const deletedUser = await User.first({ id: user.id });
console.log("✓ User deleted:", deletedUser === undefined);
console.log("\n✓ All tests passed!");
} catch (error) {
console.error("\n✗ Test failed:", error);
process.exit(1);
}
}
TestModelOperations();
Run the test:
Expected output:
Starting model operations test...
Test 1: Creating user...
✓ User created: abc-123-def-456
Test 2: Reading user...
✓ User found: Test User
Test 3: Updating user...
✓ User updated: Updated Name
Test 4: Querying users...
✓ Found 1 active users
Test 5: Deleting user...
✓ User deleted: true
✓ All tests passed!
Step 3: Verify Table Creation¶
Check that DynamoDB tables were created:
# For DynamoDB Local
aws dynamodb list-tables \
--endpoint-url http://localhost:8000 \
--region us-east-1
# For AWS DynamoDB
aws dynamodb list-tables --region us-east-1
Expected output:
Describe the table structure:
# For DynamoDB Local
aws dynamodb describe-table \
--table-name User \
--endpoint-url http://localhost:8000 \
--region us-east-1
# For AWS DynamoDB
aws dynamodb describe-table \
--table-name User \
--region us-east-1
Troubleshooting¶
Common Installation Issues¶
Issue: Module Not Found¶
Error:
Solution:
# Verify installation
npm list @arcaelas/dynamite
# Reinstall if necessary
npm install @arcaelas/dynamite --save
# Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install
Issue: Peer Dependencies Missing¶
Error:
Solution:
Issue: TypeScript Decorator Errors¶
Error:
Solution:
Update your tsconfig.json:
Common Configuration Issues¶
Issue: Cannot Connect to DynamoDB Local¶
Error:
Solution:
# Check if DynamoDB Local is running
docker ps | grep dynamodb-local
# If not running, start it
docker run -d -p 8000:8000 amazon/dynamodb-local
# Test connection
curl http://localhost:8000
Issue: AWS Credentials Invalid¶
Error:
Solution:
# Verify credentials
aws sts get-caller-identity
# Reconfigure AWS CLI
aws configure
# Or check environment variables
echo $AWS_ACCESS_KEY_ID
echo $AWS_SECRET_ACCESS_KEY
Issue: Missing Table Permissions¶
Error:
Solution:
Ensure your IAM user/role has the necessary permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:CreateTable",
"dynamodb:DescribeTable",
"dynamodb:PutItem",
"dynamodb:GetItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
],
"Resource": "arn:aws:dynamodb:*:*:table/*"
}
]
}
Runtime Issues¶
Issue: Metadata Not Found¶
Error:
Solution:
Ensure decorators are executed before using the model:
// ✓ Correct: Import model before using
import { User } from "./models/user";
const user = await User.create({ name: "John" });
// ✗ Wrong: Using model before decorators execute
const user = await User.create({ name: "John" });
import { User } from "./models/user";
Issue: Primary Key Missing¶
Error:
Solution:
Every model must have a primary key:
Performance Issues¶
Issue: Slow Queries¶
Check your query patterns:
// ✗ Bad: Scanning entire table
const users = (await User.where({})).filter(u => u.age > 18);
// ✓ Good: Using query filters
const users = await User.where("age", ">", 18);
Issue: High Memory Usage¶
Use attribute projection to limit data:
// ✓ Only fetch needed fields
const users = await User.where({}, {
attributes: ["id", "name", "email"]
});
Next Steps¶
Congratulations! You've successfully installed and configured @arcaelas/dynamite.
Recommended Next Steps¶
- Learn the Basics: Read the Getting Started Guide
- Explore Features: Check out Decorators Guide
- Understand Relationships: Learn about Relations Example
- Master Queries: Study Advanced Queries
- TypeScript Types: Review Types Reference
Example Projects¶
Create a sample project to practice:
mkdir my-dynamite-app
cd my-dynamite-app
npm init -y
npm install @arcaelas/dynamite @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
Additional Resources¶
Community and Support¶
- Issues: Report bugs on GitHub
- Discussions: Join community discussions
- Updates: Follow releases
Need Help?
If you encounter any issues not covered in this guide, please: 1. Check the Troubleshooting section above 2. Open an issue on GitHub
Made with ❤️ by Miguel Alejandro - Arcaelas Insiders