Skip to content

Quick Start Guide

Add AWS resources to your application as easily as installing npm packages. This guide will walk you through installing the Hereya CLI, authenticating with Hereya Cloud, bootstrapping your AWS account, and enhancing a simple web application with AWS S3 storage capabilities - all with just a few commands.

  • Node.js 20 or higher - Hereya CLI requires Node.js 20+
  • AWS Account - Hereya is designed for AWS infrastructure management
  • AWS CLI configured - Required for AWS resource provisioning

Verify your Node.js version:

Terminal window
node --version
# Should output v20.0.0 or higher

Install Hereya CLI globally using your preferred package manager:

Terminal window
npm install -g hereya-cli

Verify the installation:

hereya-cli/x.x.x
hereya --version

After installing the CLI, authenticate with Hereya Cloud. Hereya Cloud stores metadata for your projects and workspaces, and provides access to the registry of packages.

Terminal window
hereya login

This command will:

  • Open your web browser to authenticate with Hereya Cloud
  • Store your authentication credentials locally
  • Give you access to the Hereya package registry
  • Enable project and workspace metadata synchronization

Hereya is specifically designed for AWS infrastructure management. Before creating your first project, you need to bootstrap Hereya for AWS:

Terminal window
hereya bootstrap aws

This command sets up the necessary AWS resources that Hereya uses to:

  • Store and manage infrastructure state
  • Track resource deployments across workspaces
  • Coordinate AWS CloudFormation stacks
  • Manage resource dependencies

The bootstrap process creates:

  • An S3 bucket for storing Hereya’s infrastructure state
  • IAM roles and policies for managing resources
  • CloudFormation stack for Hereya’s core infrastructure

Note: You only need to run this once per AWS account/region. The bootstrap resources are shared across all projects that use Hereya.

Let’s create a simple web application that we’ll enhance with AWS resources using Hereya. Choose your preferred language:

Create a Node.js Express Application

  1. Create a new directory and initialize the project:
Terminal window
mkdir hello-hereya
cd hello-hereya
npm init -y
  1. Install Express:
Terminal window
npm install express
  1. Set the package type to module:
Terminal window
npm pkg set type="module"
  1. Create the application file app.js:
import express from 'express';
const app = express();
const port = process.env.PORT || 3000;
// Middleware
app.use(express.json());
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'healthy' });
});
// Main endpoint
app.get('/', (req, res) => {
res.send('Hello from Hereya!');
});
// S3 Upload endpoint placeholder
app.post('/upload', (req, res) => {
// TODO: Implement S3 upload using AWS SDK
const bucketName = process.env.bucketName;
const region = process.env.awsRegion;
res.json({
message: 'Upload endpoint ready - S3 integration coming soon',
bucket: bucketName || 'Not configured',
region: region || 'Not configured'
});
});
// List files endpoint placeholder
app.get('/files', (req, res) => {
// TODO: Implement S3 list objects using AWS SDK
res.json({
message: 'List files endpoint ready - S3 integration coming soon',
files: []
});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
// Log S3 configuration if available
if (process.env.bucketName) {
console.log(`S3 Bucket configured: ${process.env.bucketName}`);
}
});
  1. Update package.json to add start scripts:
{
"name": "hello-hereya",
"version": "1.0.0",
"type": "module",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "node app.js"
},
"dependencies": {
"express": "^4.18.0"
}
}
  1. Initialize Hereya in your project:
Terminal window
# First, create a workspace (environment)
hereya workspace create dev
# Then initialize the project
hereya init hello-hereya -w dev

After initialization, Hereya creates a hereya.yaml file in your project root, similar to how npm creates a package.json:

project: hello-hereya
workspace: dev

This file tracks:

  • project: Your project identifier in Hereya Cloud
  • workspace: The current environment for your application
  • packages: AWS resources added to your project (like dependencies in package.json)

Workspaces in Hereya represent different environments for your application. You can name them anything you like - common examples include:

  • dev - Development environment
  • staging - Staging/testing environment
  • production - Production environment
  • test - Testing environment
  • demo - Demo environment
  • feature-xyz - Feature branch environment

Each workspace maintains its own:

  • Infrastructure state
  • Environment variables
  • AWS resources
  • Configuration parameters

Before adding AWS resources, verify your application runs correctly:

Terminal window
npm start
# Visit http://localhost:3000

You should see “Hello from Hereya!” when visiting the root URL, and a health check response at /health.

3. Adding AWS S3 and Running Your Application

Section titled “3. Adding AWS S3 and Running Your Application”

Now let’s add an S3 bucket to your application, just like you would add an npm package. This demonstrates how Hereya makes AWS resources as easy to manage as code dependencies.

Terminal window
# Add an S3 bucket package configured for development
hereya add aws/s3bucket -p "namePrefix=myapp" -p "autoDeleteObjects=true"

Parameters:

  • namePrefix - A prefix for the bucket name (default: “hereya”). The actual bucket name will be generated as {namePrefix}-{random-suffix} to ensure global uniqueness
  • autoDeleteObjects - When set to true, all objects in the bucket will be automatically deleted when you run hereya down (default: false). For this quick start, we’re using true to make cleanup easier. ⚠️ Important: In production, you should leave this as false (the default) to prevent accidental data loss.

After adding the package, your hereya.yaml will look like:

project: hello-hereya
workspace: dev
packages:
aws/s3bucket:
version: "0.1.1"

The package parameters are stored separately in hereyaconfig/hereyavars/aws--s3bucket.yaml:

namePrefix: myapp
autoDeleteObjects: true

The following environment variables are now available:

  • bucketName - The generated bucket name (e.g., myapp-abc123)
  • awsRegion - The AWS region where the bucket was created
  • iamPolicyAwsS3Bucket - IAM policy document for bucket access (JSON)

View all environment variables available in your workspace:

Terminal window
hereya env

This will display something like:

bucketName=myapp-abc123
awsRegion=us-east-1
iamPolicyAwsS3Bucket={"Version":"2012-10-17","Statement":[...]}
# ... other environment variables

These environment variables are automatically injected when you run your application with Hereya.

Run your application with Hereya to automatically inject the AWS environment variables:

Terminal window
hereya run -- npm start

Your application now has access to the S3 bucket configuration! Test the endpoints:

Check the welcome message:

Terminal window
curl http://localhost:3000/

Check S3 configuration status:

Terminal window
curl -X POST http://localhost:3000/upload

Check files endpoint placeholder:

Terminal window
curl http://localhost:3000/files

The upload and files endpoints will show your S3 bucket name and region, confirming the environment variables are properly configured.

Now let’s implement the actual S3 functionality. Choose your language below for the complete implementation:

Install Dependencies

Terminal window
npm install @aws-sdk/client-s3 multer

Update Your Application

Replace your app.js with this complete implementation. The highlighted lines show the new S3 functionality:

app.js
import express from 'express';
import multer from 'multer';
import { S3Client, PutObjectCommand, ListObjectsV2Command } from '@aws-sdk/client-s3';
const app = express();
const port = process.env.PORT || 3000;
// Configure multer for memory storage
const upload = multer({
storage: multer.memoryStorage(),
limits: {
fileSize: 10 * 1024 * 1024 // 10MB limit
}
});
// Initialize S3 client
const s3Client = new S3Client({
region: process.env.awsRegion || 'us-east-1'
});
// Middleware
app.use(express.json());
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'healthy' });
});
// Main endpoint
app.get('/', (req, res) => {
res.send('Hello from Hereya!');
});
// S3 Upload endpoint
app.post('/upload', upload.single('file'), async (req, res) => {
const bucketName = process.env.bucketName;
if (!bucketName) {
return res.status(500).json({ error: 'S3 bucket not configured' });
}
if (!req.file) {
return res.status(400).json({ error: 'No file provided' });
}
try {
const key = `uploads/${Date.now()}-${req.file.originalname}`;
const command = new PutObjectCommand({
Bucket: bucketName,
Key: key,
Body: req.file.buffer,
ContentType: req.file.mimetype
});
await s3Client.send(command);
res.json({
message: 'File uploaded successfully',
bucket: bucketName,
key: key,
size: req.file.size
});
} catch (error) {
console.error('Upload error:', error);
res.status(500).json({
error: 'Failed to upload file',
details: error.message
});
}
});
// List files endpoint
app.get('/files', async (req, res) => {
const bucketName = process.env.bucketName;
if (!bucketName) {
return res.status(500).json({ error: 'S3 bucket not configured' });
}
try {
const command = new ListObjectsV2Command({
Bucket: bucketName,
Prefix: 'uploads/',
MaxKeys: 100
});
const response = await s3Client.send(command);
const files = (response.Contents || []).map(item => ({
key: item.Key,
size: item.Size,
lastModified: item.LastModified
}));
res.json({
bucket: bucketName,
count: files.length,
files: files
});
} catch (error) {
console.error('List error:', error);
res.status(500).json({
error: 'Failed to list files',
details: error.message
});
}
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
if (process.env.bucketName) {
console.log(`S3 Bucket configured: ${process.env.bucketName}`);
} else {
console.log('Warning: bucketName not configured');
}
});
Terminal window
hereya run -- npm start

Create a test file and upload it using curl:

Terminal window
# Create a test file
echo 'Hello from Hereya S3 integration!' > test.txt
# Upload the file
curl -X POST http://localhost:3000/upload \
-F "file=@test.txt" \
-H "Accept: application/json"

You should see a response like:

{
"message": "File uploaded successfully",
"bucket": "myapp-abc123",
"key": "uploads/1234567890-test.txt",
"size": 34
}
Terminal window
curl http://localhost:3000/files

You should see your uploaded files:

{
"bucket": "myapp-abc123",
"count": 1,
"files": [
{
"key": "uploads/1234567890-test.txt",
"size": 34,
"lastModified": "2024-01-15T10:30:00Z"
}
]
}
  1. Open the AWS S3 Console
  2. Find your bucket (named as you specified)
  3. Navigate to the uploads/ folder
  4. You should see your uploaded files

If you encounter any issues with your S3 integration, see the Troubleshooting section at the end of this guide.

Now that you have a working application with S3 integration, let’s deploy it to AWS AppRunner - a fully managed container service that automatically scales your application based on traffic.

Understanding Deployment Workspaces and Profiles

Section titled “Understanding Deployment Workspaces and Profiles”

Hereya distinguishes between regular workspaces (like our dev workspace) and deployment workspaces. Deployment workspaces are specifically designed to provision and manage cloud infrastructure for hosting your applications.

Key concepts:

  • Deployment packages: Special packages (like aws/apprunner) that provide hosting infrastructure, stored in the deploy section of hereya.yaml
  • Profiles: Configuration tags that allow different settings per environment (e.g., different bucket names for dev vs staging)
  • Deployment flag (-d): Required when creating workspaces intended for deployment

Create a new workspace specifically for staging deployments:

Terminal window
hereya workspace create staging -d --profile=staging

This command:

  • Creates a workspace named staging
  • Marks it as a deployment workspace with the -d flag (required for hereya deploy)
  • Assigns the staging profile for configuration segregation

Adding the AWS AppRunner Deployment Package

Section titled “Adding the AWS AppRunner Deployment Package”

Add the AWS AppRunner package to enable container deployment:

Terminal window
hereya add aws/apprunner

After adding the deployment package, your hereya.yaml will look like:

project: hello-hereya
workspace: dev
packages:
aws/s3bucket:
version: "0.3.0"
deploy:
aws/apprunner:
version: "0.3.0"

Notice how deployment packages are stored in the deploy section, separate from regular packages. Deployment packages are only provisioned when you run hereya deploy.

AWS AppRunner requires a Dockerfile to containerize your application for deployment. Create a Dockerfile in your project root directory with the appropriate configuration for your language:

Dockerfile
# Build stage
FROM node:22-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# Production stage
FROM node:22-alpine
WORKDIR /app
# Copy dependencies from builder
COPY --from=builder /app/node_modules ./node_modules
# Copy application code
COPY package*.json ./
COPY app.js ./
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
# Change ownership
RUN chown -R nodejs:nodejs /app
USER nodejs
# Expose port
EXPOSE 3000
# Start the application
CMD ["npm", "start"]

This Dockerfile:

  • Uses multi-stage build for optimized image size
  • Installs only production dependencies in a separate build stage
  • Runs the application as a non-root user for enhanced security
  • Copies only necessary files (app.js and package files)
  • Starts the application with npm start

Profiles allow you to use different configurations for different environments. Update your S3 bucket configuration to use a different name prefix for staging.

Edit hereyaconfig/hereyavars/aws--s3bucket.yaml:

namePrefix: myapp
autoDeleteObjects: "true"
---
profile: staging
namePrefix: hello-staging

The --- separator creates profile-specific configuration. When deploying to the staging workspace (which uses the staging profile), Hereya will:

  • Use hello-staging as the bucket name prefix instead of myapp
  • Create a bucket like hello-staging-abc123 instead of myapp-abc123

Deploy your application to AWS AppRunner:

Terminal window
hereya deploy -w staging

This command will:

  1. Provision regular packages in the staging workspace (S3 bucket with staging-specific configuration)
  2. Provision deployment packages (AWS AppRunner service)
  3. Build and deploy your application to the AppRunner service
  4. Configure environment variables so your deployed app can access the staging S3 bucket

The deployment process will show progress indicators and output the deployed application URL when complete.

Once deployment is complete, you’ll receive a URL from the deployment output. Enter it below to automatically update all testing commands with your actual URL:

Test your deployed application using the commands below:

Check the welcome message:

Terminal window
curl https://your-app.region.awsapprunner.com/

Test the health endpoint:

Terminal window
curl https://your-app.region.awsapprunner.com/health

Upload a file to staging S3:

Terminal window
# Create a test file for staging
echo 'Hello from staging deployment!' > staging-test.txt
# Upload to the deployed application
curl -X POST https://your-app.region.awsapprunner.com/upload \
-F "file=@staging-test.txt" \
-H "Accept: application/json"

List files in staging S3:

Terminal window
curl https://your-app.region.awsapprunner.com/files

You should see that your staging deployment is using the hello-staging-xxx bucket, confirming that profile-specific configuration is working correctly.

Updating your deployment: After making code changes, redeploy with the same command:

Terminal window
hereya deploy -w staging

Viewing environment variables in staging:

Terminal window
hereya env -w staging

Your application is now deployed and accessible from anywhere on the internet, with its own dedicated S3 bucket for staging data!

When you’re done experimenting, you can clean up the resources to avoid ongoing AWS charges. Hereya provides different commands for cleaning up deployments vs development resources.

To remove your staging deployment (AppRunner service and staging S3 bucket):

Terminal window
hereya undeploy -w staging

This command will:

  • Remove the AWS AppRunner service
  • Delete the staging S3 bucket and all uploaded files (since we used autoDeleteObjects=true)
  • Clean up all staging deployment resources
  • Keep your deployment configuration in hereya.yaml intact

To remove your development resources (the dev workspace S3 bucket):

Terminal window
hereya down

This command will:

  • Delete the dev workspace S3 bucket and all uploaded files
  • Clean up the development AWS resources
  • Keep your hereya.yaml configuration intact

Since your configurations are saved in hereya.yaml, you can recreate resources anytime:

Re-deploy to staging:

Terminal window
hereya deploy -w staging

Re-provision dev resources:

Terminal window
hereya up

After cleanup:

  • Check the AWS S3 Console to verify bucket deletions
  • Check the AWS AppRunner Console to verify service removal
  • Run hereya env -w staging and hereya env to confirm environment variables are cleared

If you see “Unable to locate credentials”:

  • Ensure AWS CLI is configured: aws configure
  • Or set environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

If you get permission errors:

  • Check your AWS IAM user has S3 permissions
  • Ensure the bucket name matches exactly
  • The examples limit uploads to 10MB
  • Adjust the limits in the code for larger files
  • For very large files, consider using multipart uploads

If you see an error about Node.js version, you need to upgrade to Node.js 20 or higher:

  • Download from nodejs.org
  • Or use your system’s package manager
  • Verify with node --version after installation

If you encounter permission errors:

Terminal window
# For npm
sudo npm install -g hereya-cli
# Or configure npm to use a different directory
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH

If you haven’t configured AWS credentials yet:

Terminal window
aws configure
# Enter your AWS Access Key ID, Secret Access Key, and region